Skip to content

Commit 2814f87

Browse files
authored
Merge branch 'master' into feat/collapse-all-with-node
2 parents 8b8c589 + 05d8172 commit 2814f87

File tree

12 files changed

+94
-38
lines changed

12 files changed

+94
-38
lines changed

.hooks/pre-commit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#!/bin/sh
1+
#!/usr/bin/env sh
22

33
make

doc/nvim-tree-lua.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,8 @@ Configuration options for opening a file from nvim-tree.
15231523

15241524
*nvim-tree.actions.open_file.window_picker.enable*
15251525
Enable the feature. If the feature is not enabled, files will open in
1526-
window from which you last opened the tree.
1526+
window from which you last opened the tree, obeying
1527+
|nvim-tree.actions.open_file.window_picker.exclude|
15271528
Type: `boolean`, Default: `true`
15281529

15291530
*nvim-tree.actions.open_file.window_picker.picker*
@@ -1542,9 +1543,10 @@ Configuration options for opening a file from nvim-tree.
15421543
Type: `string`, Default: `"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"`
15431544

15441545
*nvim-tree.actions.open_file.window_picker.exclude*
1545-
Table of buffer option names mapped to a list of option values that
1546-
indicates to the picker that the buffer's window should not be
1547-
selectable.
1546+
Table of buffer option names mapped to a list of option values.
1547+
Windows containing matching buffers will not be:
1548+
- available when using a window picker
1549+
- selected when not using a window picker
15481550
Type: `table`, Default: >lua
15491551
{
15501552
filetype = {

lua/nvim-tree.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ local function setup_autocommands(opts)
242242
pattern = "*",
243243
---@param ev vim.api.keyset.create_autocmd.callback_args
244244
callback = function(ev)
245+
if not vim.api.nvim_buf_is_valid(ev.buf) then
246+
return
247+
end
245248
if vim.api.nvim_get_option_value("filetype", { buf = ev.buf }) == "NvimTree" then
246249
require("nvim-tree.events")._dispatch_on_tree_close()
247250
end

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ local function usable_win_ids()
4343
end, win_ids)
4444
end
4545

46-
---Find the first window in the tab that is not NvimTree.
47-
---@return integer -1 if none available
48-
local function first_win_id()
49-
local selectable = usable_win_ids()
50-
if #selectable > 0 then
51-
return selectable[1]
52-
else
53-
return -1
54-
end
55-
end
56-
5746
---Get user to pick a window in the tab that is not NvimTree.
5847
---@return integer|nil -- If a valid window was picked, return its id. If an
5948
--- invalid window was picked / user canceled, return nil. If there are
@@ -246,9 +235,14 @@ local function get_target_winid(mode)
246235
local target_winid
247236
if not M.window_picker.enable or string.find(mode, "no_picker") then
248237
target_winid = lib.target_winid
249-
-- first available window
250-
if not vim.tbl_contains(vim.api.nvim_tabpage_list_wins(0), target_winid) then
251-
target_winid = first_win_id()
238+
local usable_wins = usable_win_ids()
239+
-- first available usable window
240+
if not vim.tbl_contains(usable_wins, target_winid) then
241+
if #usable_wins > 0 then
242+
target_winid = usable_wins[1]
243+
else
244+
target_winid = -1
245+
end
252246
end
253247
else
254248
-- pick a window

lua/nvim-tree/renderer/builder.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ end
135135
function Builder:format_line(indent_markers, arrows, icon, name, node)
136136
local added_len = 0
137137
local function add_to_end(t1, t2)
138-
if not t2 then
138+
if not t2 or vim.tbl_isempty(t2) then
139139
return
140140
end
141141
for _, v in ipairs(t2) do

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local M = {}
22

33
local utils = require("nvim-tree.utils")
4+
local view = require("nvim-tree.view")
45

56
local function hide(win)
67
if win then
@@ -32,7 +33,7 @@ local function effective_win_width()
3233
return win_width - win_info[1].textoff
3334
end
3435

35-
local function show()
36+
local function show(opts)
3637
local line_nr = vim.api.nvim_win_get_cursor(0)[1]
3738
if vim.wo.wrap then
3839
return
@@ -52,6 +53,11 @@ local function show()
5253
local text_width = vim.fn.strdisplaywidth(vim.fn.substitute(line, "[^[:print:]]*$", "", "g"))
5354
local win_width = effective_win_width()
5455

56+
-- windows width reduced by right aligned icons
57+
local icon_ns_id = vim.api.nvim_get_namespaces()["NvimTreeExtmarks"]
58+
local icon_extmarks = vim.api.nvim_buf_get_extmarks(0, icon_ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = true })
59+
win_width = win_width - utils.extmarks_length(icon_extmarks)
60+
5561
if text_width < win_width then
5662
return
5763
end
@@ -66,6 +72,7 @@ local function show()
6672
style = "minimal",
6773
border = "none"
6874
})
75+
vim.wo[M.popup_win].winhl = view.View.winopts.winhl
6976

7077
local ns_id = vim.api.nvim_get_namespaces()["NvimTreeHighlights"]
7178
local extmarks = vim.api.nvim_buf_get_extmarks(0, ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = true })
@@ -88,7 +95,10 @@ local function show()
8895
end
8996
end
9097
end
91-
vim.cmd([[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=wipe ]])
98+
vim.cmd([[ setlocal nowrap noswapfile nobuflisted buftype=nofile bufhidden=wipe ]])
99+
if opts.view.cursorline then
100+
vim.cmd([[ setlocal cursorline cursorlineopt=both ]])
101+
end
92102
end)
93103
end
94104

@@ -114,7 +124,7 @@ M.setup = function(opts)
114124
pattern = { "NvimTree_*" },
115125
callback = function()
116126
if utils.is_nvim_tree_buf(0) then
117-
show()
127+
show(opts)
118128
end
119129
end,
120130
})

lua/nvim-tree/renderer/decorator/init.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ function Decorator:define_sign(icon)
112112
vim.fn.sign_undefine(name)
113113
end
114114

115-
-- don't use sign if not defined
115+
-- don't render sign if empty
116116
if #icon.str < 1 then
117-
self.icon_placement = "none"
118117
return
119118
end
120119

lua/nvim-tree/utils.lua

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@ function M.find_node_line(node)
172172
return -1
173173
end
174174

175+
---@param extmarks vim.api.keyset.get_extmark_item[] as per vim.api.nvim_buf_get_extmarks
176+
---@return number
177+
function M.extmarks_length(extmarks)
178+
local length = 0
179+
for _, extmark in ipairs(extmarks) do
180+
local details = extmark[4]
181+
if details and details.virt_text then
182+
for _, text in ipairs(details.virt_text) do
183+
length = length + vim.fn.strchars(text[1])
184+
end
185+
end
186+
end
187+
return length
188+
end
189+
175190
-- get the node in the tree state depending on the absolute path of the node
176191
-- (grouped or hidden too)
177192
---@param path string
@@ -288,11 +303,51 @@ function M.rename_loaded_buffers(old_path, new_path)
288303
end
289304
end
290305

306+
local is_windows_drive = function(path)
307+
return (M.is_windows) and (path:match("^%a:\\$") ~= nil)
308+
end
309+
291310
---@param path string path to file or directory
292311
---@return boolean
293312
function M.file_exists(path)
294-
local _, error = vim.loop.fs_stat(path)
295-
return error == nil
313+
if not (M.is_windows or M.is_wsl) then
314+
local _, error = vim.loop.fs_stat(path)
315+
return error == nil
316+
end
317+
318+
-- Windows is case-insensetive, but case-preserving
319+
-- If a file's name is being changed into itself
320+
-- with different casing, windows will falsely
321+
-- report that file is already existing, so a hand-rolled
322+
-- implementation of checking for existance is needed.
323+
-- Same holds for WSL, since it can sometimes
324+
-- access Windows files directly.
325+
-- For more details see (#3117).
326+
327+
if is_windows_drive(path) then
328+
return vim.fn.isdirectory(path) == 1
329+
end
330+
331+
local parent = vim.fn.fnamemodify(path, ":h")
332+
local filename = vim.fn.fnamemodify(path, ":t")
333+
334+
local handle = vim.loop.fs_scandir(parent)
335+
if not handle then
336+
-- File can not exist if its parent directory does not exist
337+
return false
338+
end
339+
340+
while true do
341+
local name, _ = vim.loop.fs_scandir_next(handle)
342+
if not name then
343+
break
344+
end
345+
if name == filename then
346+
return true
347+
end
348+
end
349+
350+
return false
296351
end
297352

298353
---@param path string

lua/nvim-tree/view.lua

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,7 @@ local function grow()
329329
local count = vim.fn.strchars(l)
330330
-- also add space for right-aligned icons
331331
local extmarks = vim.api.nvim_buf_get_extmarks(M.get_bufnr(), ns_id, { line_nr, 0 }, { line_nr, -1 }, { details = true })
332-
for _, extmark in ipairs(extmarks) do
333-
local virt_texts = extmark[4].virt_text
334-
if virt_texts then
335-
for _, virt_text in ipairs(virt_texts) do
336-
count = count + vim.fn.strchars(virt_text[1])
337-
end
338-
end
339-
end
332+
count = count + utils.extmarks_length(extmarks)
340333
if resizing_width < count then
341334
resizing_width = count
342335
end

scripts/doc-comments.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
out=$(grep -nr "^--- @" lua)
44

scripts/help-update.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/usr/bin/env sh
22

33
# run after changing nvim-tree.lua DEFAULT_OPTS or keymap.lua M.default_on_attach
44
# scrapes and updates nvim-tree-lua.txt

scripts/luals-check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/usr/bin/env sh
22

33
# Performs a lua-language-server check on all files.
44
# luals-out/check.json will be produced on any issues, returning 1.

0 commit comments

Comments
 (0)