简体   繁体   English

我如何获得摩纳哥编辑器操作键绑定 label

[英]How I get monaco editor Action keybindings label

I am usig monaco editor and my question is how can I get InternalEditorAction keybindings label text.我是 usig monaco 编辑器,我的问题是如何获取 InternalEditorAction 键绑定 label 文本。 Like in the context menu:就像在上下文菜单中一样:

在此处输入图像描述

Get actions in monaco playground摩纳哥游乐场获取动作

    var editor = monaco.editor.create(document.getElementById("container"), {
    value: [
        '',
        'class Example {',
        '\tprivate m:number;',
        '',
        '\tpublic met(): string {',
        '\t\treturn "Hello world!";',
        '\t}',
        '}'
    ].join('\n'),
    language: "typescript"
});


editor.addAction({
    // An unique identifier of the contributed action.
    id: 'my-unique-id',

    // A label of the action that will be presented to the user.
    label: 'My Label!!!',

    // An optional array of keybindings for the action.
    keybindings: [
        monaco.KeyMod.CtrlCmd | monaco.KeyCode.F10,
    ],

    // A precondition for this action.
    precondition: null,

    // A rule to evaluate on top of the precondition in order to dispatch the keybindings.
    keybindingContext: null,

    contextMenuGroupId: 'navigation',

    contextMenuOrder: 1.5,

    // Method that will be executed when the action is triggered.
    // @param editor The editor instance is passed in as a convinience
    run: function (ed) {
        const actions = ed.getActions();
        console.log(actions[0])
 
        return null;
    }
});

Monaco Editor default keybindings:摩纳哥编辑器默认键绑定:

  • editor._standaloneKeybindingService._cachedResolver._defaultKeybindings editor._standaloneKeybindingService._cachedResolver._defaultKeybindings
  • editor._standaloneKeybindingService._getResolver()._defaultKeybindings editor._standaloneKeybindingService._getResolver()._defaultKeybindings

Example:例子:

const defaultKeybindings = editor._standaloneKeybindingService._getResolver()._defaultKeybindings;
const _id = 'editor.action.goToReferences';
const keyPart = defaultKeybindings.find(x => x.command === _id).keypressParts;

console.log(keyPart); // ['shift+F12']

ref: https://github.com/microsoft/monaco-editor/issues/287#issuecomment-521166743参考: https://github.com/microsoft/monaco-editor/issues/287#issuecomment-521166743

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

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