Skip to content

Commit 3e2b67a

Browse files
authored
Merge branch 'master' into fix/rename
2 parents 1150409 + 2ede0de commit 3e2b67a

File tree

9 files changed

+158
-23
lines changed

9 files changed

+158
-23
lines changed

.github/workflows/luarocks-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v4
1212
- name: LuaRocks Upload
13-
uses: nvim-neorocks/luarocks-tag-release@v5
13+
uses: nvim-neorocks/luarocks-tag-release@v7
1414
env:
1515
LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}
1616
with:

.github/workflows/semantic-pr-subject.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ jobs:
1414
semantic-pr-subject:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: amannn/[email protected].2
17+
- uses: amannn/[email protected].3
1818
env:
1919
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

doc/nvim-tree-lua.txt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,13 @@ Following is the default configuration. See |nvim-tree-opts| for details.
620620
default_yes = false,
621621
},
622622
},
623-
experimental = {},
623+
experimental = {
624+
actions = {
625+
open_file = {
626+
relative_path = false,
627+
},
628+
},
629+
},
624630
log = {
625631
enable = false,
626632
truncate = false,
@@ -1539,6 +1545,12 @@ Confirmation prompts.
15391545
Experimental features that may become default or optional functionality.
15401546
In the event of a problem please disable the experiment and raise an issue.
15411547

1548+
*nvim-tree.experimental.actions.open_file.relative_path*
1549+
Buffers opened by nvim-tree will use with relative paths instead of
1550+
absolute.
1551+
Execute |:ls| to see the paths of all open buffers.
1552+
Type: `boolean`, Default: `false`
1553+
15421554
==============================================================================
15431555
5.20 OPTS: LOG *nvim-tree-opts-log*
15441556

@@ -1658,6 +1670,22 @@ tree.focus() *nvim-tree-api.tree.focus()*
16581670
tree.reload() *nvim-tree-api.tree.reload()*
16591671
Refresh the tree. Does nothing if closed.
16601672

1673+
tree.resize({opts}) *nvim-tree-api.tree.resize()*
1674+
Resize the tree, persisting the new size.
1675+
Resets to |nvim-tree.view.width| when no {opts} provided.
1676+
See |:NvimTreeResize|
1677+
1678+
Parameters: ~
1679+
{opts} (table) optional parameters
1680+
1681+
Options: ~
1682+
{width} (table) new |nvim-tree.view.width| value
1683+
{absolute} (number) set the width
1684+
{relative} (number) increase or decrease the width
1685+
1686+
Only one option is supported, in the priority order above.
1687+
{absolute} and {relative} do nothing when {width} is a function.
1688+
16611689
tree.change_root({path}) *nvim-tree-api.tree.change_root()*
16621690
Change the tree's root to a path.
16631691

@@ -2774,6 +2802,7 @@ highlight group is not, hard linking as follows: >
27742802
|nvim-tree.diagnostics.show_on_open_dirs|
27752803
|nvim-tree.disable_netrw|
27762804
|nvim-tree.experimental|
2805+
|nvim-tree.experimental.actions.open_file.relative_path|
27772806
|nvim-tree.filesystem_watchers.debounce_delay|
27782807
|nvim-tree.filesystem_watchers.enable|
27792808
|nvim-tree.filesystem_watchers.ignore_dirs|
@@ -2988,6 +3017,7 @@ highlight group is not, hard linking as follows: >
29883017
|nvim-tree-api.tree.is_visible()|
29893018
|nvim-tree-api.tree.open()|
29903019
|nvim-tree-api.tree.reload()|
3020+
|nvim-tree-api.tree.resize()|
29913021
|nvim-tree-api.tree.search_node()|
29923022
|nvim-tree-api.tree.toggle()|
29933023
|nvim-tree-api.tree.toggle_custom_filter()|

lua/nvim-tree.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,13 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
584584
default_yes = false,
585585
},
586586
},
587-
experimental = {},
587+
experimental = {
588+
actions = {
589+
open_file = {
590+
relative_path = false,
591+
},
592+
},
593+
},
588594
log = {
589595
enable = false,
590596
truncate = false,

lua/nvim-tree/actions/node/open-file.lua

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,29 @@ local function open_file_in_tab(filename)
190190
if M.quit_on_open then
191191
view.close()
192192
end
193+
if M.relative_path then
194+
filename = utils.path_relative(filename, vim.fn.getcwd())
195+
end
193196
vim.cmd("tabe " .. vim.fn.fnameescape(filename))
194197
end
195198

196199
local function drop(filename)
197200
if M.quit_on_open then
198201
view.close()
199202
end
203+
if M.relative_path then
204+
filename = utils.path_relative(filename, vim.fn.getcwd())
205+
end
200206
vim.cmd("drop " .. vim.fn.fnameescape(filename))
201207
end
202208

203209
local function tab_drop(filename)
204210
if M.quit_on_open then
205211
view.close()
206212
end
213+
if M.relative_path then
214+
filename = utils.path_relative(filename, vim.fn.getcwd())
215+
end
207216
vim.cmd("tab :drop " .. vim.fn.fnameescape(filename))
208217
end
209218

@@ -310,7 +319,21 @@ local function open_in_new_window(filename, mode)
310319
end
311320
end
312321

313-
local fname = utils.escape_special_chars(vim.fn.fnameescape(filename))
322+
if (mode == "preview" or mode == "preview_no_picker") and view.View.float.enable then
323+
-- ignore "WinLeave" autocmd on preview
324+
-- because the registered "WinLeave"
325+
-- will kill the floating window immediately
326+
set_current_win_no_autocmd(target_winid, { "WinLeave", "BufEnter" })
327+
else
328+
set_current_win_no_autocmd(target_winid, { "BufEnter" })
329+
end
330+
331+
local fname
332+
if M.relative_path then
333+
fname = utils.escape_special_chars(vim.fn.fnameescape(utils.path_relative(filename, vim.fn.getcwd())))
334+
else
335+
fname = utils.escape_special_chars(vim.fn.fnameescape(filename))
336+
end
314337

315338
local command
316339
if create_new_window then
@@ -322,15 +345,6 @@ local function open_in_new_window(filename, mode)
322345
command = { cmd = "edit", args = { fname } }
323346
end
324347

325-
if (mode == "preview" or mode == "preview_no_picker") and view.View.float.enable then
326-
-- ignore "WinLeave" autocmd on preview
327-
-- because the registered "WinLeave"
328-
-- will kill the floating window immediately
329-
set_current_win_no_autocmd(target_winid, { "WinLeave", "BufEnter" })
330-
else
331-
set_current_win_no_autocmd(target_winid, { "BufEnter" })
332-
end
333-
334348
pcall(vim.api.nvim_cmd, command, { output = false })
335349
lib.set_target_win()
336350
end
@@ -346,6 +360,9 @@ end
346360

347361
local function edit_in_current_buf(filename)
348362
require("nvim-tree.view").abandon_current_window()
363+
if M.relative_path then
364+
filename = utils.path_relative(filename, vim.fn.getcwd())
365+
end
349366
vim.cmd("keepalt keepjumps edit " .. vim.fn.fnameescape(filename))
350367
end
351368

@@ -402,6 +419,7 @@ end
402419
function M.setup(opts)
403420
M.quit_on_open = opts.actions.open_file.quit_on_open
404421
M.resize_window = opts.actions.open_file.resize_window
422+
M.relative_path = opts.experimental.actions.open_file.relative_path
405423
if opts.actions.open_file.window_picker.chars then
406424
opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper()
407425
end

lua/nvim-tree/actions/tree/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ M.find_file = require "nvim-tree.actions.tree.find-file"
44
M.modifiers = require "nvim-tree.actions.tree.modifiers"
55
M.open = require "nvim-tree.actions.tree.open"
66
M.toggle = require "nvim-tree.actions.tree.toggle"
7+
M.resize = require "nvim-tree.actions.tree.resize"
78

89
function M.setup(opts)
910
M.find_file.setup(opts)
1011
M.modifiers.setup(opts)
1112
M.open.setup(opts)
1213
M.toggle.setup(opts)
14+
M.resize.setup(opts)
1315
end
1416

1517
return M

lua/nvim-tree/actions/tree/resize.lua

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
local view = require "nvim-tree.view"
2+
3+
local M = {}
4+
5+
---Resize the tree, persisting the new size.
6+
---@param opts ApiTreeResizeOpts|nil
7+
function M.fn(opts)
8+
if opts == nil then
9+
-- reset to config values
10+
view.configure_width()
11+
view.resize()
12+
return
13+
end
14+
15+
local options = opts or {}
16+
local width_cfg = options.width
17+
18+
if width_cfg ~= nil then
19+
view.configure_width(width_cfg)
20+
view.resize()
21+
return
22+
end
23+
24+
if not view.is_width_determined() then
25+
-- {absolute} and {relative} do nothing when {width} is a function.
26+
return
27+
end
28+
29+
local absolute = options.absolute
30+
if type(absolute) == "number" then
31+
view.resize(absolute)
32+
return
33+
end
34+
35+
local relative = options.relative
36+
if type(relative) == "number" then
37+
local relative_size = tostring(relative)
38+
if relative > 0 then
39+
relative_size = "+" .. relative_size
40+
end
41+
42+
view.resize(relative_size)
43+
return
44+
end
45+
end
46+
47+
function M.setup(opts)
48+
M.config = opts or {}
49+
end
50+
51+
return M

lua/nvim-tree/api.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ Api.tree.close_in_this_tab = wrap(view.close_this_tab_only)
100100
Api.tree.close_in_all_tabs = wrap(view.close_all_tabs)
101101
Api.tree.reload = wrap(actions.reloaders.reload_explorer)
102102

103+
---@class ApiTreeResizeOpts
104+
---@field width string|function|number|table|nil
105+
---@field absolute number|nil
106+
---@field relative number|nil
107+
108+
Api.tree.resize = wrap(actions.tree.resize.fn)
109+
103110
Api.tree.change_root = wrap(function(...)
104111
require("nvim-tree").change_dir(...)
105112
end)

lua/nvim-tree/view.lua

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,34 @@ function M.reset_winhl()
548548
end
549549
end
550550

551+
---Check if width determined or calculated on-fly
552+
---@return boolean
553+
function M.is_width_determined()
554+
return type(M.View.width) ~= "function"
555+
end
556+
557+
---Configure width-related config
558+
---@param width string|function|number|table|nil
559+
function M.configure_width(width)
560+
if type(width) == "table" then
561+
M.View.adaptive_size = true
562+
M.View.width = width.min or DEFAULT_MIN_WIDTH
563+
M.View.max_width = width.max or DEFAULT_MAX_WIDTH
564+
M.View.padding = width.padding or DEFAULT_PADDING
565+
elseif width == nil then
566+
if M.config.width ~= nil then
567+
-- if we had input config - fallback to it
568+
M.configure_width(M.config.width)
569+
else
570+
-- otherwise - restore initial width
571+
M.View.width = M.View.initial_width
572+
end
573+
else
574+
M.View.adaptive_size = false
575+
M.View.width = width
576+
end
577+
end
578+
551579
function M.setup(opts)
552580
local options = opts.view or {}
553581
M.View.centralize_selection = options.centralize_selection
@@ -563,15 +591,8 @@ function M.setup(opts)
563591
M.View.float = options.float
564592
M.on_attach = opts.on_attach
565593

566-
if type(options.width) == "table" then
567-
M.View.adaptive_size = true
568-
M.View.width = options.width.min or DEFAULT_MIN_WIDTH
569-
M.View.max_width = options.width.max or DEFAULT_MAX_WIDTH
570-
M.View.padding = options.width.padding or DEFAULT_PADDING
571-
else
572-
M.View.adaptive_size = false
573-
M.View.width = options.width
574-
end
594+
M.config = options
595+
M.configure_width(options.width)
575596

576597
M.View.initial_width = get_width()
577598
end

0 commit comments

Comments
 (0)