fix autocompl. not always appearing/being updated when there is no part
This commit is contained in:
parent
bc14d4f58f
commit
580a89875a
1 changed files with 31 additions and 19 deletions
|
@ -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,21 +98,27 @@ 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) {
|
||||||
this._activePartIdx = index;
|
if (index !== this._activePartIdx) {
|
||||||
// if there is a hidden autocomplete for this part, show it again
|
this._activePartIdx = index;
|
||||||
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);
|
||||||
if (ac) {
|
if (ac) {
|
||||||
// make sure that react picks up the difference between both acs
|
// make sure that react picks up the difference between both acs
|
||||||
this._autoComplete = ac;
|
this._autoComplete = ac;
|
||||||
this._autoCompletePartIdx = index;
|
this._autoCompletePartIdx = index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// not _autoComplete, only there if active part is autocomplete part
|
||||||
if (this._autoComplete) {
|
if (this.autoComplete) {
|
||||||
this._autoComplete.onPartUpdate(part, pos.offset);
|
this.autoComplete.onPartUpdate(part, pos.offset);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this._activePartIdx = null;
|
||||||
|
this._autoComplete = null;
|
||||||
|
this._autoCompletePartIdx = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,14 +188,19 @@ 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.insertAll(offset, str)) {
|
if (part.canEdit) {
|
||||||
str = null;
|
if (part.insertAll(offset, str)) {
|
||||||
|
str = null;
|
||||||
|
} else {
|
||||||
|
// console.log("splitting", offset, [part.text]);
|
||||||
|
const splitPart = part.split(offset);
|
||||||
|
// console.log("splitted", [part.text, splitPart.text]);
|
||||||
|
index += 1;
|
||||||
|
this._insertPart(index, splitPart);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// console.log("splitting", offset, [part.text]);
|
// insert str after this part
|
||||||
const splitPart = part.split(offset);
|
|
||||||
// console.log("splitted", [part.text, splitPart.text]);
|
|
||||||
index += 1;
|
index += 1;
|
||||||
this._insertPart(index, splitPart);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (str) {
|
while (str) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue