fix autocompl. not always appearing/being updated when there is no part

This commit is contained in:
Bruno Windels 2019-05-09 16:54:58 +02:00
parent bc14d4f58f
commit 580a89875a

View file

@ -88,6 +88,7 @@ export default class EditorModel {
this._addText(position, diff.added); this._addText(position, diff.added);
} }
this._mergeAdjacentParts(); this._mergeAdjacentParts();
// TODO: now that parts can be outright deleted, this doesn't make sense anymore
const caretOffset = diff.at + (diff.added ? diff.added.length : 0); const caretOffset = diff.at + (diff.added ? diff.added.length : 0);
const newPosition = this._positionForOffset(caretOffset, true); const newPosition = this._positionForOffset(caretOffset, true);
this._setActivePart(newPosition); this._setActivePart(newPosition);
@ -97,9 +98,9 @@ export default class EditorModel {
_setActivePart(pos) { _setActivePart(pos) {
const {index} = pos; const {index} = pos;
const part = this._parts[index]; const part = this._parts[index];
if (pos.index !== this._activePartIdx) { if (part) {
if (index !== this._activePartIdx) {
this._activePartIdx = index; this._activePartIdx = index;
// if there is a hidden autocomplete for this part, show it again
if (this._activePartIdx !== this._autoCompletePartIdx) { if (this._activePartIdx !== this._autoCompletePartIdx) {
// else try to create one // else try to create one
const ac = part.createAutoComplete(this._onAutoComplete); const ac = part.createAutoComplete(this._onAutoComplete);
@ -110,8 +111,14 @@ export default class EditorModel {
} }
} }
} }
if (this._autoComplete) { // not _autoComplete, only there if active part is autocomplete part
this._autoComplete.onPartUpdate(part, pos.offset); if (this.autoComplete) {
this.autoComplete.onPartUpdate(part, pos.offset);
}
} else {
this._activePartIdx = null;
this._autoComplete = null;
this._autoCompletePartIdx = null;
} }
} }
@ -181,6 +188,7 @@ export default class EditorModel {
let {index, offset} = pos; let {index, offset} = pos;
const part = this._parts[index]; const part = this._parts[index];
if (part) { if (part) {
if (part.canEdit) {
if (part.insertAll(offset, str)) { if (part.insertAll(offset, str)) {
str = null; str = null;
} else { } else {
@ -190,6 +198,10 @@ export default class EditorModel {
index += 1; index += 1;
this._insertPart(index, splitPart); this._insertPart(index, splitPart);
} }
} else {
// insert str after this part
index += 1;
}
} }
while (str) { while (str) {
const newPart = this._partCreator.createPartForInput(str); const newPart = this._partCreator.createPartForInput(str);