diff --git a/spec/highlight-support.spec.js b/spec/highlight-support.spec.js
index bcc410e0..b8587757 100644
--- a/spec/highlight-support.spec.js
+++ b/spec/highlight-support.spec.js
@@ -327,6 +327,38 @@ ke The
World Go Round`)
expect(this.getHtml()).to.equal(expectedHtml)
})
+ it('limits start and end values to text range', function () {
+ setupHighlightEnv(this, 'ab')
+ this.highlightRange('ab', 'myId', -1, 100)
+ const expectedHtml = this.formatHtml(
+ `ab`
+ )
+
+ expect(this.getHtml()).to.equal(expectedHtml)
+ })
+
+ it('always selects the first character if values are too small', function () {
+ setupHighlightEnv(this, 'ab')
+ const highlightText = undefined // Avoid validation
+ this.highlightRange(highlightText, 'myId', 0, 0)
+ const expectedHtml = this.formatHtml(
+ `ab`
+ )
+
+ expect(this.getHtml()).to.equal(expectedHtml)
+ })
+
+ it('always selects the last character if values are too large', function () {
+ setupHighlightEnv(this, 'ab')
+ const highlightText = undefined // Avoid validation
+ this.highlightRange(highlightText, 'myId', 2, 5)
+ const expectedHtml = this.formatHtml(
+ `ab`
+ )
+
+ expect(this.getHtml()).to.equal(expectedHtml)
+ })
+
it('handles a
tag without whitespaces', function () {
setupHighlightEnv(this, 'a
b')
this.highlightRange('b', 'myId', 1, 2)
@@ -482,7 +514,7 @@ ke The
World Go Round`)
it('extracts a readable text', function () {
setupHighlightEnv(this, '๐ Make The \r\n ๐ Go \n๐')
- this.highlightRange('๐ Makeย The ๐ Go ๐', 'myId', 0, 23)
+ this.highlightRange('๐ Makeย The \n ๐ Go \n๐', 'myId', 0, 23)
const expectedRanges = {
myId: {
text: '๐ Makeย The \n ๐ Go \n๐',
@@ -499,7 +531,7 @@ ke The
World Go Round`)
setupHighlightEnv(this, '๐ Make The \r\n ๐ Go \n๐')
let called = 0
const dispatcher = {notify: () => called++}
- this.highlightRange('๐ Makeย The ๐ Go ๐', 'myId', 0, 20, dispatcher)
+ this.highlightRange('๐ Makeย The \n ๐ Go \n๐', 'myId', 0, 23, dispatcher)
expect(called).to.equal(1)
})
@@ -508,7 +540,7 @@ ke The
World Go Round`)
setupHighlightEnv(this, '๐ Make The \r\n ๐ Go \n๐')
let called = 0
const dispatcher = {notify: () => called++}
- this.highlightRange('๐ Makeย The ๐ Go ๐', 'myId', 0, 20)
+ this.highlightRange('๐ Makeย The \n ๐ Go \n๐', 'myId', 0, 23)
this.removeHighlight('first', dispatcher)
expect(called).to.equal(1)
diff --git a/spec/selection.spec.js b/spec/selection.spec.js
index ccdc0fb9..4e2bd180 100644
--- a/spec/selection.spec.js
+++ b/spec/selection.spec.js
@@ -142,6 +142,17 @@ describe('Selection', function () {
})
})
+ describe('getTextRange()', function () {
+
+ it('handles a zero width non-break space', function () {
+ const oneWord = createElement('