Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 97420

Is there a way to make my own save command that overrides the standard file save keybind?

$
0
0

I'm contributing to an open issue regarding keybindings and custom editors. More specifically, if one were to edit a Markdown file in the standard .md text editor then hit CMD+S, not only does VSCode save the edits on the open file, but it also toggles to the Markdown's preview mode.

Right now, I have a custom editor save command in the works, and the constructor/keybindings is as follows (in TypeScript):

(new class SaveCustomEditorCommand extends Command {
    public static readonly ID = 'editor.action.customEditor.save';

    constructor() {
        super({
            id: SaveCustomEditorCommand.ID,
            precondition: CONTEXT_HAS_CUSTOM_EDITORS,
            kbOpts: {
                primary: KeyMod.CtrlCmd | KeyCode.KEY_S,
                weight: KeybindingWeight.EditorContrib
            }
        });
    }
    ... // fully implemented runCommand function
}).register();

As the command is, hitting CMD+S simply saves the changes and nothing more. However, if I were to change the KeyCode from KEY_S to KEY_Y (since CMD+Y isn't an already existing keybinding command), the save-to-preview command works as intended. Setting the weight property inside kbOpts to higher enums does not change anything.

I'm certain that somewhere in VSCode source, the File/Save CMD+S command takes total precedence, but given that my command should be running only under the precondition that the context has custom editors, I was wondering if I can somehow force my "Save and Preview" command to run instead of the simple, universal "Save" command.

Any pointers or guidance would be much appreciated; this is my first contribution to anything open-source!

If keeping CMD+Y is the more feasible course of action for a "Save and Preview" keybinding, then that works for me, but I would like to least try with CMD+S if possible.


Viewing all articles
Browse latest Browse all 97420

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>