diff --git a/runtime/vscode/overrides/vscode-window-commands.vim b/runtime/vscode/overrides/vscode-window-commands.vim index 824bd29..adf4d53 100644 --- a/runtime/vscode/overrides/vscode-window-commands.vim +++ b/runtime/vscode/overrides/vscode-window-commands.vim @@ -34,6 +34,14 @@ function! s:manageEditorWidth(...) endfor endfunction +" A lone runs the builtin window command once 'timeoutlen' passes, and that reads the next key +" without mappings, skipping the ones below. Read the key here instead and feed the whole command +" again, remapped when one of them handles it. +function! s:windowCommand(mode) abort + let keys = "\" . getcharstr() + call feedkeys((v:count ? v:count : '') . keys, (empty(maparg(keytrans(keys), a:mode)) ? 'n' : 'm') . 'i') +endfunction + command! -complete=file -nargs=? Split call split('h', ) command! -complete=file -nargs=? Vsplit call split('v', ) command! -complete=file -nargs=? New call split('h', '__vscode_new__') @@ -46,6 +54,9 @@ AlterCommand new New AlterCommand vne[w] Vnew AlterCommand on[ly] Only +nnoremap call windowCommand('n') +xnoremap call windowCommand('x') + " buffer management nnoremap n call splitNew('h', '__vscode_new__') xnoremap n call splitNew('h', '__vscode_new__') diff --git a/src/test/integ/vscode-integration-specific.test.ts b/src/test/integ/vscode-integration-specific.test.ts index 25bb56e..5133149 100644 --- a/src/test/integ/vscode-integration-specific.test.ts +++ b/src/test/integ/vscode-integration-specific.test.ts @@ -6,7 +6,7 @@ import { strict as assert } from "assert"; import vscode, { Selection } from "vscode"; import { NeovimClient } from "neovim"; -import { wait } from "../../utils"; +import { wait, waitUntil } from "../../utils"; import { attachTestNvimClient, @@ -345,6 +345,22 @@ describe("VSCode integration specific stuff", () => { ); }); + it("Window commands typed after timeoutlen still go to vscode #2466", async () => { + await openTextDocument({ content: "blah" }); + const timeoutlen = (await client.getOption("timeoutlen")) as number; + await client.setOption("timeoutlen", 100); + try { + await sendNeovimKeys(client, "", 500); + await sendNeovimKeys(client, "v"); + await waitUntil(() => + assert.equal(vscode.window.tabGroups.all.length, 2, "v should split the editor"), + ); + } finally { + await client.setOption("timeoutlen", timeoutlen); + await vscode.commands.executeCommand("workbench.action.joinAllGroups"); + } + }); + it("Opens a file through e command", async () => { const filePath = path.join(os.tmpdir(), Math.random().toString()); fs.writeFileSync(filePath, ["line 1"].join("\n"), {