From 060e3b298b6271bfb6017dc3c5bb42a6ecfd0f8d Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Sun, 2 Feb 2025 12:34:54 +0900 Subject: [PATCH 01/13] test(popup): add a testcase for relative: cursor --- popup/mod_test.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/popup/mod_test.ts b/popup/mod_test.ts index 01081b6d..06c11a43 100644 --- a/popup/mod_test.ts +++ b/popup/mod_test.ts @@ -105,5 +105,29 @@ test({ }, }); } + + t.step({ + name: `open() with relative cursor`, + fn: async () => { + await denops.cmd("normal! 10G10"); + await using popupWindow = await popup.open(denops, { + relative: "cursor", + width: 20, + height: 20, + row: 3, + col: 3, + }); + console.log(popupWindow.winid); + assertEquals(await fn.win_gettype(denops, popupWindow.winid), "popup"); + assertEquals(await fn.winwidth(denops, popupWindow.winid), 20); + assertEquals(await fn.winheight(denops, popupWindow.winid), 20); + + const info = (await fn.getwininfo(denops, popupWindow.winid))[0]; + assertEquals(info.winrow, 13); + assertEquals(info.wincol, 13); + + await denops.cmd("normal! 0G0"); + }, + }) }, }); From 256b2b9c226519cbc4b01e8a92f7551783d197fa Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Sun, 2 Feb 2025 12:37:02 +0900 Subject: [PATCH 02/13] style: deno fmt --- popup/mod_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/popup/mod_test.ts b/popup/mod_test.ts index 06c11a43..94f234ca 100644 --- a/popup/mod_test.ts +++ b/popup/mod_test.ts @@ -128,6 +128,6 @@ test({ await denops.cmd("normal! 0G0"); }, - }) + }); }, }); From 670613d28c2b119c1321b5ad03f7cb66206aa2c1 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Sun, 2 Feb 2025 12:39:27 +0900 Subject: [PATCH 03/13] test(popup): use await for t.step Signed-off-by: Shinnosuke Sawada-Dazai --- popup/mod_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/popup/mod_test.ts b/popup/mod_test.ts index 94f234ca..1b97839b 100644 --- a/popup/mod_test.ts +++ b/popup/mod_test.ts @@ -106,7 +106,7 @@ test({ }); } - t.step({ + await t.step({ name: `open() with relative cursor`, fn: async () => { await denops.cmd("normal! 10G10"); From 49ee07f5d36f89148c574c60dbc107ad20448ccc Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Sun, 2 Feb 2025 12:47:33 +0900 Subject: [PATCH 04/13] test(popup): add buffer content Signed-off-by: Shinnosuke Sawada-Dazai --- popup/mod_test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/popup/mod_test.ts b/popup/mod_test.ts index 1b97839b..c9e48336 100644 --- a/popup/mod_test.ts +++ b/popup/mod_test.ts @@ -109,7 +109,12 @@ test({ await t.step({ name: `open() with relative cursor`, fn: async () => { - await denops.cmd("normal! 10G10"); + for (let i = 0; i < 10; i++) { + await fn.append(denops, 0, [ + "0123456789", + ]); + } + await denops.cmd("normal! G$"); await using popupWindow = await popup.open(denops, { relative: "cursor", width: 20, From f02618c00d429a2375f8abb8aab5e9a86f48257a Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Sun, 2 Feb 2025 12:51:24 +0900 Subject: [PATCH 05/13] test(popup): remove unnecessary console log Signed-off-by: Shinnosuke Sawada-Dazai --- popup/mod_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/popup/mod_test.ts b/popup/mod_test.ts index c9e48336..1de545c6 100644 --- a/popup/mod_test.ts +++ b/popup/mod_test.ts @@ -122,7 +122,7 @@ test({ row: 3, col: 3, }); - console.log(popupWindow.winid); + assertEquals(await fn.win_gettype(denops, popupWindow.winid), "popup"); assertEquals(await fn.winwidth(denops, popupWindow.winid), 20); assertEquals(await fn.winheight(denops, popupWindow.winid), 20); From 88f227ad191decc767c4953b8cea122d3cada916 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Sun, 2 Feb 2025 13:54:27 +0900 Subject: [PATCH 06/13] test(popup): simplify append call and update cursor position assertions Signed-off-by: Shinnosuke Sawada-Dazai --- popup/mod_test.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/popup/mod_test.ts b/popup/mod_test.ts index 1de545c6..ce076fa9 100644 --- a/popup/mod_test.ts +++ b/popup/mod_test.ts @@ -110,11 +110,10 @@ test({ name: `open() with relative cursor`, fn: async () => { for (let i = 0; i < 10; i++) { - await fn.append(denops, 0, [ - "0123456789", - ]); + await fn.append(denops, 0, "0123456789"); } - await denops.cmd("normal! G$"); + await fn.cursor(denops, [5, 5]); + await using popupWindow = await popup.open(denops, { relative: "cursor", width: 20, @@ -128,10 +127,8 @@ test({ assertEquals(await fn.winheight(denops, popupWindow.winid), 20); const info = (await fn.getwininfo(denops, popupWindow.winid))[0]; - assertEquals(info.winrow, 13); - assertEquals(info.wincol, 13); - - await denops.cmd("normal! 0G0"); + assertEquals(info.winrow, 9); + assertEquals(info.wincol, 8); }, }); }, From ba9ef4b9169adfc058ab513584647043dba8d7c8 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Sun, 2 Feb 2025 13:54:57 +0900 Subject: [PATCH 07/13] feat(popup): support relative: cursor in vim Signed-off-by: Shinnosuke Sawada-Dazai --- popup/vim.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/popup/vim.ts b/popup/vim.ts index f9db6eca..42a7b784 100644 --- a/popup/vim.ts +++ b/popup/vim.ts @@ -37,12 +37,26 @@ function toPopupCreateOptions( }; } +function handleRelative( + relative: "editor" | "cursor", + offset?: number, +): string | number | undefined { + if (offset == undefined) { + return undefined; + } + if (relative == "editor") { + return offset; + } else { + return offset < 0 ? `cursor${offset}` : `cursor+${offset}`; + } +} + function toPopupSetOptionsOptions( options: Partial>, ): vimFn.PopupSetOptionsOptions { const v: vimFn.PopupCreateOptions = { - line: options.row, - col: options.col, + line: handleRelative(options.relative ?? "editor", options.row), + col: handleRelative(options.relative ?? "editor", options.col), pos: options.anchor ? posFromAnchor(options.anchor) : undefined, fixed: true, // To keep consistent with the behavior of Neovim's floating window flip: false, // To keep consistent with the behavior of Neovim's floating window From b878289a5a8d1d42208c8fc254a9e6ed606a2397 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Sun, 2 Feb 2025 13:59:21 +0900 Subject: [PATCH 08/13] test(popup): fix assertion Signed-off-by: Shinnosuke Sawada-Dazai --- popup/mod_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/popup/mod_test.ts b/popup/mod_test.ts index ce076fa9..8cf3891c 100644 --- a/popup/mod_test.ts +++ b/popup/mod_test.ts @@ -127,7 +127,7 @@ test({ assertEquals(await fn.winheight(denops, popupWindow.winid), 20); const info = (await fn.getwininfo(denops, popupWindow.winid))[0]; - assertEquals(info.winrow, 9); + assertEquals(info.winrow, 7); assertEquals(info.wincol, 8); }, }); From 40f437af028405f6f8e1a8c2dfc8b34f2d0cae5e Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Sun, 2 Feb 2025 14:02:15 +0900 Subject: [PATCH 09/13] test(popup): fix assertion Signed-off-by: Shinnosuke Sawada-Dazai --- popup/mod_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/popup/mod_test.ts b/popup/mod_test.ts index 8cf3891c..f58e5a8e 100644 --- a/popup/mod_test.ts +++ b/popup/mod_test.ts @@ -127,8 +127,8 @@ test({ assertEquals(await fn.winheight(denops, popupWindow.winid), 20); const info = (await fn.getwininfo(denops, popupWindow.winid))[0]; - assertEquals(info.winrow, 7); - assertEquals(info.wincol, 8); + assertEquals(info.winrow, 7, "winrow should be 7"); + assertEquals(info.wincol, 7, "wincol should be 7"); }, }); }, From 604f808b4fdf4a6e12052dc6db456e15d1f9619a Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Sun, 2 Feb 2025 14:14:30 +0900 Subject: [PATCH 10/13] test(popup): optimize append calls for relative cursor test Signed-off-by: Shinnosuke Sawada-Dazai --- popup/mod_test.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/popup/mod_test.ts b/popup/mod_test.ts index f58e5a8e..8dc95b98 100644 --- a/popup/mod_test.ts +++ b/popup/mod_test.ts @@ -109,9 +109,18 @@ test({ await t.step({ name: `open() with relative cursor`, fn: async () => { - for (let i = 0; i < 10; i++) { - await fn.append(denops, 0, "0123456789"); - } + await fn.append(denops, 0, [ + "0123456789", + "0123456789", + "0123456789", + "0123456789", + "0123456789", + "0123456789", + "0123456789", + "0123456789", + "0123456789", + "0123456789", + ]); await fn.cursor(denops, [5, 5]); await using popupWindow = await popup.open(denops, { From 9e57f4cdfa2ee11ff900099d1a261387ed818f53 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Sun, 2 Feb 2025 15:39:14 +0900 Subject: [PATCH 11/13] refactor(popup): simplify handleRelative function and improve option handling Signed-off-by: Shinnosuke Sawada-Dazai --- popup/vim.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/popup/vim.ts b/popup/vim.ts index 42a7b784..59c69c67 100644 --- a/popup/vim.ts +++ b/popup/vim.ts @@ -39,15 +39,15 @@ function toPopupCreateOptions( function handleRelative( relative: "editor" | "cursor", - offset?: number, -): string | number | undefined { - if (offset == undefined) { - return undefined; - } - if (relative == "editor") { - return offset; - } else { - return offset < 0 ? `cursor${offset}` : `cursor+${offset}`; + offset: number, +): string | number { + switch (relative) { + case "editor": + return offset; + case "cursor": + return offset < 0 ? `cursor${offset}` : `cursor+${offset}`; + default: + unreachable(relative); } } @@ -55,8 +55,8 @@ function toPopupSetOptionsOptions( options: Partial>, ): vimFn.PopupSetOptionsOptions { const v: vimFn.PopupCreateOptions = { - line: handleRelative(options.relative ?? "editor", options.row), - col: handleRelative(options.relative ?? "editor", options.col), + line: options.row ? handleRelative(options.relative ?? "editor", options.row) : undefined, + col: options.col ? handleRelative(options.relative ?? "editor", options.col) : undefined, pos: options.anchor ? posFromAnchor(options.anchor) : undefined, fixed: true, // To keep consistent with the behavior of Neovim's floating window flip: false, // To keep consistent with the behavior of Neovim's floating window From 912ebaa3a2194c2c694f5b9d827e97f05eeb79c5 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Sun, 2 Feb 2025 15:39:22 +0900 Subject: [PATCH 12/13] test(popup): add anchor property to popup test case Signed-off-by: Shinnosuke Sawada-Dazai --- popup/mod_test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/popup/mod_test.ts b/popup/mod_test.ts index 8dc95b98..16115cd8 100644 --- a/popup/mod_test.ts +++ b/popup/mod_test.ts @@ -129,6 +129,7 @@ test({ height: 20, row: 3, col: 3, + anchor: "NW", }); assertEquals(await fn.win_gettype(denops, popupWindow.winid), "popup"); From 9f077dd40ef3398ed138854de958712709b73e49 Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Mon, 3 Feb 2025 07:36:38 +0900 Subject: [PATCH 13/13] style(popup): deno fmt --- popup/vim.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/popup/vim.ts b/popup/vim.ts index 59c69c67..605f95d2 100644 --- a/popup/vim.ts +++ b/popup/vim.ts @@ -55,8 +55,12 @@ function toPopupSetOptionsOptions( options: Partial>, ): vimFn.PopupSetOptionsOptions { const v: vimFn.PopupCreateOptions = { - line: options.row ? handleRelative(options.relative ?? "editor", options.row) : undefined, - col: options.col ? handleRelative(options.relative ?? "editor", options.col) : undefined, + line: options.row + ? handleRelative(options.relative ?? "editor", options.row) + : undefined, + col: options.col + ? handleRelative(options.relative ?? "editor", options.col) + : undefined, pos: options.anchor ? posFromAnchor(options.anchor) : undefined, fixed: true, // To keep consistent with the behavior of Neovim's floating window flip: false, // To keep consistent with the behavior of Neovim's floating window