From b4fc86838e403586bb64df984e0ba17ea26b5090 Mon Sep 17 00:00:00 2001 From: dinhmai74 Date: Sat, 2 Aug 2025 19:45:39 +0700 Subject: [PATCH 1/3] fix: update readme config, update picker_ui config with widht,height and preview --- README.md | 44 +++--------------- lua/fff/main.lua | 14 ++++++ lua/fff/picker_ui.lua | 105 +++++++++++++++++------------------------- 3 files changed, 63 insertions(+), 100 deletions(-) diff --git a/README.md b/README.md index f7569146..e9ed4302 100644 --- a/README.md +++ b/README.md @@ -64,43 +64,6 @@ FFF.nvim requires: } ``` -## Default Configuration - -```lua -require("fff").setup({ - width = 0.8, - height = 0.8, - preview_width = 0.5, - prompt = '🪿 ', - title = 'FFF Files', - max_results = 60, -- Maximum number of search results - max_threads = 4, -- Maximum threads for fuzzy search - - keymaps = { - close = '', - select = '', - select_split = '', - select_vsplit = '', - select_tab = '', - move_up = { '', '' }, - move_down = { '', '' }, - preview_scroll_up = '', - preview_scroll_down = '', - }, - - hl = { - border = 'FloatBorder', - normal = 'Normal', - cursor = 'CursorLine', - matched = 'IncSearch', - title = 'Title', - prompt = 'Question', - active_file = 'Visual', - frecency = 'Number', - debug = 'Comment', - }, -}) -``` ### Default Configuration @@ -111,8 +74,13 @@ require("fff").setup({ -- UI dimensions and appearance width = 0.8, -- Window width as fraction of screen height = 0.8, -- Window height as fraction of screen - preview_width = 0.5, -- Preview pane width as fraction of picker prompt = '🪿 ', -- Input prompt symbol + preview = { + enabled = true, + width = 0.5, + max_lines = 100, + max_size = 1024 * 1024, -- 1MB + }, title = 'FFF Files', -- Window title max_results = 60, -- Maximum search results to display max_threads = 4, -- Maximum threads for fuzzy search diff --git a/lua/fff/main.lua b/lua/fff/main.lua index b5c7cee7..f5bdfcef 100644 --- a/lua/fff/main.lua +++ b/lua/fff/main.lua @@ -11,8 +11,11 @@ function M.setup(config) local default_config = { base_path = vim.fn.getcwd(), max_results = 100, + width = 0.8, + height = 0.8, preview = { enabled = true, + width = 0.5, max_lines = 100, max_size = 1024 * 1024, -- 1MB }, @@ -25,6 +28,17 @@ function M.setup(config) preview_up = '', preview_down = '', }, + hl = { + border = 'FloatBorder', + normal = 'Normal', + cursor = 'CursorLine', + matched = 'IncSearch', + title = 'Title', + prompt = 'Question', + active_file = 'Visual', + frecency = 'Number', + debug = 'Comment', + }, layout = { prompt_position = 'top', preview_position = 'right', diff --git a/lua/fff/picker_ui.lua b/lua/fff/picker_ui.lua index 90fcb5f5..875261e9 100644 --- a/lua/fff/picker_ui.lua +++ b/lua/fff/picker_ui.lua @@ -40,40 +40,6 @@ M.state = { render_debounce_ms = 5, -- Faster rendering for better responsiveness } -local default_config = { - width = 0.8, - height = 0.8, - preview_width = 0.5, - prompt = '🪿 ', - title = 'FFF Files', - max_results = 60, -- Maximum number of search results - max_threads = 4, -- Maximum threads for fuzzy search - - keymaps = { - close = '', - select = '', - select_split = '', - select_vsplit = '', - select_tab = '', - move_up = { '', '' }, - move_down = { '', '' }, - preview_scroll_up = '', - preview_scroll_down = '', - }, - - hl = { - border = 'FloatBorder', - normal = 'Normal', - cursor = 'CursorLine', - matched = 'IncSearch', - title = 'Title', - prompt = 'Question', - active_file = 'Visual', - frecency = 'Number', - debug = 'Comment', - }, -} - --- Create the picker UI function M.create_ui() local config = M.state.config @@ -87,7 +53,7 @@ function M.create_ui() local col = math.floor((vim.o.columns - width) / 2) local row = math.floor((vim.o.lines - height) / 2) - local preview_width = math.floor(width * config.preview_width) -- Full preview width + local preview_width = M.enabled_preview() and math.floor(width * config.preview.width) or 0 local list_width = width - preview_width - 3 -- Account for separators local list_height = height - 4 -- Same as list window height @@ -101,7 +67,7 @@ function M.create_ui() local buf_opts = { false, true } -- nofile, scratch buffer M.state.input_buf = vim.api.nvim_create_buf(buf_opts[1], buf_opts[2]) M.state.list_buf = vim.api.nvim_create_buf(buf_opts[1], buf_opts[2]) - M.state.preview_buf = vim.api.nvim_create_buf(buf_opts[1], buf_opts[2]) + if M.enabled_preview() then M.state.preview_buf = vim.api.nvim_create_buf(buf_opts[1], buf_opts[2]) end if debug_enabled then M.state.file_info_buf = vim.api.nvim_create_buf(buf_opts[1], buf_opts[2]) @@ -140,17 +106,19 @@ function M.create_ui() local preview_row = debug_enabled and (row + file_info_height + 3) or (row + 1) local preview_height_adj = debug_enabled and preview_height or (list_height + 2) - M.state.preview_win = vim.api.nvim_open_win(M.state.preview_buf, false, { - relative = 'editor', - width = preview_width, - height = preview_height_adj, - col = col + list_width + 3, - row = preview_row, - border = 'single', - style = 'minimal', - title = ' PREVIEW TEST TITLE ', - title_pos = 'left', - }) + if M.enabled_preview() then + M.state.preview_win = vim.api.nvim_open_win(M.state.preview_buf, false, { + relative = 'editor', + width = preview_width, + height = preview_height_adj, + col = col + list_width + 3, + row = preview_row, + border = 'single', + style = 'minimal', + title = ' PREVIEW TEST TITLE ', + title_pos = 'left', + }) + end M.state.input_win = vim.api.nvim_open_win(M.state.input_buf, false, { relative = 'editor', @@ -194,9 +162,11 @@ function M.setup_buffers() vim.api.nvim_buf_set_option(M.state.file_info_buf, 'modifiable', false) end - vim.api.nvim_buf_set_option(M.state.preview_buf, 'buftype', 'nofile') - vim.api.nvim_buf_set_option(M.state.preview_buf, 'filetype', 'fff_preview') - vim.api.nvim_buf_set_option(M.state.preview_buf, 'modifiable', false) + if M.enabled_preview() then + vim.api.nvim_buf_set_option(M.state.preview_buf, 'buftype', 'nofile') + vim.api.nvim_buf_set_option(M.state.preview_buf, 'filetype', 'fff_preview') + vim.api.nvim_buf_set_option(M.state.preview_buf, 'modifiable', false) + end end --- Setup window options @@ -217,12 +187,14 @@ function M.setup_windows() vim.api.nvim_win_set_option(M.state.list_win, 'signcolumn', 'yes:1') -- Enable signcolumn for git status borders vim.api.nvim_win_set_option(M.state.list_win, 'foldcolumn', '0') - vim.api.nvim_win_set_option(M.state.preview_win, 'wrap', false) - vim.api.nvim_win_set_option(M.state.preview_win, 'cursorline', false) - vim.api.nvim_win_set_option(M.state.preview_win, 'number', false) - vim.api.nvim_win_set_option(M.state.preview_win, 'relativenumber', false) - vim.api.nvim_win_set_option(M.state.preview_win, 'signcolumn', 'no') - vim.api.nvim_win_set_option(M.state.preview_win, 'foldcolumn', '0') + if M.enabled_preview() then + vim.api.nvim_win_set_option(M.state.preview_win, 'wrap', false) + vim.api.nvim_win_set_option(M.state.preview_win, 'cursorline', false) + vim.api.nvim_win_set_option(M.state.preview_win, 'number', false) + vim.api.nvim_win_set_option(M.state.preview_win, 'relativenumber', false) + vim.api.nvim_win_set_option(M.state.preview_win, 'signcolumn', 'no') + vim.api.nvim_win_set_option(M.state.preview_win, 'foldcolumn', '0') + end end local function normalize_keys(keys) @@ -794,6 +766,7 @@ function M.render_list() end function M.update_preview() + if not M.enabled_preview() then return end if not M.state.active then return end local items = M.state.filtered_items @@ -852,6 +825,7 @@ end --- Clear preview function M.clear_preview() if not M.state.active then return end + if not M.enabled_preview() then return end vim.api.nvim_win_set_config(M.state.preview_win, { title = ' Preview ', @@ -1009,14 +983,12 @@ function M.close() local buffers = { M.state.input_buf, M.state.list_buf, - M.state.preview_buf, M.state.file_info_buf, } - + if M.enabled_preview() then buffers[#buffers + 1] = M.state.preview_buf end + for _, buf in ipairs(buffers) do - if buf and vim.api.nvim_buf_is_valid(buf) then - vim.api.nvim_buf_delete(buf, { force = true }) - end + if buf and vim.api.nvim_buf_is_valid(buf) then vim.api.nvim_buf_delete(buf, { force = true }) end end M.state.input_win = nil @@ -1069,7 +1041,7 @@ function M.open(opts) end end - M.state.config = vim.tbl_deep_extend('force', default_config, opts or {}) + M.state.config = main.config if not M.create_ui() then vim.notify('Failed to create picker UI', vim.log.levels.ERROR) @@ -1106,4 +1078,13 @@ function M.monitor_scan_progress() end end +M.enabled_preview = function() + local preview = nil + if M and M.state and M.state.config then preview = M.state.config.preview end + + if not preview then return true end + + return preview.enabled +end + return M From a97eeaf39e19499158eaffd9a8d49c3f738295d0 Mon Sep 17 00:00:00 2001 From: dinhmai74 Date: Sat, 2 Aug 2025 20:08:05 +0700 Subject: [PATCH 2/3] fix: update default picker_ui opt to main --- lua/fff/main.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/fff/main.lua b/lua/fff/main.lua index f5bdfcef..2e6a1038 100644 --- a/lua/fff/main.lua +++ b/lua/fff/main.lua @@ -11,6 +11,8 @@ function M.setup(config) local default_config = { base_path = vim.fn.getcwd(), max_results = 100, + prompt = '🪿 ', -- Input prompt symbol + title = 'FFF Files', -- Window title width = 0.8, height = 0.8, preview = { From 272bdccf1f729ba1da1c9d3d840f328a182440bf Mon Sep 17 00:00:00 2001 From: dinhmai74 Date: Sat, 2 Aug 2025 20:30:25 +0700 Subject: [PATCH 3/3] fix: update default keymaps --- lua/fff/main.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lua/fff/main.lua b/lua/fff/main.lua index 2e6a1038..92d2744e 100644 --- a/lua/fff/main.lua +++ b/lua/fff/main.lua @@ -22,13 +22,15 @@ function M.setup(config) max_size = 1024 * 1024, -- 1MB }, keymaps = { - select = '', - vsplit = '', - split = '', - tab = '', close = '', - preview_up = '', - preview_down = '', + select = '', + select_split = '', + select_vsplit = '', + select_tab = '', + move_up = { '', '' }, + move_down = { '', '' }, + preview_scroll_up = '', + preview_scroll_down = '', }, hl = { border = 'FloatBorder',