Multi-character IME commit inserts after selection instead of replacing it
Describe the bug
This is a follow-up to issue #3952 , the bug still exists seven years later.
To Reproduce
- Enter insert mode.
- Select existing text in the editor
- Type with an IME and commit a multi-character string (e.g. "你好") with space.
Expect that the selected text is replaced by the committed text (native VS Code behavior). But actual is: The selected text is kept, and the committed text is inserted before/after the selection.
Single-character commits replace the selection correctly.
Screenshots
https://github.com/user-attachments/assets/fdab694b-81f4-4c45-875a-8572c3aef278
Environment (please complete the following information):
- VSCodeVim 1.32.4
- VS Code 1.134
- Windows 11 24H2
Root cause
In src/textEditor.ts:
Path: IME commit → type command (overridden in extensionBase.ts) → handleKeyEvent → TypeInInsertMode → insertTextVSCode transformation → TextEditor.insert().
For text.length === 1, default:type is used and VS Code's native typing semantics replace the selection. For multi-character text, editBuilder.insert() inserts at the end of the selection and never removes the selected range.
The text.length === 1 check exists to avoid VS Code post-typing side effects (auto-closing brackets etc.) on large insertions, but it also drops the selection-replacement semantics of typing.
Source: VSCodeVim/Vim