-
-
Notifications
You must be signed in to change notification settings - Fork 638
refactor(#2988): multi instance change_dir and dir_up #3209
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
base: master
Are you sure you want to change the base?
Changes from all commits
0f2b74b
2a07d7c
d9d70f0
d9124d7
538ad5f
e104ddd
3a6190b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,22 @@ | ||
| local utils = require("nvim-tree.utils") | ||
| local core = require("nvim-tree.core") | ||
| local change_dir = require("nvim-tree.explorer.change-dir") | ||
| local find_file = require("nvim-tree.actions.finders.find-file") | ||
|
|
||
| local M = {} | ||
|
|
||
| ---@param node Node | ||
| function M.fn(node) | ||
|
Member
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 function has been moved to
Member
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. Looks like this file is still present. You might have to
Edit2: this stands: we really don't need this file and it should be removed. |
||
| if not node or node.name == ".." then | ||
| require("nvim-tree.actions.root.change-dir").fn("..") | ||
| change_dir.fn("..") | ||
| else | ||
| local cwd = core.get_cwd() | ||
| if cwd == nil then | ||
| return | ||
| end | ||
|
|
||
| local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(cwd), ":h") | ||
| require("nvim-tree.actions.root.change-dir").fn(newdir) | ||
| require("nvim-tree.actions.finders.find-file").fn(node.absolute_path) | ||
| change_dir.fn(newdir) | ||
| find_file.fn(node.absolute_path) | ||
| end | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,13 +23,18 @@ local Renderer = require("nvim-tree.renderer") | |
|
|
||
| local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON | ||
|
|
||
| local change_dir = require("nvim-tree.explorer.change-dir") | ||
| local find_file = require("nvim-tree.actions.finders.find-file") | ||
|
|
||
|
|
||
| local config | ||
|
|
||
| ---@class (exact) Explorer: RootNode | ||
| ---@field uid_explorer number vim.loop.hrtime() at construction time | ||
| ---@field opts table user options | ||
| ---@field augroup_id integer | ||
| ---@field renderer Renderer | ||
| ---@field change_dir any | ||
|
Member
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 still isn't quite right: we're assigning the static We're stuck at a half way point in the refactor of change dir. The outcome of this issue is to have all of change dir moved into the Explorer class as methods. You've achieved this nicely for Decision time: Option 1:
Option 2:
This is my fault: I said "It might be easiest to split into two PRs." where I should have said "complete these changes in two PRs" I strongly recommend option 2.
Author
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. Thanks for your review once again, I quickly follow instructions and update the PR. |
||
| ---@field filters Filters | ||
| ---@field live_filter LiveFilter | ||
| ---@field sorters Sorter | ||
|
|
@@ -66,6 +71,7 @@ function Explorer:new(args) | |
| self.clipboard = Clipboard({ explorer = self }) | ||
|
|
||
| self:create_autocmds() | ||
| self.change_dir = change_dir | ||
|
|
||
| self:_load(self) | ||
| end | ||
|
|
@@ -665,8 +671,24 @@ function Explorer:get_nodes() | |
| return self:clone() | ||
| end | ||
|
|
||
| ---@param node Node | ||
alex-courtis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| function Explorer:dir_up(node) | ||
| if not node or node.name == ".." then | ||
| change_dir.fn("..") | ||
| else | ||
| local cwd = core.get_cwd() | ||
| if cwd == nil then | ||
| return | ||
| end | ||
| local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(cwd), ":h") | ||
| change_dir.fn(newdir) | ||
| find_file.fn(node.absolute_path) | ||
| end | ||
| end | ||
|
|
||
| function Explorer:setup(opts) | ||
| config = opts | ||
| change_dir.setup(opts) | ||
| end | ||
|
|
||
| return Explorer | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't make unnecessary changes.