Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3372 from matrix-org/bwindels/fix-command-tab-com…
Browse files Browse the repository at this point in the history
…plete

New composer: fix tab-complete in commands
  • Loading branch information
bwindels authored Sep 2, 2019
2 parents 7032dc6 + fdd23b3 commit 4329d8c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/components/views/rooms/BasicMessageComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export default class BasicMessageEditor extends React.Component {
handled = true;
// autocomplete or enter to send below shouldn't have any modifier keys pressed.
} else if (!(event.metaKey || event.altKey || event.shiftKey)) {
if (model.autoComplete) {
if (model.autoComplete && model.autoComplete.hasCompletions()) {
const autoComplete = model.autoComplete;
switch (event.key) {
case "ArrowUp":
Expand Down Expand Up @@ -309,7 +309,11 @@ export default class BasicMessageEditor extends React.Component {
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");
return part.text[offset] !== " " && (
part.type === "plain" ||
part.type === "pill-candidate" ||
part.type === "command"
);
});
const {partCreator} = model;
// await for auto-complete to be open
Expand Down
5 changes: 5 additions & 0 deletions src/editor/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export default class AutocompleteWrapperModel {
return this._getAutocompleterComponent().hasSelection();
}

hasCompletions() {
const ac = this._getAutocompleterComponent();
return ac && ac.countCompletions() > 0;
}

onEnter() {
this._updateCallback({close: true});
}
Expand Down
4 changes: 0 additions & 4 deletions src/editor/parts.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,6 @@ export class CommandPartCreator extends PartCreator {
}

class CommandPart extends PillCandidatePart {
acceptsInsertion(chr, i) {
return PlainPart.prototype.acceptsInsertion.call(this, chr, i);
}

get type() {
return "command";
}
Expand Down

0 comments on commit 4329d8c

Please sign in to comment.