microsoft / microsoft/vscode

`cancelSelection` interferes with extension API `registerCommand("type")`

Open
#331,580 0 comments 0 reactions 1 assignee Claimed by @hediet View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

Does this issue occur when all extensions are disabled?: No, it's a bug with the extension API itself

- VS Code Version: 1.135.0-insider (Universal)
- OS Version: Darwin arm64 25.4.0

Hello, I'm reporting a bug I've noticed where calling `cancelSelection` interferes with extensions that register the `"type"` command. Normally extensions can register `"type"` to intercept all inputs:

```
subscription = vscode.commands.registerCommand("type", onType)
```

This is useful for Vim-style extensions which want to override regular typed letters like "a", "b", "c". Typing those letters are instead intercepted by the `onType` listener, and don't actually type letters.

However, I noticed that when I trigger a `"cancelSelection"` command, the next typed letter will actually get typed, somehow bypassing the `"type"` register command:

https://github.com/user-attachments/assets/b48758c2-b450-4fd1-9acd-7e2bcd05337e

In the above recording I have a `"type"` command registered, configured so that typing the letter "a" will trigger the `"cancelSelection"` command, and typing the letter "j" will trigger the `"cursorDown"` command.

When I press "j" I would expect the cursor to move down one row.

Instead, when I press "j" it removes most of the section I had previously highlighted, only keeping a couple letters. Then it adds "jj".

Some extra information:
* This issue began occurring sometime between 2026-01-01 and 2026-04-23 on stable
* My extension I used to reproduce this (`bmalehorn.vimspired`) hasn't been updated in 3 years, so it's not a change in the extension. You can view the extension source [here](https://github.com/bmalehorn/vscode-vimspired/blob/578eeb3b80979ac87d33799b8485475503f910b4/src/extension.ts)
* It's possible this is a regression in the extension API, and I'd be fine with a workaround my extension can use
* Canceling selection by pressing Escape does not reproduce the issue (so, what's the difference between Escape and `cancelSelection`?)
* This doesn't occur on reverse selection (selecting from right to left)
* This doesn't occur on multiline selections
* The amount of text remaining (above, only 1 character remained) is not consistently 1 character, it's a variable amount between 0 and the whole line
* Different keys (a, j) and different commands (cursorDown) still reproduce the issue

Steps to Reproduce:

1. Install the extension `bmalehorn.vimspired`
2. Set your vscode config to:
```json
{
"vimspired.keybindings": {
"a": "cancelSelection",
"j": "cursorDown",
},
}
```
3. in a file, highlight one line from left to right
4. press "a"
5. press "j"

Expected: the cursor moves down 1 row, no text is modified.
Actual: the previously-highlighted portion is partially deleted and "jj" is added to the end.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.