mirror of https://github.com/vector-im/riot-web
only capture Enter when autocompletion list has selection
this is the old behaviour and makes sense IMO also close the auto complete when resetting the composer model, in case it was still openpull/21833/head
parent
3c5cf3e778
commit
e2dfe888cc
|
@ -203,19 +203,32 @@ export default class BasicMessageEditor extends React.Component {
|
|||
const autoComplete = model.autoComplete;
|
||||
switch (event.key) {
|
||||
case "Enter":
|
||||
autoComplete.onEnter(event); break;
|
||||
// only capture enter when something is selected in the list,
|
||||
// otherwise don't handle so the contents of the composer gets sent
|
||||
if (autoComplete.hasSelection()) {
|
||||
autoComplete.onEnter(event);
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
case "ArrowUp":
|
||||
autoComplete.onUpArrow(event); break;
|
||||
autoComplete.onUpArrow(event);
|
||||
handled = true;
|
||||
break;
|
||||
case "ArrowDown":
|
||||
autoComplete.onDownArrow(event); break;
|
||||
autoComplete.onDownArrow(event);
|
||||
handled = true;
|
||||
break;
|
||||
case "Tab":
|
||||
autoComplete.onTab(event); break;
|
||||
autoComplete.onTab(event);
|
||||
handled = true;
|
||||
break;
|
||||
case "Escape":
|
||||
autoComplete.onEscape(event); break;
|
||||
autoComplete.onEscape(event);
|
||||
handled = true;
|
||||
break;
|
||||
default:
|
||||
return; // don't preventDefault on anything else
|
||||
}
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
if (handled) {
|
||||
|
|
|
@ -33,6 +33,10 @@ export default class AutocompleteWrapperModel {
|
|||
});
|
||||
}
|
||||
|
||||
hasSelection() {
|
||||
return this._getAutocompleterComponent().hasSelection();
|
||||
}
|
||||
|
||||
onEnter() {
|
||||
this._updateCallback({close: true});
|
||||
}
|
||||
|
@ -103,7 +107,7 @@ export default class AutocompleteWrapperModel {
|
|||
}
|
||||
case "#":
|
||||
return this._partCreator.roomPill(completionId);
|
||||
// also used for emoji completion
|
||||
// used for emoji and command completion replacement
|
||||
default:
|
||||
return this._partCreator.plain(text);
|
||||
}
|
||||
|
|
|
@ -105,6 +105,13 @@ export default class EditorModel {
|
|||
|
||||
reset(serializedParts, caret, inputType) {
|
||||
this._parts = serializedParts.map(p => this._partCreator.deserializePart(p));
|
||||
// close auto complete if open
|
||||
// this would happen when clearing the composer after sending
|
||||
// a message with the autocomplete still open
|
||||
if (this._autoComplete) {
|
||||
this._autoComplete = null;
|
||||
this._autoCompletePartIdx = null;
|
||||
}
|
||||
this._updateCallback(caret, inputType);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue