prevent zero-length removals from deleting uneditable parts

This solves an issue where, when backspacing the proceeding character next to a pill,
chrome reports the caret as being in the pill node, not at
the start of the proceeding text node. This would cause the pill
to be removed together with proceeding character.

This is a bug in any case, removing 0 characters
shouldn't remove the part
pull/21833/head
Bruno Windels 2019-05-16 19:14:24 +01:00
parent 245f48a22c
commit 690ee63bb4
1 changed files with 17 additions and 12 deletions

View File

@ -183,6 +183,8 @@ export default class EditorModel {
// part might be undefined here
let part = this._parts[index];
const amount = Math.min(len, part.text.length - offset);
// don't allow 0 amount deletions
if (amount) {
if (part.canEdit) {
const replaceWith = part.remove(offset, amount);
if (typeof replaceWith === "string") {
@ -199,6 +201,9 @@ export default class EditorModel {
removedOffsetDecrease += offset;
this._removePart(index);
}
} else {
index += 1;
}
len -= amount;
offset = 0;
}