mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 11:47:23 +03:00
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 open
This commit is contained in:
parent
3c5cf3e778
commit
e2dfe888cc
3 changed files with 31 additions and 7 deletions
|
@ -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 a new issue