Ella
Ella

Reputation: 710

Keybindings: Is there a `when` clause for the index of the focused editor in its group, or if it's the last?

I use keyboard shortcuts to cycle through tabs using workbench.action.nextEditorInGroup and workbench.action.previousEditorInGroup which works great for me except that they "wrap". In other words, if you are on the first tab of an editor group and you execute workbench.action.previousEditorInGroup it will focus the last editor in the group. There doesn't seem to be a setting for preventing this behavior (though if you know of one that would solve my problem!), so I'm hoping to achieve it through the when clause in the keybindings.

I found activeEditorGroupIndex and activeEditorGroupLast, but I have not found a similar clause for the editor index. Does anyone know of one?

Here's my current bindings:

    { "key": "ctrl+.", "command": "workbench.action.nextEditorInGroup", "when": "editorFocus" },
    { "key": "ctrl+,", "command": "workbench.action.previousEditorInGroup", "when": "editorFocus" },

What I'd like is something like:

    { "key": "ctrl+.", "command": "workbench.action.nextEditorInGroup", "when": "editorFocus && !activeEditorLast" },
    { "key": "ctrl+,", "command": "workbench.action.previousEditorInGroup", "when": "editorFocus && !activeEditorIndex == 0" },

Upvotes: 2

Views: 288

Answers (1)

Mark
Mark

Reputation: 182331

These new context keys are in v1.66:

activeEditorIsFirstInGroup  
activeEditorIsLastInGroup

New context keys were added to figure out if an editor is first or last in an editor group:

  • activeEditorIsFirstInGroup- Whether the active editor is the first one in its group.
  • activeEditorIsLastInGroup- Whether the active editor is the last one in its group.

see https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_66.md#new-context-keys-for-editors

I would think these keybindings should work for you:

{ "key": "ctrl+.", "command": "workbench.action.nextEditorInGroup", "when": "editorFocus && !activeEditorIsLastInGroup" },  

{ "key": "ctrl+,", "command": "workbench.action.previousEditorInGroup", "when": "editorFocus && !activeEditorIsFirstInGroup" }

Upvotes: 3

Related Questions