post-merge fixes, the new keybindings stuff made it messy

This commit is contained in:
Michael Telatynski 2021-05-11 11:14:21 +01:00
parent 60d3da2441
commit 60e7089c77
4 changed files with 52 additions and 55 deletions

View file

@ -161,31 +161,29 @@ const messageComposerBindings = (): KeyBinding<MessageComposerAction>[] => {
const autocompleteBindings = (): KeyBinding<AutocompleteAction>[] => { const autocompleteBindings = (): KeyBinding<AutocompleteAction>[] => {
return [ return [
{ {
action: AutocompleteAction.CompleteOrNextSelection, action: AutocompleteAction.ForceComplete,
keyCombo: { keyCombo: {
key: Key.TAB, key: Key.TAB,
}, },
}, },
{ {
action: AutocompleteAction.CompleteOrNextSelection, action: AutocompleteAction.ForceComplete,
keyCombo: { keyCombo: {
key: Key.TAB, key: Key.TAB,
ctrlKey: true, ctrlKey: true,
}, },
}, },
{ {
action: AutocompleteAction.CompleteOrPrevSelection, action: AutocompleteAction.Complete,
keyCombo: { keyCombo: {
key: Key.TAB, key: Key.ENTER,
shiftKey: true,
}, },
}, },
{ {
action: AutocompleteAction.CompleteOrPrevSelection, action: AutocompleteAction.Complete,
keyCombo: { keyCombo: {
key: Key.TAB, key: Key.ENTER,
ctrlKey: true, ctrlKey: true,
shiftKey: true,
}, },
}, },
{ {

View file

@ -52,13 +52,11 @@ export enum MessageComposerAction {
/** Actions for text editing autocompletion */ /** Actions for text editing autocompletion */
export enum AutocompleteAction { export enum AutocompleteAction {
/** /** Accepts chosen autocomplete selection */
* Select previous selection or, if the autocompletion window is not shown, open the window and select the first Complete = 'Complete',
* selection. /** Accepts chosen autocomplete selection or,
*/ * if the autocompletion window is not shown, open the window and select the first selection */
CompleteOrPrevSelection = 'ApplySelection', ForceComplete = 'ForceComplete',
/** Select next selection or, if the autocompletion window is not shown, open it and select the first selection */
CompleteOrNextSelection = 'CompleteOrNextSelection',
/** Move to the previous autocomplete selection */ /** Move to the previous autocomplete selection */
PrevSelection = 'PrevSelection', PrevSelection = 'PrevSelection',
/** Move to the next autocomplete selection */ /** Move to the next autocomplete selection */

View file

@ -434,6 +434,45 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
private onKeyDown = (event: React.KeyboardEvent) => { private onKeyDown = (event: React.KeyboardEvent) => {
const model = this.props.model; const model = this.props.model;
let handled = false; let handled = false;
const autocompleteAction = getKeyBindingsManager().getAutocompleteAction(event);
if (model.autoComplete && model.autoComplete.hasCompletions()) {
const autoComplete = model.autoComplete;
switch (autocompleteAction) {
case AutocompleteAction.ForceComplete:
case AutocompleteAction.Complete:
autoComplete.confirmCompletion();
handled = true;
break;
case AutocompleteAction.PrevSelection:
autoComplete.selectPreviousSelection();
handled = true;
break;
case AutocompleteAction.NextSelection:
autoComplete.selectNextSelection();
handled = true;
break;
case AutocompleteAction.Cancel:
autoComplete.onEscape(event);
handled = true;
break;
default:
return; // don't preventDefault on anything else
}
} else if (autocompleteAction === AutocompleteAction.ForceComplete) {
// there is no current autocomplete window, try to open it
this.tabCompleteName();
handled = true;
} else if (event.key === Key.BACKSPACE || event.key === Key.DELETE) {
this.formatBarRef.current.hide();
}
if (handled) {
event.preventDefault();
event.stopPropagation();
return;
}
const action = getKeyBindingsManager().getMessageComposerAction(event); const action = getKeyBindingsManager().getMessageComposerAction(event);
switch (action) { switch (action) {
case MessageComposerAction.FormatBold: case MessageComposerAction.FormatBold:
@ -485,42 +524,6 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
handled = true; handled = true;
break; break;
} }
if (handled) {
event.preventDefault();
event.stopPropagation();
return;
}
const autocompleteAction = getKeyBindingsManager().getAutocompleteAction(event);
if (model.autoComplete && model.autoComplete.hasCompletions()) {
const autoComplete = model.autoComplete;
switch (autocompleteAction) {
case AutocompleteAction.CompleteOrPrevSelection:
case AutocompleteAction.PrevSelection:
autoComplete.selectPreviousSelection();
handled = true;
break;
case AutocompleteAction.CompleteOrNextSelection:
case AutocompleteAction.NextSelection:
autoComplete.selectNextSelection();
handled = true;
break;
case AutocompleteAction.Cancel:
autoComplete.onEscape(event);
handled = true;
break;
default:
return; // don't preventDefault on anything else
}
} else if (autocompleteAction === AutocompleteAction.CompleteOrPrevSelection
|| autocompleteAction === AutocompleteAction.CompleteOrNextSelection) {
// there is no current autocomplete window, try to open it
this.tabCompleteName();
handled = true;
} else if (event.key === Key.BACKSPACE || event.key === Key.DELETE) {
this.formatBarRef.current.hide();
}
if (handled) { if (handled) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();

View file

@ -64,7 +64,8 @@ export default class AutocompleteWrapperModel {
return ac && ac.countCompletions() > 0; return ac && ac.countCompletions() > 0;
} }
public onEnter() { public async confirmCompletion() {
await this.getAutocompleterComponent().onConfirmCompletion();
this.updateCallback({close: true}); this.updateCallback({close: true});
} }
@ -76,9 +77,6 @@ export default class AutocompleteWrapperModel {
if (acComponent.countCompletions() === 0) { if (acComponent.countCompletions() === 0) {
// Force completions to show for the text currently entered // Force completions to show for the text currently entered
await acComponent.forceComplete(); await acComponent.forceComplete();
} else {
await acComponent.onConfirmCompletion();
this.updateCallback({close: true});
} }
} }