Skip to content

Commit 2bcb5fe

Browse files
authored
Merge branch 'master' into feat/close-file-buffer-2
2 parents aa6fe10 + db74032 commit 2bcb5fe

File tree

10 files changed

+73
-37
lines changed

10 files changed

+73
-37
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "1.9.0"
2+
".": "1.10.0"
33
}

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Changelog
22

3+
## [1.10.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.9.0...nvim-tree-v1.10.0) (2025-01-13)
4+
5+
6+
### Features
7+
8+
* **api:** add node.open.vertical_no_picker, node.open.horizontal_no_picker ([#3031](https://github.com/nvim-tree/nvim-tree.lua/issues/3031)) ([68fc4c2](https://github.com/nvim-tree/nvim-tree.lua/commit/68fc4c20f5803444277022c681785c5edd11916d))
9+
10+
11+
### Bug Fixes
12+
13+
* **#3015:** dynamic width no longer truncates on right_align icons ([#3022](https://github.com/nvim-tree/nvim-tree.lua/issues/3022)) ([f7b76cd](https://github.com/nvim-tree/nvim-tree.lua/commit/f7b76cd1a75615c8d6254fc58bedd2a7304eb7d8))
14+
* **#3018:** error when focusing nvim-tree when in terminal mode ([#3019](https://github.com/nvim-tree/nvim-tree.lua/issues/3019)) ([db8d7ac](https://github.com/nvim-tree/nvim-tree.lua/commit/db8d7ac1f524fc6f808764b29fa695c51e014aa6))
15+
* **#3041:** use vim.diagnostic.get for updating diagnostics ([#3042](https://github.com/nvim-tree/nvim-tree.lua/issues/3042)) ([aae0185](https://github.com/nvim-tree/nvim-tree.lua/commit/aae01853ddbd790d1efd6ff04ff96cf38c02c95f))
16+
* Can't re-enter normal mode from terminal mode ([db8d7ac](https://github.com/nvim-tree/nvim-tree.lua/commit/db8d7ac1f524fc6f808764b29fa695c51e014aa6))
17+
* hijack directory "BufEnter", "BufNewFile" events are nested ([#3044](https://github.com/nvim-tree/nvim-tree.lua/issues/3044)) ([39bc630](https://github.com/nvim-tree/nvim-tree.lua/commit/39bc63081605c1d4b974131ebecaea11e8a8595f))
18+
* view.width functions may return strings ([#3020](https://github.com/nvim-tree/nvim-tree.lua/issues/3020)) ([6b4be1d](https://github.com/nvim-tree/nvim-tree.lua/commit/6b4be1dc0cd4d5d5b8e8b56b510a75016e99746f))
19+
320
## [1.9.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.8.0...nvim-tree-v1.9.0) (2024-12-07)
421

522

lua/nvim-tree.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ local function setup_autocommands(opts)
190190
end
191191

192192
if opts.hijack_directories.enable then
193-
create_nvim_tree_autocmd({ "BufEnter", "BufNewFile" }, { callback = M.open_on_directory })
193+
create_nvim_tree_autocmd({ "BufEnter", "BufNewFile" }, { callback = M.open_on_directory, nested = true })
194194
end
195195

196196
if opts.view.centralize_selection then

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ local function setup_window(node)
5050
file_path = node.absolute_path,
5151
}
5252
local bufnr = vim.api.nvim_create_buf(false, true)
53+
vim.bo[bufnr].bufhidden = "wipe"
5354
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
5455
vim.api.nvim_win_set_buf(winnr, bufnr)
5556
end

lua/nvim-tree/appearance/hi-test.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ local Class = require("nvim-tree.classic")
55
-- others with name and links less than this arbitrary value are short
66
local SHORT_LEN = 50
77

8+
local namespace_hi_test_id = vim.api.nvim_create_namespace("NvimTreeHiTest")
9+
810
---@class (exact) HighlightDisplay: Class for :NvimTreeHiTest
911
---@field group string nvim-tree highlight group name
1012
---@field links string link chain to a concretely defined group
@@ -52,7 +54,12 @@ function HighlightDisplay:render(bufnr, fmt, l)
5254
local text = string.format(fmt, self.group, self.links, self.def)
5355

5456
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { text })
55-
vim.api.nvim_buf_add_highlight(bufnr, -1, self.group, l, 0, #self.group)
57+
58+
if vim.fn.has("nvim-0.11") == 1 then
59+
vim.hl.range(bufnr, namespace_hi_test_id, self.group, { l, 0 }, { l, #self.group, }, {})
60+
else
61+
vim.api.nvim_buf_add_highlight(bufnr, -1, self.group, l, 0, #self.group) ---@diagnostic disable-line: deprecated
62+
end
5663

5764
return l + 1
5865
end

lua/nvim-tree/diagnostics.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ function M.update_lsp(ev)
128128

129129
local profile_event = log.profile_start("DiagnosticChanged event")
130130

131-
---@type vim.Diagnostic[]
132-
local diagnostics = ev.data.diagnostics
131+
local diagnostics = vim.diagnostic.get(ev.buf)
133132

134133
-- use the buffer from the event, as ev.data.diagnostics will be empty on resolved diagnostics
135134
local bufname = uniformize_path(vim.api.nvim_buf_get_name(ev.buf))

lua/nvim-tree/help.lua

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ local WIN_HL = table.concat({
1111
"CursorLine:NvimTreeCursorLine",
1212
}, ",")
1313

14+
local namespace_help_id = vim.api.nvim_create_namespace("NvimTreeHelp")
15+
1416
local M = {
1517
config = {},
1618

@@ -82,8 +84,8 @@ end
8284

8385
--- Compute all lines for the buffer
8486
---@param map table keymap.get_keymap
85-
---@return table strings of text
86-
---@return table arrays of arguments 3-6 for nvim_buf_add_highlight()
87+
---@return string[] lines of text
88+
---@return HighlightRangeArgs[] hl_range_args for lines
8789
---@return number maximum length of text
8890
local function compute(map)
8991
local head_lhs = "nvim-tree mappings"
@@ -130,10 +132,10 @@ local function compute(map)
130132
local width = #lines[1]
131133

132134
-- header highlight, assume one character keys
133-
local hl = {
134-
{ "NvimTreeFolderName", 0, 0, #head_lhs },
135-
{ "NvimTreeFolderName", 0, width - 1, width },
136-
{ "NvimTreeFolderName", 1, width - 1, width },
135+
local hl_range_args = {
136+
{ higroup = "NvimTreeFolderName", start = { 0, 0, }, finish = { 0, #head_lhs, }, },
137+
{ higroup = "NvimTreeFolderName", start = { 0, width - 1, }, finish = { 0, width, }, },
138+
{ higroup = "NvimTreeFolderName", start = { 1, width - 1, }, finish = { 1, width, }, },
137139
}
138140

139141
-- mappings, left padded 1
@@ -145,10 +147,10 @@ local function compute(map)
145147
width = math.max(#line, width)
146148

147149
-- highlight lhs
148-
table.insert(hl, { "NvimTreeFolderName", i + 1, 1, #l.lhs + 1 })
150+
table.insert(hl_range_args, { higroup = "NvimTreeFolderName", start = { i + 1, 1, }, finish = { i + 1, #l.lhs + 1, }, })
149151
end
150152

151-
return lines, hl, width
153+
return lines, hl_range_args, width
152154
end
153155

154156
--- close the window and delete the buffer, if they exist
@@ -172,7 +174,7 @@ local function open()
172174
local map = keymap.get_keymap()
173175

174176
-- text and highlight
175-
local lines, hl, width = compute(map)
177+
local lines, hl_range_args, width = compute(map)
176178

177179
-- create the buffer
178180
M.bufnr = vim.api.nvim_create_buf(false, true)
@@ -187,8 +189,12 @@ local function open()
187189
end
188190

189191
-- highlight it
190-
for _, h in ipairs(hl) do
191-
vim.api.nvim_buf_add_highlight(M.bufnr, -1, h[1], h[2], h[3], h[4])
192+
for _, args in ipairs(hl_range_args) do
193+
if vim.fn.has("nvim-0.11") == 1 then
194+
vim.hl.range(M.bufnr, namespace_help_id, args.higroup, args.start, args.finish, {})
195+
else
196+
vim.api.nvim_buf_add_highlight(M.bufnr, -1, args.higroup, args.start[1], args.start[2], args.finish[2]) ---@diagnostic disable-line: deprecated
197+
end
192198
end
193199

194200
-- open a very restricted window

lua/nvim-tree/renderer/builder.lua

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,9 @@ local BUILTIN_DECORATORS = {
3333
Cut = CutDecorator,
3434
}
3535

36-
---@class (exact) AddHighlightArgs
37-
---@field group string[]
38-
---@field line number
39-
---@field col_start number
40-
---@field col_end number
41-
4236
---@class (exact) Builder
4337
---@field lines string[] includes icons etc.
44-
---@field hl_args AddHighlightArgs[] line highlights
38+
---@field hl_range_args HighlightRangeArgs[] highlights for lines
4539
---@field signs string[] line signs
4640
---@field extmarks table[] extra marks for right icon placement
4741
---@field virtual_lines table[] virtual lines for hidden count display
@@ -67,7 +61,7 @@ function Builder:new(args)
6761
self.explorer = args.explorer
6862
self.index = 0
6963
self.depth = 0
70-
self.hl_args = {}
64+
self.hl_range_args = {}
7165
self.combined_groups = {}
7266
self.lines = {}
7367
self.markers = {}
@@ -106,7 +100,9 @@ end
106100
---@param start number
107101
---@param end_ number|nil
108102
function Builder:insert_highlight(groups, start, end_)
109-
table.insert(self.hl_args, { groups, self.index, start, end_ or -1 })
103+
for _, higroup in ipairs(groups) do
104+
table.insert(self.hl_range_args, { higroup = higroup, start = { self.index, start, }, finish = { self.index, end_ or -1, } })
105+
end
110106
end
111107

112108
---@private

lua/nvim-tree/renderer/components/full-name.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,15 @@ local function show()
7979
---@type vim.api.keyset.extmark_details
8080
local details = extmark[4]
8181

82-
vim.api.nvim_buf_add_highlight(0, ns_id, details.hl_group, 0, col, details.end_col)
82+
if type(details) == "table" then
83+
if vim.fn.has("nvim-0.12") == 1 then
84+
vim.hl.range(0, ns_id, details.hl_group, { 0, col }, { 0, details.end_col, }, {})
85+
else
86+
vim.api.nvim_buf_add_highlight(0, ns_id, details.hl_group, 0, col, details.end_col) ---@diagnostic disable-line: deprecated
87+
end
88+
end
8389
end
84-
vim.cmd([[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=hide ]])
90+
vim.cmd([[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=wipe ]])
8591
end)
8692
end
8793

lua/nvim-tree/renderer/init.lua

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ local namespace_highlights_id = vim.api.nvim_create_namespace("NvimTreeHighlight
1111
local namespace_extmarks_id = vim.api.nvim_create_namespace("NvimTreeExtmarks")
1212
local namespace_virtual_lines_id = vim.api.nvim_create_namespace("NvimTreeVirtualLines")
1313

14+
---@alias HighlightRangeArgs { higroup:string, start:integer[], finish:integer[] } named arguments for vim.hl.range
15+
1416
---@class (exact) Renderer: Class
1517
---@field explorer Explorer
1618
local Renderer = Class:extend()
@@ -30,19 +32,19 @@ end
3032
---@private
3133
---@param bufnr number
3234
---@param lines string[]
33-
---@param hl_args AddHighlightArgs[]
35+
---@param hl_range_args HighlightRangeArgs[]
3436
---@param signs string[]
3537
---@param extmarks table[] extra marks for right icon placement
3638
---@param virtual_lines table[] virtual lines for hidden count display
37-
function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
39+
function Renderer:_draw(bufnr, lines, hl_range_args, signs, extmarks, virtual_lines)
3840
if vim.fn.has("nvim-0.10") == 1 then
3941
vim.api.nvim_set_option_value("modifiable", true, { buf = bufnr })
4042
else
4143
vim.api.nvim_buf_set_option(bufnr, "modifiable", true) ---@diagnostic disable-line: deprecated
4244
end
4345

4446
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
45-
self:render_hl(bufnr, hl_args)
47+
self:render_hl(bufnr, hl_range_args)
4648

4749
if vim.fn.has("nvim-0.10") == 1 then
4850
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
@@ -77,16 +79,18 @@ function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
7779
end
7880

7981
---@private
80-
function Renderer:render_hl(bufnr, hl)
82+
---@param bufnr integer
83+
---@param hl_range_args HighlightRangeArgs[]
84+
function Renderer:render_hl(bufnr, hl_range_args)
8185
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
8286
return
8387
end
8488
vim.api.nvim_buf_clear_namespace(bufnr, namespace_highlights_id, 0, -1)
85-
for _, data in ipairs(hl) do
86-
if type(data[1]) == "table" then
87-
for _, group in ipairs(data[1]) do
88-
vim.api.nvim_buf_add_highlight(bufnr, namespace_highlights_id, group, data[2], data[3], data[4])
89-
end
89+
for _, args in ipairs(hl_range_args) do
90+
if vim.fn.has("nvim-0.11") == 1 then
91+
vim.hl.range(bufnr, namespace_highlights_id, args.higroup, args.start, args.finish, {})
92+
else
93+
vim.api.nvim_buf_add_highlight(bufnr, namespace_highlights_id, args.higroup, args.start[1], args.start[2], args.finish[2]) ---@diagnostic disable-line: deprecated
9094
end
9195
end
9296
end
@@ -103,7 +107,7 @@ function Renderer:draw()
103107

104108
local builder = Builder(self.explorer):build()
105109

106-
self:_draw(bufnr, builder.lines, builder.hl_args, builder.signs, builder.extmarks, builder.virtual_lines)
110+
self:_draw(bufnr, builder.lines, builder.hl_range_args, builder.signs, builder.extmarks, builder.virtual_lines)
107111

108112
if cursor and #builder.lines >= cursor[1] then
109113
vim.api.nvim_win_set_cursor(view.get_winnr() or 0, cursor)

0 commit comments

Comments
 (0)