-
-
Notifications
You must be signed in to change notification settings - Fork 623
fix(#1785): retain focused node on filter toggle #2202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
6fdbd53
22ba98f
2a10b4e
55ae145
22dc1bd
c19bf0b
608d2a8
59628ee
28d5360
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,57 @@ | ||
local lib = require "nvim-tree.lib" | ||
local core = require "nvim-tree.core" | ||
local utils = require "nvim-tree.utils" | ||
local filters = require "nvim-tree.explorer.filters" | ||
local reloaders = require "nvim-tree.actions.reloaders.reloaders" | ||
|
||
local M = {} | ||
|
||
local function reload() | ||
local node = lib.get_node_at_cursor() | ||
reloaders.reload_explorer() | ||
local explorer = core.get_explorer() | ||
|
||
if explorer == nil then | ||
return | ||
end | ||
|
||
while node do | ||
local found_node, _ = utils.find_node(explorer.nodes, function(node_) | ||
return node_.absolute_path == node.absolute_path | ||
end) | ||
|
||
if found_node or node.parent == nil then | ||
utils.focus_file(node.absolute_path) | ||
break | ||
end | ||
|
||
node = node.parent | ||
end | ||
end | ||
|
||
function M.custom() | ||
filters.config.filter_custom = not filters.config.filter_custom | ||
return reloaders.reload_explorer() | ||
reload() | ||
end | ||
|
||
function M.git_ignored() | ||
filters.config.filter_git_ignored = not filters.config.filter_git_ignored | ||
return reloaders.reload_explorer() | ||
reload() | ||
end | ||
|
||
function M.git_clean() | ||
filters.config.filter_git_clean = not filters.config.filter_git_clean | ||
return reloaders.reload_explorer() | ||
reload() | ||
end | ||
|
||
function M.no_buffer() | ||
filters.config.filter_no_buffer = not filters.config.filter_no_buffer | ||
return reloaders.reload_explorer() | ||
reload() | ||
end | ||
|
||
function M.dotfiles() | ||
filters.config.filter_dotfiles = not filters.config.filter_dotfiles | ||
return reloaders.reload_explorer() | ||
reload() | ||
end | ||
|
||
return M |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ local view = require "nvim-tree.view" | |
local utils = require "nvim-tree.utils" | ||
local Iterator = require "nvim-tree.iterators.node-iterator" | ||
|
||
-- Keeps memory of focused node when entering filter prompt | ||
local last_node | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be a future problem when we finally sort out multiple trees / tabs. Can you please store this at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, that makes total sense. |
||
|
||
local M = { | ||
filter = nil, | ||
} | ||
|
@@ -134,6 +137,7 @@ local function create_overlay() | |
end | ||
|
||
function M.start_filtering() | ||
last_node = require("nvim-tree.lib").get_node_at_cursor() | ||
M.filter = M.filter or "" | ||
|
||
redraw() | ||
|
@@ -145,9 +149,16 @@ function M.start_filtering() | |
end | ||
|
||
function M.clear_filter() | ||
local node = require("nvim-tree.lib").get_node_at_cursor() | ||
M.filter = nil | ||
reset_filter() | ||
redraw() | ||
|
||
if node then | ||
utils.focus_file(node.absolute_path) | ||
elseif last_node then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This applies only to live filter, not the other toggle filters. Do we need to apply it there as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it would be useful because when toggling any other filter there will always be a focused node, unless the really rare case when a filter gets toggled when the live filter is already applied and the prompt is focused. |
||
utils.focus_file(last_node.absolute_path) | ||
end | ||
end | ||
|
||
function M.setup(opts) | ||
|
Uh oh!
There was an error while loading. Please reload this page.