Skip to content

Commit f612f8e

Browse files
dmtrKovalenkogustav-fff
authored andcommitted
test(ui): cover dir_position=right path overflow
Reserve 2 cols (separator + trailing margin) when right-aligning the directory column so format_file_display can shrink dir_path via the configured path_shorten_strategy without colliding with the filename. Filename is never abbreviated. Adds a deeply-nested fixture file and a narrow-geometry snapshot that exercises the overflow path.
1 parent 80a068c commit f612f8e

48 files changed

Lines changed: 605 additions & 522 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,11 @@ require('fff').setup({
283283
min_list_height = 10, -- do not display anything except the list below this threshold
284284
show_scrollbar = true,
285285
path_shorten_strategy = 'middle_number', -- 'middle_number' | 'middle' | 'end' | 'start'
286-
dir_position = 'left', -- 'left' | 'right' (right-aligns directory column for readability)
286+
-- 'left' : `filename dir/path`
287+
-- 'right' : `filename dir/path`
288+
-- Filename always renders in full; on overflow the directory column is
289+
-- shrunk by `path_shorten_strategy` to fit available space.
290+
dir_position = 'left', -- 'left' | 'right'
287291
anchor = 'center',
288292
},
289293
preview = {

lua/fff/picker_ui/file_renderer.lua

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ function M.render_line(item, ctx, item_idx) -- luacheck: ignore item_idx
4848
end
4949
end
5050

51-
-- Format filename and path
52-
-- Don't reserve space for frecency - path takes priority
51+
-- Format filename and path. Path takes priority over frecency on overflow.
52+
-- Right-align mode reserves 2 extra columns: 1 separating filename from the
53+
-- right-aligned dir virt_text, 1 trailing margin. format_file_display will
54+
-- shrink dir_path to fit; filename is always shown in full.
55+
local right_align_dir = ctx.config.layout and ctx.config.layout.dir_position == 'right'
5356
local icon_width = icon and (vim.fn.strdisplaywidth(icon) + 1) or 0
54-
local available_width = math.max(ctx.max_path_width - icon_width, 40)
57+
local reserved = right_align_dir and 2 or 0
58+
local available_width = math.max(ctx.max_path_width - icon_width - reserved, 40)
5559
local filename, dir_path = ctx.format_file_display(item, available_width)
5660

57-
local right_align_dir = ctx.config.layout and ctx.config.layout.dir_position == 'right'
5861
local inline_dir = right_align_dir and '' or dir_path
5962
local sep = inline_dir == '' and '' or ' '
6063

@@ -87,8 +90,10 @@ function M.apply_highlights(item, ctx, item_idx, buf, ns_id, line_idx, line_cont
8790

8891
-- Get icon and paths
8992
local icon, icon_hl_group = icons.get_icon(item.name, item.extension, false)
93+
local right_align_dir = ctx.config.layout and ctx.config.layout.dir_position == 'right'
9094
local icon_width = icon and (vim.fn.strdisplaywidth(icon) + 1) or 0
91-
local available_width = math.max(ctx.max_path_width - icon_width, 40)
95+
local reserved = right_align_dir and 2 or 0
96+
local available_width = math.max(ctx.max_path_width - icon_width - reserved, 40)
9297
local filename, dir_path = ctx.format_file_display(item, available_width)
9398

9499
-- 1. Cursor highlight
@@ -144,7 +149,6 @@ function M.apply_highlights(item, ctx, item_idx, buf, ns_id, line_idx, line_cont
144149
end
145150

146151
-- 5. Directory path (dimmed)
147-
local right_align_dir = ctx.config.layout and ctx.config.layout.dir_position == 'right'
148152
if #filename > 0 and #dir_path > 0 then
149153
if right_align_dir then
150154
local dir_width = vim.fn.strdisplaywidth(dir_path)

tests/picker_ui_snap.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,26 @@ T['dir_position']['right'] = function()
231231
assert_snapshot_match()
232232
end
233233

234+
-- Long-path overflow: filename must render in full; directory column must be
235+
-- shrunk via path_shorten_strategy to fit the remaining space without
236+
-- colliding with the filename.
237+
T['dir_position_right_overflow'] = MiniTest.new_set({
238+
hooks = {
239+
pre_case = function() setup({ cols = 70, rows = 24, winborder = 'rounded' }) end,
240+
post_case = teardown,
241+
},
242+
})
243+
244+
T['dir_position_right_overflow']['narrow'] = function()
245+
child.lua([[
246+
local conf = require('fff.conf')
247+
local cfg = conf.get()
248+
cfg.layout.dir_position = 'right'
249+
]])
250+
open_picker('bottom', 'very_long_widget_name')
251+
assert_snapshot_match()
252+
end
253+
234254
T['scrollbar'] = MiniTest.new_set({
235255
hooks = {
236256
pre_case = function() setup({ cols = 140, rows = 32 }) end,

tests/screenshots/tests-picker_ui_snap.lua---combo---boost_bottom

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
02|~
44
03|~
55
04|~ ┌ FFFiles ────────────────────────────────────────────┬ src/main.rs ───────────────────────────────────────────┐
6-
05|~ │ │fn main() {} │
7-
06|~ │ table.tsx src/components │ │
8-
07|~ │ list.tsx src/components │ │
9-
08|~ │ dialog.tsx src/components │ │
10-
09|~ │ button.tsx src/components │ │
11-
10|~ │ api.rs src │ │
12-
11|~ │ license.md docs │ │
13-
12|~ │ regression.rs tests │ │
14-
13|~ │ menu.tsx src/components │ │
15-
14|~ │ changelog.md docs │ │
16-
15|~ │ contributing.md docs │ │
17-
16|~ │ integration.rs tests │ │
18-
17|~ │ input.tsx src/components │ │
19-
18|~ │ intro.md docs │ │
6+
05|~ │ table.tsx src/components │fn main() {} │
7+
06|~ │ list.tsx src/components │ │
8+
07|~ │ dialog.tsx src/components │ │
9+
08|~ │ button.tsx src/components │ │
10+
09|~ │ api.rs src │ │
11+
10|~ │ license.md docs │ │
12+
11|~ │ regression.rs tests │ │
13+
12|~ │ menu.tsx src/components │ │
14+
13|~ │ changelog.md docs │ │
15+
14|~ │ contributing.md docs │ │
16+
15|~ │ integration.rs tests │ │
17+
16|~ │ input.tsx src/components │ │
18+
17|~ │ intro.md docs │ │
19+
18|~ │ very_long_widget_name.tsx src/../forms/inputs │ │
2020
19|~ │ main_test.rs tests │ │
2121
20|~ │ main_utils.rs src │ │
2222
21|~ │ main_runner.rs src │ │
@@ -25,7 +25,7 @@
2525
24|~ ├── ↓ Last Match (×4 combo) ──────────────────────────┤ │
2626
25|~ │ main.rs src │ │
2727
26|~ ├─────────────────────────────────────────────────────┤ │
28-
27|~ │> main 19/32 │ │
28+
27|~ │> main 20/33 │ │
2929
28|~ └─────────────────────────────────────────────────────┴────────────────────────────────────────────────────────┘
3030
29|~
3131
30|~
@@ -37,20 +37,20 @@
3737
02|11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
3838
03|11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
3939
04|11111111111111123333333332222222222222222222222222222222222222222222223333333333333222222222222222222222222222222222222222222221111111111111
40-
05|11111111111111124422222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222221111111111111
41-
06|11111111111111124422222222225555555555555522222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
42-
07|11111111111111124422222222255555555555555222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
40+
05|11111111111111124422222222225555555555555522222222222222222222222222222222222222222222222222222222222222222222222222222222222221111111111111
41+
06|11111111111111124422222222255555555555555222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
42+
07|11111111111111124422222222222555555555555552222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
4343
08|11111111111111124422222222222555555555555552222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
44-
09|11111111111111124422222222222555555555555552222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
45-
10|11111111111111124422222225552222222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
46-
11|11111111111111124422222222222555522222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
47-
12|11111111111111124422222222222222555552222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
48-
13|11111111111111124422222222255555555555555222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
49-
14|11111111111111124422222222222225555222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
50-
15|11111111111111124422222222222222225555222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
51-
16|11111111111111124422222222222222255555222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
52-
17|11111111111111124422222222225555555555555522222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
53-
18|11111111111111124422222222255552222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
44+
09|11111111111111124422222225552222222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
45+
10|11111111111111124422222222222555522222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
46+
11|11111111111111124422222222222222555552222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
47+
12|11111111111111124422222222255555555555555222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
48+
13|11111111111111124422222222222225555222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
49+
14|11111111111111124422222222222222225555222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
50+
15|11111111111111124422222222222222255555222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
51+
16|11111111111111124422222222225555555555555522222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
52+
17|11111111111111124422222222255552222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
53+
18|11111111111111124422222222222222222222222222555555555555555555522222224444444444444444444444444444444444444444444444444444444421111111111111
5454
19|11111111111111124466662222222225555522222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
5555
20|11111111111111124466662222222222555222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
5656
21|11111111111111124466662222222222255522222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111

0 commit comments

Comments
 (0)