Merge pull request #3372 from matrix-org/bwindels/fix-command-tab-complete
New composer: fix tab-complete in commandspull/21833/head
commit
4329d8c4ef
|
@ -268,7 +268,7 @@ export default class BasicMessageEditor extends React.Component {
|
||||||
handled = true;
|
handled = true;
|
||||||
// autocomplete or enter to send below shouldn't have any modifier keys pressed.
|
// autocomplete or enter to send below shouldn't have any modifier keys pressed.
|
||||||
} else if (!(event.metaKey || event.altKey || event.shiftKey)) {
|
} else if (!(event.metaKey || event.altKey || event.shiftKey)) {
|
||||||
if (model.autoComplete) {
|
if (model.autoComplete && model.autoComplete.hasCompletions()) {
|
||||||
const autoComplete = model.autoComplete;
|
const autoComplete = model.autoComplete;
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case "ArrowUp":
|
case "ArrowUp":
|
||||||
|
@ -309,7 +309,11 @@ export default class BasicMessageEditor extends React.Component {
|
||||||
const position = model.positionForOffset(caret.offset, caret.atNodeEnd);
|
const position = model.positionForOffset(caret.offset, caret.atNodeEnd);
|
||||||
const range = model.startRange(position);
|
const range = model.startRange(position);
|
||||||
range.expandBackwardsWhile((index, offset, part) => {
|
range.expandBackwardsWhile((index, offset, part) => {
|
||||||
return part.text[offset] !== " " && (part.type === "plain" || part.type === "pill-candidate");
|
return part.text[offset] !== " " && (
|
||||||
|
part.type === "plain" ||
|
||||||
|
part.type === "pill-candidate" ||
|
||||||
|
part.type === "command"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
const {partCreator} = model;
|
const {partCreator} = model;
|
||||||
// await for auto-complete to be open
|
// await for auto-complete to be open
|
||||||
|
|
|
@ -40,6 +40,11 @@ export default class AutocompleteWrapperModel {
|
||||||
return this._getAutocompleterComponent().hasSelection();
|
return this._getAutocompleterComponent().hasSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasCompletions() {
|
||||||
|
const ac = this._getAutocompleterComponent();
|
||||||
|
return ac && ac.countCompletions() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
onEnter() {
|
onEnter() {
|
||||||
this._updateCallback({close: true});
|
this._updateCallback({close: true});
|
||||||
}
|
}
|
||||||
|
|
|
@ -465,10 +465,6 @@ export class CommandPartCreator extends PartCreator {
|
||||||
}
|
}
|
||||||
|
|
||||||
class CommandPart extends PillCandidatePart {
|
class CommandPart extends PillCandidatePart {
|
||||||
acceptsInsertion(chr, i) {
|
|
||||||
return PlainPart.prototype.acceptsInsertion.call(this, chr, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
get type() {
|
get type() {
|
||||||
return "command";
|
return "command";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue