From 34590531c7a65f3c3453e8ad0b40c6c7a8555030 Mon Sep 17 00:00:00 2001 From: mityu Date: Mon, 11 Nov 2024 20:28:36 +0900 Subject: [PATCH] :bug: Fix `helper/input` cancellation on Vim Fix `helper/input` does not return `null` on / if the cursor is not at the end of line on Vim. --- helper/input.ts | 6 +++--- helper/input_test.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/helper/input.ts b/helper/input.ts index 552bccd4..e248c78f 100644 --- a/helper/input.ts +++ b/helper/input.ts @@ -7,7 +7,7 @@ import * as fn from "../function/mod.ts"; import * as lambda from "../lambda/mod.ts"; import { execute } from "./execute.ts"; -const cacheKey = "denops_std/helper/input@2"; +const cacheKey = "denops_std/helper/input@3"; async function ensurePrerequisites(denops: Denops): Promise { if (typeof denops.context[cacheKey] === "string") { @@ -71,8 +71,8 @@ async function ensurePrerequisites(denops: Denops): Promise { function! s:input_${suffix}(prompt, text, completion) abort let originalEsc = maparg('', 'c', 0, 1) let originalInt = maparg('', 'c', 0, 1) - execute printf('cnoremap %s', s:escape_token_${suffix}) - execute printf('cnoremap %s', s:escape_token_${suffix}) + execute printf('cnoremap %s', s:escape_token_${suffix}) + execute printf('cnoremap %s', s:escape_token_${suffix}) try let result = a:completion is# v:null \\ ? input(a:prompt, a:text) diff --git a/helper/input_test.ts b/helper/input_test.ts index 42ffcfb1..50936820 100644 --- a/helper/input_test.ts +++ b/helper/input_test.ts @@ -157,6 +157,36 @@ test({ assertEquals(result, null); }, }); + await t.step({ + name: "returns `null` when is pressed outside EOL", + fn: async () => { + await autocmd.group(denops, "denops_std_helper_input", (helper) => { + helper.remove("*"); + helper.define( + "CmdlineEnter", + "*", + `call feedkeys("Hello world!\\\\", "it")`, + ); + }); + const result = await input(denops); + assertEquals(result, null); + }, + }); + await t.step({ + name: "returns `null` when is pressed outside EOL", + fn: async () => { + await autocmd.group(denops, "denops_std_helper_input", (helper) => { + helper.remove("*"); + helper.define( + "CmdlineEnter", + "*", + `call feedkeys("Hello world!\\\\", "it")`, + ); + }); + const result = await input(denops); + assertEquals(result, null); + }, + }); await t.step({ name: "should have global mapping restored", fn: async () => {