mirror of https://github.com/vector-im/riot-web
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 partpull/21833/head
parent
245f48a22c
commit
690ee63bb4
|
@ -183,21 +183,26 @@ export default class EditorModel {
|
||||||
// part might be undefined here
|
// part might be undefined here
|
||||||
let part = this._parts[index];
|
let part = this._parts[index];
|
||||||
const amount = Math.min(len, part.text.length - offset);
|
const amount = Math.min(len, part.text.length - offset);
|
||||||
if (part.canEdit) {
|
// don't allow 0 amount deletions
|
||||||
const replaceWith = part.remove(offset, amount);
|
if (amount) {
|
||||||
if (typeof replaceWith === "string") {
|
if (part.canEdit) {
|
||||||
this._replacePart(index, this._partCreator.createDefaultPart(replaceWith));
|
const replaceWith = part.remove(offset, amount);
|
||||||
}
|
if (typeof replaceWith === "string") {
|
||||||
part = this._parts[index];
|
this._replacePart(index, this._partCreator.createDefaultPart(replaceWith));
|
||||||
// remove empty part
|
}
|
||||||
if (!part.text.length) {
|
part = this._parts[index];
|
||||||
this._removePart(index);
|
// remove empty part
|
||||||
|
if (!part.text.length) {
|
||||||
|
this._removePart(index);
|
||||||
|
} else {
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
index += 1;
|
removedOffsetDecrease += offset;
|
||||||
|
this._removePart(index);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
removedOffsetDecrease += offset;
|
index += 1;
|
||||||
this._removePart(index);
|
|
||||||
}
|
}
|
||||||
len -= amount;
|
len -= amount;
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
|
Loading…
Reference in New Issue