How to use the monaco-editor.KeyMod function in monaco-editor

To help you get started, we’ve selected a few monaco-editor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mattgodbolt / compiler-explorer / static / panes / ir-view.js View on Github external
Ir.prototype.initEditorActions = function () {
    this.irEditor.addAction({
        id: 'viewsource',
        label: 'Scroll to source',
        keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.F10],
        keybindingContext: null,
        contextMenuGroupId: 'navigation',
        contextMenuOrder: 1.5,
        run: _.bind(function (ed) {
            var desiredLine = ed.getPosition().lineNumber - 1;
            var source = this.irCode[desiredLine].source;
            if (source !== null && source.file === null) {
                // a null file means it was the user's source
                this.eventHub.emit('editorLinkLine', this._editorid, source.line, -1, true);
            }
        }, this)
    });
};
github mattgodbolt / compiler-explorer / static / panes / compiler.js View on Github external
Compiler.prototype.initEditorActions = function () {
    this.isLabelCtxKey = this.outputEditor.createContextKey('isLabel', true);

    this.outputEditor.addAction({
        id: 'jumptolabel',
        label: 'Jump to label',
        keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter],
        precondition: 'isLabel',
        contextMenuGroupId: 'navigation',
        contextMenuOrder: 1.5,
        run: _.bind(function (ed) {
            this.jumpToLabel(ed.getPosition());
        }, this)
    });

    // Hiding the 'Jump to label' context menu option if no label can be found
    // in the clicked position.
    var contextmenu = this.outputEditor.getContribution('editor.contrib.contextmenu');
    var realMethod = contextmenu._onContextMenu;
    contextmenu._onContextMenu = _.bind(function (e) {
        if (this.isLabelCtxKey && e.target.position) {
            var label = this.getLabelAtPosition(e.target.position);
            this.isLabelCtxKey.set(label);
github open-rpc / playground / src / MonacoJSONEditor.tsx View on Github external
});

    // Vim Mode:
    // Press Chord Ctrl-K, Ctrl-V => the action will run if it is enabled

    editor.addAction({
      // An unique identifier of the contributed action.
      id: "vim-mode",

      // A label of the action that will be presented to the user.
      label: "Vim Mode",

      // An optional array of keybindings for the action.
      keybindings: [
        // chord
        monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_K, monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_V),
      ],
      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: (ed) => {
        this.onVimKeybind();
      },
    });
    /* tslint:enable */
  }
  public onChange() {
github Meituan-Dianping / lyrebird / frontend / src / components / CodeEditor.vue View on Github external
mounted: function(){
        const copyToClipboard = this.copyToClipboard
        this.editor = monaco.editor.create(
            this.$el.querySelector('#code-editor'), 
            {
                value: this.content,
                language: this.language,
                theme: 'vs',
                readOnly: this.readOnly
            }
        );
        this.editor.addAction({
            id: 'json-path',
            label: 'Copy JsonPath',
            keybindings: [
                monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_J)
            ],
            precondition: "editorLangId == 'json'",
            keybindingContext: "editorLangId == 'json'",
            contextMenuGroupId: '9_cutcopypaste',
            contextMenuOrder: 2,
            run: copyToClipboard
        });
        this.editor.onDidChangeModelContent(event => {
            const value = this.editor.getValue()
            if (this.value !== value) {
                this.$emit('change', value, event)
            }
        })
        this.editor.onDidChangeCursorPosition(event => {
            const value = this.editor.getValue()
            const offSet = this.editor.getModel().getOffsetAt(event.position)
github sourcegraph / sourcegraph / packages / webapp / src / settings / MonacoSettingsEditor.tsx View on Github external
setTimeout(() => {
            if (isStandaloneCodeEditor(editor)) {
                editor.addCommand(
                    monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S,
                    () => {
                        if (this.props.onDidSave) {
                            this.props.onDidSave()
                        }
                    },
                    ''
                )
            }
        })
    }
github emilwidlund / carousel / src / components / Editor.tsx View on Github external
componentDidMount() {
        const {options} = this.props;
        this._editor = monaco.editor.create(this._node, options);
        this.props.EditorStore.editor = this._editor;

        this._editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, () => {
            this.props.ProjectStore.saveProject();
        }, '');

        reaction(
            () => this.props.EditorStore.selectedFile,
            (file) => {
                this._editor.setModel(file.model);
            }
        );
    }
github ra-gg / Delir / packages / delir / src / views / KeyframeEditor / ExpressionEditor.tsx View on Github external
public componentDidMount() {
    this.editor = monaco.editor.create(this.editorElement, {
      language: 'javascript',
      codeLens: true,
      automaticLayout: true,
      theme: 'vs-dark',
      minimap: { enabled: false },
      value: this.props.code ? this.props.code : '',
    })

    this.editor.createContextKey('cond1', true)
    this.editor.createContextKey('cond2', true)
    this.disposables.push(this.editor.onDidFocusEditorText(this.onFocusEditor))
    this.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, this.handleClickClose, 'cond1')
    this.editor.focus()
  }
github open-rpc / playground / src / hooks / useMonacoReplaceMetaSchema.tsx View on Github external
useEffect(() => {
    if (!editor) { return; }

    editor.addAction({
      id: "replace-meta-schema",
      label: "Replace Meta Schema",
      keybindings: [
        monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_K, monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_R), //tslint:disable-line
      ],
      contextMenuGroupId: "navigation",
      contextMenuOrder: 1.5,
      run: () => {
        const result = window.prompt("Paste schema to replace current meta schema", "{}");
        if (result) {
          setMetaSchema(JSON.parse(result));
        }
      },
    });
  }, [editor]);
github ra-gg / Delir / packages / delir / src / views / KeyframeEditor / ScriptParamEditor.tsx View on Github external
language: langType,
      codeLens: true,
      automaticLayout: true,
      theme: 'vs-dark',
      minimap: { enabled: false },
      value: code ? code : '',
    })

    editor.createContextKey('cond1', true)
    editor.createContextKey('cond2', true)
    disposables.current.push(
      editor.onDidFocusEditorText(() => {
        MonacoUtil.activateLibrarySet('scriptEditor')
      }),
    )
    editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, handleClose, 'cond1')
    editor.focus()

    editorRef.current = editor

    return () => {
      disposables.current.forEach(d => d.dispose())
      disposables.current = []
      editorRef.current!.dispose()
    }
  }, [target.entityId, target.paramName])
github ra-gg / Delir / packages / delir / views / KeyframeEditor / ExpressionEditor.tsx View on Github external
public componentDidMount() {
        this.editor = monaco.editor.create(this.editorElement, {
            language: 'javascript',
            codeLens: true,
            automaticLayout: true,
            theme: 'vs-dark',
            minimap: { enabled: false },
            value: this.props.code ? this.props.code : '',
        })

        this.editor.createContextKey('cond1', true)
        this.editor.createContextKey('cond2', true)
        this.disposables.push(this.editor.onDidFocusEditorText(this.onFocusEditor))
        this.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, this.handleClickClose, 'cond1')
        this.editor.focus()
    }