Skip to content

Commit f6e575c

Browse files
committed
fix: window placement
also set filter to nil when filter is empty on insert leave
1 parent 04655a2 commit f6e575c

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

lua/nvim-tree/actions/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ local M = {
4040
{ key = "]c", action = "next_git_item" },
4141
{ key = "-", action = "dir_up" },
4242
{ key = "s", action = "system_open" },
43+
{ key = "f", action = "live_filter" },
4344
{ key = "q", action = "close" },
4445
{ key = "g?", action = "toggle_help" },
4546
{ key = "W", action = "collapse_all" },
@@ -64,6 +65,7 @@ local keypress_funcs = {
6465
first_sibling = require("nvim-tree.actions.movements").sibling(-math.huge),
6566
full_rename = require("nvim-tree.actions.rename-file").fn(true),
6667
last_sibling = require("nvim-tree.actions.movements").sibling(math.huge),
68+
live_filter = require("nvim-tree.live-filter").start_filtering,
6769
next_git_item = require("nvim-tree.actions.movements").find_git_item "next",
6870
next_sibling = require("nvim-tree.actions.movements").sibling(1),
6971
parent_node = require("nvim-tree.actions.movements").parent_node(false),

lua/nvim-tree/live-filter.lua

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
-- TODO
22
-- getting the node list should apply the filter first (for get_node_at_cursor for instance)
33
-- custom configuration
4-
-- placement bug with window (see todo/fixme)
54
-- documentation
65
-- more advanced matching algorithm
76
-- asynchronous node discovery when folders are not yet loaded: (might involve performance issues -> max depth search could fix that)
@@ -36,6 +35,11 @@ function M.remove_overlay()
3635
a.nvim_win_close(overlay_winnr, { force = true })
3736
overlay_bufnr = nil
3837
overlay_winnr = nil
38+
39+
if M.filter == "" then
40+
M.filter = nil
41+
redraw()
42+
end
3943
end
4044

4145
local function record_char()
@@ -61,16 +65,13 @@ local function configure_buffer_overloay()
6165
a.nvim_buf_set_keymap(overlay_bufnr, "i", "<C-c>", "<cmd>lua require'nvim-tree.live-filter'.cancel_filter()<cr>", {})
6266
end
6367

64-
-- TODO/FIXME: find why it doesn't properly place the column when the screen is split...
65-
local function create_overlay(row, col)
68+
local function create_overlay()
6669
configure_buffer_overloay()
6770
overlay_winnr = a.nvim_open_win(overlay_bufnr, true, {
68-
col = col + 2,
69-
row = row,
70-
relative = "win",
71-
anchor = "NW",
72-
win = view.get_winnr(),
73-
width = 100,
71+
col = 2,
72+
row = 0,
73+
relative = "cursor",
74+
width = a.nvim_win_get_width(view.get_winnr()) - #M.prefix - 2,
7475
height = 1,
7576
border = "none",
7677
style = "minimal",
@@ -86,8 +87,9 @@ function M.start_filtering()
8687

8788
redraw()
8889
local row = view.hide_root_folder or TreeExplorer.cwd == "/" and 1 or 2
89-
a.nvim_win_set_cursor(view.get_winnr(), { row, #M.prefix })
90-
create_overlay(row - 1, #M.prefix)
90+
view.set_cursor { row, #M.prefix }
91+
-- needs scheduling to let the cursor move before initializing the window
92+
vim.schedule(create_overlay)
9193
end
9294

9395
local function matches(node, filter)

0 commit comments

Comments
 (0)