Skip to content

Commit 3459053

Browse files
committed
🐛 Fix helper/input cancellation on Vim
Fix `helper/input` does not return `null` on <ESC>/<C-c> if the cursor is not at the end of line on Vim.
1 parent ec2d3ab commit 3459053

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

helper/input.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as fn from "../function/mod.ts";
77
import * as lambda from "../lambda/mod.ts";
88
import { execute } from "./execute.ts";
99

10-
const cacheKey = "denops_std/helper/input@2";
10+
const cacheKey = "denops_std/helper/input@3";
1111

1212
async function ensurePrerequisites(denops: Denops): Promise<string> {
1313
if (typeof denops.context[cacheKey] === "string") {
@@ -71,8 +71,8 @@ async function ensurePrerequisites(denops: Denops): Promise<string> {
7171
function! s:input_${suffix}(prompt, text, completion) abort
7272
let originalEsc = maparg('<Esc>', 'c', 0, 1)
7373
let originalInt = maparg('<C-c>', 'c', 0, 1)
74-
execute printf('cnoremap <nowait><buffer> <Esc> <C-u>%s<CR>', s:escape_token_${suffix})
75-
execute printf('cnoremap <nowait><buffer> <C-c> <C-u>%s<CR>', s:escape_token_${suffix})
74+
execute printf('cnoremap <nowait><buffer> <Esc> <C-e><C-u>%s<CR>', s:escape_token_${suffix})
75+
execute printf('cnoremap <nowait><buffer> <C-c> <C-e><C-u>%s<CR>', s:escape_token_${suffix})
7676
try
7777
let result = a:completion is# v:null
7878
\\ ? input(a:prompt, a:text)

helper/input_test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,36 @@ test({
157157
assertEquals(result, null);
158158
},
159159
});
160+
await t.step({
161+
name: "returns `null` when <Esc> is pressed outside EOL",
162+
fn: async () => {
163+
await autocmd.group(denops, "denops_std_helper_input", (helper) => {
164+
helper.remove("*");
165+
helper.define(
166+
"CmdlineEnter",
167+
"*",
168+
`call feedkeys("Hello world!\\<Left>\\<Esc>", "it")`,
169+
);
170+
});
171+
const result = await input(denops);
172+
assertEquals(result, null);
173+
},
174+
});
175+
await t.step({
176+
name: "returns `null` when <C-c> is pressed outside EOL",
177+
fn: async () => {
178+
await autocmd.group(denops, "denops_std_helper_input", (helper) => {
179+
helper.remove("*");
180+
helper.define(
181+
"CmdlineEnter",
182+
"*",
183+
`call feedkeys("Hello world!\\<Left>\\<C-c>", "it")`,
184+
);
185+
});
186+
const result = await input(denops);
187+
assertEquals(result, null);
188+
},
189+
});
160190
await t.step({
161191
name: "should have global mapping restored",
162192
fn: async () => {

0 commit comments

Comments
 (0)