Skip to content

Commit 57a49d2

Browse files
committed
fix(win): relative=cursor layout
1 parent d32b062 commit 57a49d2

4 files changed

Lines changed: 91 additions & 6 deletions

File tree

lua/fzf-lua/win.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,12 @@ function FzfWin:normalize_winopts()
612612
winopts.row = math.floor((winopts.row or 0) + screenpos.row - 1)
613613
winopts.col = math.floor((winopts.col or 0) + screenpos.col - 1)
614614
winopts.relative = nil
615-
else
616-
-- make row close to the center of screen (include cmdheight)
617-
-- avoid breaking existing test
618-
winopts.row = self:normalize_size(assert(tonumber(winopts.row)), vim.o.lines - winopts.height)
619-
winopts.col = self:normalize_size(assert(tonumber(winopts.col)), max_width - winopts.width)
620-
winopts.row = math.min(winopts.row, max_height - winopts.height)
621615
end
616+
-- make row close to the center of screen (include cmdheight)
617+
-- avoid breaking existing test
618+
winopts.row = self:normalize_size(assert(tonumber(winopts.row)), vim.o.lines - winopts.height)
619+
winopts.col = self:normalize_size(assert(tonumber(winopts.col)), max_width - winopts.width)
620+
winopts.row = math.min(winopts.row, max_height - winopts.height)
622621
-- width/height can be used for text area
623622
winopts.width = math.max(1, winopts.width - w)
624623
winopts.height = math.max(1, winopts.height - h)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--|---------|---------|---------|---------|---------|---------|----
2+
01|╭──────────foo──────────╮╭────────────────────────╮
3+
02|│ 1 SELECTED FILE: foo ││> 3/3 │
4+
03|│ ││─────────────────────── │
5+
04|│ ││▌ foo │
6+
05|│ ││ bar │
7+
06|│ ││ baz │
8+
07|│ ││ │
9+
08|│ ││ │
10+
09|│ ││ │
11+
10|│ ││ │
12+
11|│ ││ │
13+
12|│ ││ │
14+
13|│ ││ │
15+
14|│ ││ │
16+
15|│ ││ │
17+
16|│ ││ │
18+
17|│ ││ │
19+
18|│ ││ │
20+
19|│ ││ │
21+
20|╰───────────────────────╯╰────────────────────────╯
22+
21|~
23+
22|~
24+
23|~
25+
24|[No Name] 0,0-1 All
26+
25|
27+
26|
28+
27|
29+
28|-- TERMINAL -- 1,3 All
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--|---------|---------|---------|---------|---------|---------|----
2+
01|aaaaaaaaaaaaa╭──────────foo──────────╮╭────────────────────────╮
3+
02|~ │ 1 SELECTED FILE: foo ││> 3/3 │
4+
03|~ │ ││─────────────────────── │
5+
04|~ │ ││▌ foo │
6+
05|~ │ ││ bar │
7+
06|~ │ ││ baz │
8+
07|~ │ ││ │
9+
08|~ │ ││ │
10+
09|~ │ ││ │
11+
10|~ │ ││ │
12+
11|~ │ ││ │
13+
12|~ │ ││ │
14+
13|~ │ ││ │
15+
14|~ │ ││ │
16+
15|~ │ ││ │
17+
16|~ │ ││ │
18+
17|~ │ ││ │
19+
18|~ │ ││ │
20+
19|~ │ ││ │
21+
20|~ ╰───────────────────────╯╰────────────────────────╯
22+
21|~
23+
22|~
24+
23|~
25+
24|[No Name] [+] 1,64 All
26+
25|
27+
26|
28+
27|
29+
28|-- TERMINAL -- 1,3 All

tests/win_spec.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,34 @@ T["win"]["toggle"][""] = new_set(
310310
end
311311
})
312312

313+
T["win"]["relative=cursor"] = function()
314+
-- Ignore terminal command line with process number
315+
local screen_opts = { ignore_text = { 24, 28 }, normalize_paths = helpers.IS_WIN() }
316+
local opts = {
317+
__expect_lines = true,
318+
__screen_opts = screen_opts,
319+
winopts = {
320+
relative = "cursor",
321+
preview = { layout = "horizontal", horizontal = "left:50%" }
322+
},
323+
previewer = function() return require("fzf-lua.test.previewer").builtin end,
324+
__after_open = function()
325+
child.wait_until(function() return child.lua_get([[_G._fzf_load_called]]) == true end)
326+
if helpers.IS_WIN() then vim.uv.sleep(250) end
327+
end,
328+
}
329+
helpers.FzfLua.fzf_exec(child, { "foo", "bar", "baz" }, opts)
330+
child.cmd([[enew]])
331+
set_lines({ ("a"):rep(child.o.columns) })
332+
type_keys("g$")
333+
-- pretend we closed the window to make helpers won't wait for new open
334+
exec_lua([[_G._fzf_lua_on_create = nil]])
335+
exec_lua([[_G._fzf_load_called = nil]])
336+
helpers.FzfLua.fzf_exec(child, { "foo", "bar", "baz" }, opts)
337+
child.cmd([[bwipe!]])
338+
end
339+
340+
313341
T["win"]["reuse"] = new_set({
314342
parametrize = {
315343
{ {} },

0 commit comments

Comments
 (0)