仅在可见时启用键盘快捷键以转义摩纳哥建议小部件

Enable keyboard shortcut for escaping Monaco suggestions widget only when it is visible

我添加了使用 space 栏退出摩纳哥建议小部件的快捷方式,这导致 space 栏不再作为 space 栏工作。 我在想,理想情况下,我只需要添加一个条件,仅当摩纳哥建议小部件可见时才启用快捷方式,这是可行的吗?

到目前为止,这是我的代码:

const hideSuggestions = editor.createContextKey('hideSuggestions', true)

editor.addCommand(
  monaco.KeyCode.Space, function () {editor.trigger('', 'hideSuggestWidget', null) }, 'hideSuggestions' )

我只是缺少一些将 hideSuggestions 从 true 更改为 false 的方法,无论是否触发了摩纳哥建议小部件。

而不是 addCommand 使用更高级的 addAction 方法,它允许指定先决条件:

        const blockContext = "editorTextFocus && !suggestWidgetVisible && !renameInputVisible && !inSnippetMode " +
            "&& !quickFixWidgetVisible";

            editor.addAction({
                id: "executeCurrent",
                label: "Execute Block",
                keybindings: [KeyMod.Shift | KeyCode.Enter],
                contextMenuGroupId: "2_execution",
                precondition: blockContext,
                run: () => { return this.executeCurrentContext(false, false); },
            });

当用户按下 shift+enter.

时,我将其用于 运行 一个动作