简体   繁体   English

仅在可见时为 escaping 摩纳哥建议小部件启用键盘快捷键

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

I've added a shortcut to escape the Monaco suggestions widget with the space bar, which caused the space bar not to work anymore as a space bar.我添加了一个快捷方式来使用空格键退出 Monaco 建议小部件,这导致空格键不再作为空格键工作。 I'm thinking that ideally, I would just have to add a conditional that would enable the shortcut only when the Monaco suggestions widget is visible, is it something that is feasible?我在想,理想情况下,我只需要添加一个条件,仅当摩纳哥建议小部件可见时才启用快捷方式,这是可行的吗?

Here is my code, so far:到目前为止,这是我的代码:

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

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

I'm only missing some way of changing hideSuggestions from true to false whether the Monaco suggestions widget is triggered or not.无论是否触发摩纳哥建议小部件,我只是缺少将hideSuggestions从 true 更改为 false 的一些方法。

Instead of addCommand use the more advanced addAction method, which allows to specify preconditions:而不是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); },
            });

I use this for running an action when the user presses shift + enter .当用户按下shift + enter时,我用它来运行一个动作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM