don't put cursor position in NewlinePart after adding it
You can't append to it anyway, so mark it uneditable and skip uneditable parts if that's where an edit ended up. This has the added advantage that if there is text after a newly insert pill, the cursor will be put just before it rather than in the pill, after the last character.
This commit is contained in:
parent
0e3d4fbc0c
commit
f27607a74c
2 changed files with 19 additions and 1 deletions
|
@ -88,7 +88,8 @@ export default class EditorModel {
|
|||
}
|
||||
this._mergeAdjacentParts();
|
||||
const caretOffset = diff.at - removedOffsetDecrease + addedLen;
|
||||
const newPosition = this._positionForOffset(caretOffset, true);
|
||||
let newPosition = this._positionForOffset(caretOffset, true);
|
||||
newPosition = newPosition.skipUneditableParts(this._parts);
|
||||
this._setActivePart(newPosition);
|
||||
this._updateCallback(newPosition);
|
||||
}
|
||||
|
@ -261,4 +262,13 @@ class DocumentPosition {
|
|||
get offset() {
|
||||
return this._offset;
|
||||
}
|
||||
|
||||
skipUneditableParts(parts) {
|
||||
const part = parts[this.index];
|
||||
if (part && !part.canEdit) {
|
||||
return new DocumentPosition(this.index + 1, 0);
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue