Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ require('fff').setup({
show_scrollbar = true,
show_file_count = true, -- false hides the matched/total file count next to the prompt
title_position = 'left', -- 'left' | 'center' | 'right'
filename_position = 'left', -- preview title (file path) alignment: 'left' | 'center' | 'right'
path_shorten_strategy = 'middle', -- 'middle' | 'middle_number' | 'end' | 'start'
-- 'center' | 'top' | 'bottom' | 'left' | 'right' | 'top_left' | 'top_right' | 'bottom_left' | 'bottom_right'
anchor = 'center',
Expand Down
1 change: 1 addition & 0 deletions doc/fff.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ Defaults are sensible. Override only what you care about.
show_scrollbar = true,
show_file_count = true, -- false hides the matched/total file count next to the prompt
title_position = 'left', -- 'left' | 'center' | 'right'
filename_position = 'left', -- preview title (file path) alignment: 'left' | 'center' | 'right'
path_shorten_strategy = 'middle', -- 'middle' | 'middle_number' | 'end' | 'start'
-- 'center' | 'top' | 'bottom' | 'left' | 'right' | 'top_left' | 'top_right' | 'bottom_left' | 'bottom_right'
anchor = 'center',
Expand Down
2 changes: 2 additions & 0 deletions lua/fff/conf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local M = {}
--- @field show_scrollbar boolean
--- @field show_file_count boolean
--- @field title_position 'left'|'center'|'right'
--- @field filename_position 'left'|'center'|'right'
--- @field path_shorten_strategy string
--- @field show_path_first boolean
--- @field border? 'single'|'double'|'rounded'|'solid'|'shadow'|'none'|table<string[],string[]> Border preset; falls back to `vim.o.winborder` when nil
Expand Down Expand Up @@ -284,6 +285,7 @@ local function init()
show_scrollbar = true, -- Show scrollbar for pagination
show_file_count = true, -- Show the matched/total file count on the right of the prompt
title_position = 'left', -- or 'center', 'right'
filename_position = 'left', -- preview title (file path) alignment: 'left', 'center', 'right'
-- How to shorten long directory paths in the file list:
-- 'middle' (default): always uses dots (a/./b, a/../b, a/.../b)
-- 'middle_number' uses dots for 1-3 hidden (a/./b, a/../b, a/.../b)
Expand Down
13 changes: 9 additions & 4 deletions lua/fff/layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ end

M.resolve_prompt_position = resolve_prompt_position

function M.resolve_title_pos(value)
if utils.is_one_of(value, { 'left', 'center', 'right' }) then return value end
return 'left'
end

local function resolve_preview_position(config)
if config and config.layout and config.layout.preview_position then
local terminal_width = vim.o.columns
Expand Down Expand Up @@ -255,8 +260,8 @@ local function build_window_configs(layout, config, prompt_position, preview_pos
local border_chars, t_junctions = get_border_chars(config)
local has_preview = layout.preview ~= nil
local title = ' ' .. (config.title or 'FFFiles') .. ' '
local title_pos = config.layout.title_position
if not utils.is_one_of(title_pos, { 'left', 'center', 'right' }) then title_pos = 'left' end
local title_pos = M.resolve_title_pos(config.layout.title_position)
local filename_pos = M.resolve_title_pos(config.layout.filename_position)

local list_neighbour_input_top = prompt_position == 'top'
local list_neighbour_input_bottom = prompt_position == 'bottom'
Expand Down Expand Up @@ -426,7 +431,7 @@ local function build_window_configs(layout, config, prompt_position, preview_pos
border = preview_border,
-- Title hidden when file_info renders above — its footer already says "Preview".
title = layout.file_info and '' or ' Preview ',
title_pos = 'left',
title_pos = filename_pos,
zindex = 51,
}
end
Expand All @@ -451,7 +456,7 @@ local function build_window_configs(layout, config, prompt_position, preview_pos
style = 'minimal',
border = fi_border,
title = ' File Info ',
title_pos = 'left',
title_pos = filename_pos,
-- Above the list/preview zindex so its borders win the shared rows.
zindex = 53,
}
Expand Down
9 changes: 6 additions & 3 deletions lua/fff/picker_ui/preview_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local M = {}

local preview = require('fff.file_picker.preview')
local utils = require('fff.utils')
local layout = require('fff.layout')
local picker_ui_state = require('fff.picker_ui.picker_ui_state')

local canonicalize_fff_path = utils.canonicalize_fff_path
Expand All @@ -14,6 +15,8 @@ function M.init(parent_module) P = parent_module end

local S = picker_ui_state.state

local function filename_pos() return layout.resolve_title_pos(S.config and S.config.layout.filename_position) end

function M.close_preview_timer(timer)
timer = timer or S.preview_timer
if not timer then return end
Expand Down Expand Up @@ -128,7 +131,7 @@ function M.update_preview_title(item, location)

vim.api.nvim_win_set_config(S.preview_win, {
title = title,
title_pos = 'left',
title_pos = filename_pos(),
})
end

Expand Down Expand Up @@ -204,7 +207,7 @@ function M.update_preview()
preview.update_file_info_buffer(item, S.file_info_buf, S.cursor, S.preview_win)
if S.file_info_win and vim.api.nvim_win_is_valid(S.file_info_win) then
local rel = item.relative_path or item.path or ''
pcall(vim.api.nvim_win_set_config, S.file_info_win, { title = ' ' .. rel .. ' ', title_pos = 'left' })
pcall(vim.api.nvim_win_set_config, S.file_info_win, { title = ' ' .. rel .. ' ', title_pos = filename_pos() })
end
end

Expand All @@ -218,7 +221,7 @@ function M.clear_preview()

vim.api.nvim_win_set_config(S.preview_win, {
title = ' Preview ',
title_pos = 'left',
title_pos = filename_pos(),
})

if S.file_info_buf then
Expand Down
31 changes: 31 additions & 0 deletions tests/picker_ui_snap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,37 @@ for _, prompt in ipairs(PROMPT_POSITIONS) do
end
end

T['filename_center'] = MiniTest.new_set({
hooks = {
pre_case = function() setup({ cols = 140, rows = 32 }) end,
post_case = teardown,
},
})

for _, prompt in ipairs(PROMPT_POSITIONS) do
T['filename_center']['empty_' .. prompt] = function()
open_picker(prompt, nil, { filename_position = 'center' })
assert_snapshot_match()
end
end

-- Non-default position on a non-default file: title is re-set on cursor move.
T['filename_right'] = MiniTest.new_set({
hooks = {
pre_case = function() setup({ cols = 140, rows = 32 }) end,
post_case = teardown,
},
})

for _, prompt in ipairs(PROMPT_POSITIONS) do
T['filename_right']['cursor_second_item_' .. prompt] = function()
open_picker(prompt, nil, { filename_position = 'right' })
child.type_keys(prompt == 'bottom' and '<Up>' or '<Down>')
vim.loop.sleep(200)
assert_snapshot_match()
end
end

T['combo'] = MiniTest.new_set({
hooks = {
pre_case = function() setup({ cols = 140, rows = 32 }) end,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
--|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
01|
02|~
03|~
04|~ ┌ FFFiles ────────────────────────────────────────────┬────────────────────── README.md ───────────────────────┐
05|~ │ store.rs src │# Fixture │
06|~ │ state.rs src │ │
07|~ │ runner.rs src │ │
08|~ │ parser.rs src │ │
09|~ │ main_utils.rs src │ │
10|~ │ main_runner.rs src │ │
11|~ │ main_loop.rs src │ │
12|~ │ main_helper.rs src │ │
13|~ │ main.rs src │ │
14|~ │ lib.rs src │ │
15|~ │ error.rs src │ │
16|~ │ config.rs src │ │
17|~ │ cli.rs src │ │
18|~ │ api.rs src │ │
19|~ │ reference.md docs │ │
20|~ │ license.md docs │ │
21|~ │ intro.md docs │ │
22|~ │ guide.md docs │ │
23|~ │ contributing.md docs │ │
24|~ │ changelog.md docs │ │
25|~ │ README.md │ │
26|~ ├─────────────────────────────────────────────────────┤ │
27|~ │> 32 │ │
28|~ └─────────────────────────────────────────────────────┴────────────────────────────────────────────────────────┘
29|~
30|~
31|[No Name] 0,1 All
32|-- INSERT -- 1,3 All

--|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
01|00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
02|11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
03|11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
04|11111111111111123333333332222222222222222222222222222222222222222222222222222222222222222222333333333332222222222222222222222221111111111111
05|11111111111111124422222222255522222222222222222222222222222222222222226666666662222222222222222222222222222222222222222222222221111111111111
06|11111111111111124422222222255522222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
07|11111111111111124422222222225552222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
08|11111111111111124422222222225552222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
09|11111111111111124422222222222222555222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
10|11111111111111124422222222222222255522222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
11|11111111111111124422222222222225552222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
12|11111111111111124422222222222222255522222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
13|11111111111111124422222222555222222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
14|11111111111111124422222225552222222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
15|11111111111111124422222222255522222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
16|11111111111111124422222222225552222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
17|11111111111111124422222225552222222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
18|11111111111111124422222225552222222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
19|11111111111111124422222222222225555222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
20|11111111111111124422222222222555522222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
21|11111111111111124422222222255552222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
22|11111111111111124422222222255552222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
23|11111111111111124422222222222222225555222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
24|11111111111111124422222222222225555222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
25|11111111111111127788888888888888888888888888888888888888888888888888824444444444444444444444444444444444444444444444444444444421111111111111
26|11111111111111122222222222222222222222222222222222222222222222222222224444444444444444444444444444444444444444444444444444444421111111111111
27|11111111111111122222222222222222222222222222222222222222222222222442224444444444444444444444444444444444444444444444444444444421111111111111
28|11111111111111122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222221111111111111
29|11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
30|11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
31|99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
32|::::::::::::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Loading
Loading