force completion when hitting tab

by replacing word before caret with pill-candidate and
forcing auto complete
pull/21833/head
Bruno Windels 2019-08-27 16:16:43 +02:00
parent 68c2bb7ca6
commit f02713d08e
1 changed files with 19 additions and 0 deletions

View File

@ -269,6 +269,9 @@ export default class BasicMessageEditor extends React.Component {
default:
return; // don't preventDefault on anything else
}
} else if (event.key === "Tab") {
this._tabCompleteName(event);
handled = true;
}
}
if (handled) {
@ -277,6 +280,22 @@ export default class BasicMessageEditor extends React.Component {
}
}
async _tabCompleteName(event) {
const {model} = this.props;
const caret = this.getCaret();
const position = model.positionForOffset(caret.offset, caret.atNodeEnd);
const range = model.startRange(position);
range.expandBackwardsWhile((index, offset, part) => {
return part.text[offset] !== " " && (part.type === "plain" || part.type === "pill-candidate");
});
const {partCreator} = model;
await model.transform(() => {
const addedLen = range.replace([partCreator.pillCandidate(range.text)]);
return model.positionForOffset(caret.offset + addedLen, true);
});
await model.autoComplete.onTab();
}
isModified() {
return this._modifiedFlag;
}