Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable few default keybindings in inline monaco editor #2047

Merged
merged 8 commits into from
Nov 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! handles when the cursorIsMoving outside of the inline formula edit box.

import { Action } from '@/app/actions/actions';
import { defaultActionSpec } from '@/app/actions/defaultActionsSpec';
import { events } from '@/app/events/events';
import { sheets } from '@/app/grid/controller/Sheets';
import { getSingleSelection } from '@/app/grid/sheet/selection';
Expand Down Expand Up @@ -307,6 +308,47 @@ class InlineEditorKeyboard {
}
}

// show go to menu
else if (matchShortcut(Action.ShowGoToMenu, e)) {
e.stopPropagation();
e.preventDefault();
inlineEditorHandler.close(0, 0, false).then(() => {
defaultActionSpec[Action.ShowGoToMenu].run();
});
}

// show find in current sheet
else if (matchShortcut(Action.FindInCurrentSheet, e)) {
e.stopPropagation();
e.preventDefault();
inlineEditorHandler.close(0, 0, false).then(() => {
defaultActionSpec[Action.FindInCurrentSheet].run();
});
}

// show command palette
else if (matchShortcut(Action.ShowCommandPalette, e)) {
e.stopPropagation();
e.preventDefault();
inlineEditorHandler.close(0, 0, false).then(() => {
defaultActionSpec[Action.ShowCommandPalette].run();
});
}

// switch sheet next
else if (matchShortcut(Action.SwitchSheetNext, e)) {
e.stopPropagation();
e.preventDefault();
defaultActionSpec[Action.SwitchSheetNext].run();
}

// switch sheet previous
else if (matchShortcut(Action.SwitchSheetPrevious, e)) {
e.stopPropagation();
e.preventDefault();
defaultActionSpec[Action.SwitchSheetPrevious].run();
}

// trigger cell type menu
else if (matchShortcut(Action.ShowCellTypeMenu, e) && inlineEditorMonaco.get().length === 0) {
e.preventDefault();
Expand Down Expand Up @@ -355,13 +397,7 @@ class InlineEditorKeyboard {
// Resets the keyboard position after cursorIsMoving has ended.
resetKeyboardPosition(skipFocus?: boolean) {
const location = inlineEditorHandler.location;
if (!location) {
return;
}

if (!inlineEditorHandler.cursorIsMoving) {
return;
}
if (!location) return;

inlineEditorHandler.cursorIsMoving = false;
pixiApp.cellHighlights.clearHighlightedCell();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ class InlineEditorMonaco {
language: inlineEditorHandler.formula ? 'formula' : 'inline-editor',
});

this.disableKeybindings();

interface SuggestController {
widget: { value: { onDidShow: (fn: () => void) => void; onDidHide: (fn: () => void) => void } };
}
Expand Down Expand Up @@ -497,6 +499,38 @@ class InlineEditorMonaco {
}
this.editor.trigger(null, 'editor.action.inlineSuggest.trigger', null);
}

disableKeybindings() {
editor.addKeybindingRules([
{
keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyF,
},
{
keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyG,
},
{
keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyL,
},
{
keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyL,
},
{
keybinding: monaco.KeyCode.F1,
},
{
keybinding: monaco.KeyCode.F3,
},
{
keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.F3,
},
{
keybinding: monaco.KeyMod.Shift | monaco.KeyCode.F3,
},
{
keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.F3,
},
]);
}
}

export const inlineEditorMonaco = new InlineEditorMonaco();
Loading