Merge pull request #3393 from matrix-org/bwindels/cider-fix-lastcaret

New composer: fix needing to push arrow-up twice after sending first message after switching to a room
This commit is contained in:
Bruno Windels 2019-09-06 09:22:10 +00:00 committed by GitHub
commit 6b104f6344
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 7 deletions

View file

@ -149,6 +149,9 @@ export default class EditorModel {
reset(serializedParts, caret, inputType) {
this._parts = serializedParts.map(p => this._partCreator.deserializePart(p));
if (!caret) {
caret = this.getPositionAtEnd();
}
// close auto complete if open
// this would happen when clearing the composer after sending
// a message with the autocomplete still open

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;
}
}