Merge pull request #2665 from overleaf/pr-fix-spelling-markers-safari

Spellcheck improvements + fix spelling markers being out of place

GitOrigin-RevId: fa70e257f96f78d3570c86871f85c79daf08014c
This commit is contained in:
nate stemen
2020-03-19 04:17:09 +00:00
committed by Copybot
parent c301d8bc25
commit 3a2bdfe7f1
2 changed files with 127 additions and 71 deletions
File diff suppressed because one or more lines are too long
@@ -64,7 +64,7 @@ define([
}) })
this.adapter.getLinesByRows.returns(['oppozition']) this.adapter.getLinesByRows.returns(['oppozition'])
this.spellCheckManager.init() this.spellCheckManager.init()
this.timelord.tick(200) this.timelord.tick(500)
this.$httpBackend.flush() this.$httpBackend.flush()
expect(this.highlightedWordManager.addHighlight).to.have.been.called expect(this.highlightedWordManager.addHighlight).to.have.been.called
}) })
@@ -88,52 +88,78 @@ define([
] ]
}) })
}) })
it('only checks visible lines', function() { describe('when doing the first check', function() {
this.spellCheckManager.init() beforeEach(function() {
this.timelord.tick(200) this.spellCheckManager.init()
this.$httpBackend.flush() })
expect(this.adapter.getLinesByRows).to.have.been.calledWith([3, 4, 5]) it('initially flags all lines as dirty ', function() {
expect(this.spellCheckManager.changedLines)
.to.have.lengthOf(10)
.and.to.not.include(false)
})
it('checks beyond the currently visible viewport', function() {
this.timelord.tick(500)
this.$httpBackend.flush()
expect(this.adapter.getLinesByRows).to.have.been.calledWith([
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
])
})
}) })
describe('after the initial check', function() {
beforeEach(function() {
this.spellCheckManager.init()
this.spellCheckManager.firstCheck = false
})
it('ignores updated lines', function() { it('only checks visible lines', function() {
this.spellCheckManager.init() this.spellCheckManager.runSpellCheck()
this.spellCheckManager.changedLines[4] = false this.spellCheckManager.timeoutId = null
this.timelord.tick(200) this.$httpBackend.flush()
this.$httpBackend.flush() expect(this.adapter.getLinesByRows).to.have.been.calledWith([3, 4, 5])
expect(this.adapter.getLinesByRows).to.have.been.calledWith([3, 5]) })
})
it('clears highlights for changed lines', function() { it('flags checked lines as non-dirty', function() {
this.spellCheckManager.init() this.spellCheckManager.runSpellCheck()
this.timelord.tick(200) this.spellCheckManager.timeoutId = null
this.$httpBackend.flush() this.$httpBackend.flush()
expect( expect(this.spellCheckManager.changedLines[2]).to.equal(true)
this.highlightedWordManager.clearRow.getCall(0).args[0] expect(this.spellCheckManager.changedLines[3]).to.equal(false)
).to.equal(3) expect(this.spellCheckManager.changedLines[4]).to.equal(false)
expect( expect(this.spellCheckManager.changedLines[5]).to.equal(false)
this.highlightedWordManager.clearRow.getCall(1).args[0] expect(this.spellCheckManager.changedLines[6]).to.equal(true)
).to.equal(4) })
expect(
this.highlightedWordManager.clearRow.getCall(2).args[0]
).to.equal(5)
})
it('initially flags all lines as dirty', function() { it('ignores updated lines', function() {
this.spellCheckManager.init() this.spellCheckManager.changedLines[4] = false
expect(this.spellCheckManager.changedLines) this.spellCheckManager.runSpellCheck()
.to.have.lengthOf(10) this.spellCheckManager.timeoutId = null
.and.to.not.include(false) this.$httpBackend.flush()
}) expect(this.adapter.getLinesByRows).to.have.been.calledWith([3, 5])
})
it('initially flags checked lines as non-dirty', function() { it('clears highlights for changed lines', function() {
this.spellCheckManager.init() this.spellCheckManager.runSpellCheck()
this.timelord.tick(200) this.spellCheckManager.timeoutId = null
this.$httpBackend.flush() this.$httpBackend.flush()
expect(this.spellCheckManager.changedLines[2]).to.equal(true) expect(
expect(this.spellCheckManager.changedLines[3]).to.equal(false) this.highlightedWordManager.clearRow.getCall(0).args[0]
expect(this.spellCheckManager.changedLines[4]).to.equal(false) ).to.equal(3)
expect(this.spellCheckManager.changedLines[5]).to.equal(false) expect(
expect(this.spellCheckManager.changedLines[6]).to.equal(true) this.highlightedWordManager.clearRow.getCall(1).args[0]
).to.equal(4)
expect(
this.highlightedWordManager.clearRow.getCall(2).args[0]
).to.equal(5)
})
}) })
}) })
@@ -156,14 +182,14 @@ define([
it('adds already checked words to the spellchecker cache', function() { it('adds already checked words to the spellchecker cache', function() {
expect(this.spellCheckManager.cache.info().size).to.equal(0) expect(this.spellCheckManager.cache.info().size).to.equal(0)
this.spellCheckManager.init() this.spellCheckManager.init()
this.timelord.tick(200) this.timelord.tick(500)
this.$httpBackend.flush() this.$httpBackend.flush()
expect(this.spellCheckManager.cache.info().size).to.equal(3) expect(this.spellCheckManager.cache.info().size).to.equal(3)
}) })
it('adds misspeled word suggestions to the cache', function() { it('adds misspeled word suggestions to the cache', function() {
this.spellCheckManager.init() this.spellCheckManager.init()
this.timelord.tick(200) this.timelord.tick(500)
this.$httpBackend.flush() this.$httpBackend.flush()
expect( expect(
@@ -175,7 +201,7 @@ define([
it('adds non-misspeled words to the cache as a boolean', function() { it('adds non-misspeled words to the cache as a boolean', function() {
this.spellCheckManager.init() this.spellCheckManager.init()
this.timelord.tick(200) this.timelord.tick(500)
this.$httpBackend.flush() this.$httpBackend.flush()
expect( expect(
this.spellCheckManager.cache.get( this.spellCheckManager.cache.get(
@@ -210,7 +236,7 @@ define([
] ]
}) })
this.spellCheckManager.init() this.spellCheckManager.init()
this.timelord.tick(200) this.timelord.tick(500)
this.$httpBackend.flush() this.$httpBackend.flush()
}) })
@@ -231,10 +257,10 @@ define([
] ]
}) })
this.spellCheckManager.init() this.spellCheckManager.init()
this.timelord.tick(200) this.timelord.tick(500)
this.$httpBackend.flush() this.$httpBackend.flush()
this.spellCheckManager.init() this.spellCheckManager.init()
this.timelord.tick(200) this.timelord.tick(500)
}) })
it('hits the backend only with non-cached words', function() { it('hits the backend only with non-cached words', function() {
@@ -254,7 +280,7 @@ define([
] ]
}) })
this.spellCheckManager.init() this.spellCheckManager.init()
this.timelord.tick(200) this.timelord.tick(500)
this.$httpBackend.flush() this.$httpBackend.flush()
this.adapter.getLinesByRows.returns(['Lorem ipsum dolor sit amet']) this.adapter.getLinesByRows.returns(['Lorem ipsum dolor sit amet'])
@@ -274,7 +300,7 @@ define([
] ]
}) })
this.spellCheckManager.init() this.spellCheckManager.init()
this.timelord.tick(200) this.timelord.tick(500)
this.$httpBackend.flush() this.$httpBackend.flush()
}) })