fix(cursor): keep the visual selection whole over characters outside the BMP

The inclusive Nvim end column was turned into an exclusive VSCode one by
adding a single UTF-16 unit. A character outside the BMP is two of them, so
the selection ended in the middle of a surrogate pair and drifted away from
where Nvim had the cursor: moving right over it took two presses and the
selected region no longer matched.

Step over the whole character instead, using its byte length.

Closes #2535
This commit is contained in:
dualfroz committed 2026-09-13 15:30:08 +02:00
1 parent c0394e311c
commit aa086f6b53
2 files changed
+33 -2

No files matched your search

+19
View File
@@ -1,4 +1,5 @@
import { NeovimClient } from "neovim";
import vscode from "vscode";
import {
attachTestNvimClient,
@@ -286,4 +287,22 @@ describe("Multi-width characters", () => {
client,
);
});
it("Works - visual mode over chars outside the BMP", async () => {
// 𝕜 is U+1D55C: one Nvim character, but two UTF-16 units for VSCode
await openTextDocument({ content: ["a𝕜b"].join("\n") });
await assertContent({ content: ["a𝕜b"], cursor: [0, 0] }, client);
await sendVSCodeKeys("v");
await assertContent({ vsCodeSelections: [new vscode.Selection(0, 0, 0, 1)] }, client);
await sendVSCodeKeys("l");
await assertContent({ vsCodeSelections: [new vscode.Selection(0, 0, 0, 3)] }, client);
await sendVSCodeKeys("l");
await assertContent({ vsCodeSelections: [new vscode.Selection(0, 0, 0, 4)] }, client);
await sendEscapeKey();
});
});