update last caret from update callback instead of input event

many editor updates are not caused by an input event, so
the last caret wasn't always up to date.

Updating the caret from the update callback ensures that every
time the editor contents is changed, the last caret is updated.
This commit is contained in:
Bruno Windels 2019-09-06 11:09:01 +02:00
parent 124b7135cd
commit 2596281a7c
2 changed files with 23 additions and 7 deletions

View file

@ -120,4 +120,17 @@ export default class DocumentPosition {
const atEnd = offset >= lastPart.text.length;
return new DocumentOffset(offset, atEnd);
}
isAtEnd(model) {
if (model.parts.length === 0) {
return true;
}
const lastPartIdx = model.parts.length - 1;
const lastPart = model.parts[lastPartIdx];
return this.index === lastPartIdx && this.offset === lastPart.text.length;
}
isAtStart() {
return this.index === 0 && this.offset === 0;
}
}