fix(window): keep window commands typed after timeoutlen in vscode
Once 'timeoutlen' passes after a lone <C-w>, nvim runs its builtin window command, which reads the next key without mappings, so the vscode window mappings were skipped (e.g. <C-w>c closed the nvim window instead of the editor). Map a lone <C-w> to read the next key and feed the whole command again, with its count, remapped when one of the window mappings handles it (special keys like <C-w><C-Down> included). Fixes #2466
This commit is contained in:
1 parent
17cff16264
commit
955555921e
2 files changed
+28
-1
No files matched your search
@@ -34,6 +34,14 @@ function! s:manageEditorWidth(...)
|
|||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" A lone <C-w> 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 = "\<C-w>" . getcharstr()
|
||||||
|
call feedkeys((v:count ? v:count : '') . keys, (empty(maparg(keytrans(keys), a:mode)) ? 'n' : 'm') . 'i')
|
||||||
|
endfunction
|
||||||
|
|
||||||
command! -complete=file -nargs=? Split call <SID>split('h', <q-args>)
|
command! -complete=file -nargs=? Split call <SID>split('h', <q-args>)
|
||||||
command! -complete=file -nargs=? Vsplit call <SID>split('v', <q-args>)
|
command! -complete=file -nargs=? Vsplit call <SID>split('v', <q-args>)
|
||||||
command! -complete=file -nargs=? New call <SID>split('h', '__vscode_new__')
|
command! -complete=file -nargs=? New call <SID>split('h', '__vscode_new__')
|
||||||
@@ -46,6 +54,9 @@ AlterCommand new New
|
|||||||
AlterCommand vne[w] Vnew
|
AlterCommand vne[w] Vnew
|
||||||
AlterCommand on[ly] Only
|
AlterCommand on[ly] Only
|
||||||
|
|
||||||
|
nnoremap <C-w> <Cmd>call <SID>windowCommand('n')<CR>
|
||||||
|
xnoremap <C-w> <Cmd>call <SID>windowCommand('x')<CR>
|
||||||
|
|
||||||
" buffer management
|
" buffer management
|
||||||
nnoremap <C-w>n <Cmd>call <SID>splitNew('h', '__vscode_new__')<CR>
|
nnoremap <C-w>n <Cmd>call <SID>splitNew('h', '__vscode_new__')<CR>
|
||||||
xnoremap <C-w>n <Cmd>call <SID>splitNew('h', '__vscode_new__')<CR>
|
xnoremap <C-w>n <Cmd>call <SID>splitNew('h', '__vscode_new__')<CR>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { strict as assert } from "assert";
|
|||||||
import vscode, { Selection } from "vscode";
|
import vscode, { Selection } from "vscode";
|
||||||
import { NeovimClient } from "neovim";
|
import { NeovimClient } from "neovim";
|
||||||
|
|
||||||
import { wait } from "../../utils";
|
import { wait, waitUntil } from "../../utils";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
attachTestNvimClient,
|
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, "<C-w>", 500);
|
||||||
|
await sendNeovimKeys(client, "v");
|
||||||
|
await waitUntil(() =>
|
||||||
|
assert.equal(vscode.window.tabGroups.all.length, 2, "<C-w>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 () => {
|
it("Opens a file through e command", async () => {
|
||||||
const filePath = path.join(os.tmpdir(), Math.random().toString());
|
const filePath = path.join(os.tmpdir(), Math.random().toString());
|
||||||
fs.writeFileSync(filePath, ["line 1"].join("\n"), {
|
fs.writeFileSync(filePath, ["line 1"].join("\n"), {
|
||||||
|
|||||||
Reference in new issue
Block a user