Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should no trigger errors in Edge when text prediction enabled(T1200561) #109

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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