Search code examples
visual-studio-code

What does `keybindings.editor.copyCommandTitle` do precisely?


When I try to test out keybindings.editor.copyCommandTitle by assigning to it a key, it doesn't seem to do anything. Is this because it does nothing?


Solution

  • When in the keybindings editor and a keybinding is focused, it copies the keybinding's command's title to the clipboard

    KeybindingsRegistry.registerCommandAndKeybindingRule({
      id: KEYBINDINGS_EDITOR_COMMAND_COPY_COMMAND_TITLE,
      weight: KeybindingWeight.WorkbenchContrib,
      when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS),
      primary: 0,
      handler: async (accessor, args: any) => {
          const editorPane = accessor.get(IEditorService).activeEditorPane;
          if (editorPane instanceof KeybindingsEditor) {
              await editorPane.copyKeybindingCommandTitle(editorPane.activeKeybindingEntry!);
          }
      }
    });
    

    ^ copied from https://github.com/microsoft/vscode/blob/111a6f72380eb66d91baf171692be2177df652e8/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts#L1101. Definition of copyKeybindingCommandTitle is in https://github.com/microsoft/vscode/blob/111a6f72380eb66d91baf171692be2177df652e8/src/vs/workbench/contrib/preferences/browser/keybindingsEditor.ts#L300 and does what its name says it does.