Skip to content

Commit

Permalink
HtmlEditor in Edge - Should no trigger errors when text prediction en…
Browse files Browse the repository at this point in the history
…abled(T1200561) (#109)
  • Loading branch information
alexanderPolosatov authored Dec 25, 2023
1 parent 13e5af5 commit 408ed5e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Block, { BlockEmbed, bubbleFormats } from '../blots/block';
import Break from '../blots/break';
import TextBlot, { escapeText } from '../blots/text';
import removeClass from '../utils/remove_class';
import isDefined from '../utils/is_defined';

const ASCII = /^[ -~]*$/;

Expand Down Expand Up @@ -243,11 +244,18 @@ class Editor {
} else {
this.delta = this.getDelta();
if (!change || !isEqual(oldDelta.compose(change), this.delta)) {
change = oldDelta.diff(this.delta, selectionInfo);
if (!this.deltaContainsRetain(oldDelta)) {
change = oldDelta.diff(this.delta, selectionInfo);
}
}
}
return change;
}

// T1200561
deltaContainsRetain(delta) {
return delta.ops.some((op) => isDefined(op.retain));
}
}

function convertListHTML(items, lastIndent, types) {
Expand Down
55 changes: 55 additions & 0 deletions test/unit/core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,61 @@ describe('Editor', function () {
});
});

// T1200561
describe('deltaContainsRetain functionality', function () {
it('delta should be empty when deltaContainsRetain returns false(T1200561)', function () {
const editor = this.initialize(Editor, '<p></p>');

editor.deltaContainsRetain = () => {
return false;
};

const sourceDelta = new Delta().insert('123');
editor.update(sourceDelta);

const newDelta = new Delta().insert('new string');

const resultDelta = editor.update(newDelta);

expect(resultDelta.ops.length).toEqual(0);
});

it('delta should be empty when deltaContainsRetain returns true(T1200561)', function () {
const editor = this.initialize(Editor, '<p></p>');

editor.deltaContainsRetain = () => {
return true;
};

const sourceDelta = new Delta().insert('123');
editor.update(sourceDelta);

const newDelta = new Delta().insert('new string');

const resultDelta = editor.update(newDelta);

expect(resultDelta.ops.length).toEqual(1);
});

it('deltaContainsRetain should return true when delta contains retain operation(T1200561)', function () {
const editor = this.initialize(Editor, '<p></p>');
const delta = new Delta().retain(3);

const deltaContainsRetain = editor.deltaContainsRetain(delta);

expect(deltaContainsRetain).toEqual(true);
});

it('deltaContainsRetain should return false when delta not contains retain operation(T1200561)', function () {
const editor = this.initialize(Editor, '<p></p>');
const delta = new Delta().insert('123');

const deltaContainsRetain = editor.deltaContainsRetain(delta);

expect(deltaContainsRetain).toEqual(false);
});
});

describe('applyDelta', function () {
it('insert', function () {
const editor = this.initialize(Editor, '<p></p>');
Expand Down

0 comments on commit 408ed5e

Please sign in to comment.