1
1
local M = {}
2
2
3
3
local utils = require (" nvim-tree.utils" )
4
+ local view = require (" nvim-tree.view" )
4
5
5
6
local function hide (win )
6
7
if win then
@@ -32,7 +33,7 @@ local function effective_win_width()
32
33
return win_width - win_info [1 ].textoff
33
34
end
34
35
35
- local function show ()
36
+ local function show (opts )
36
37
local line_nr = vim .api .nvim_win_get_cursor (0 )[1 ]
37
38
if vim .wo .wrap then
38
39
return
@@ -50,6 +51,12 @@ local function show()
50
51
end
51
52
52
53
local text_width = vim .fn .strdisplaywidth (vim .fn .substitute (line , " [^[:print:]]*$" , " " , " g" ))
54
+
55
+ -- also make space for right-aligned icons
56
+ local icon_ns_id = vim .api .nvim_get_namespaces ()[" NvimTreeExtmarks" ]
57
+ local icon_extmarks = vim .api .nvim_buf_get_extmarks (0 , icon_ns_id , { line_nr - 1 , 0 }, { line_nr - 1 , - 1 }, { details = true })
58
+ text_width = text_width + view .extmarks_length (icon_extmarks )
59
+
53
60
local win_width = effective_win_width ()
54
61
55
62
if text_width < win_width then
@@ -66,12 +73,26 @@ local function show()
66
73
style = " minimal" ,
67
74
border = " none"
68
75
})
76
+ vim .wo [M .popup_win ].winhl = view .View .winopts .winhl
69
77
70
- local ns_id = vim .api .nvim_get_namespaces ()[" NvimTreeHighlights" ]
71
- local extmarks = vim .api .nvim_buf_get_extmarks (0 , ns_id , { line_nr - 1 , 0 }, { line_nr - 1 , - 1 }, { details = true })
78
+ local hl_ns_id = vim .api .nvim_get_namespaces ()[" NvimTreeHighlights" ]
79
+ local hl_extmarks = vim .api .nvim_buf_get_extmarks (0 , hl_ns_id , { line_nr - 1 , 0 }, { line_nr - 1 , - 1 }, { details = true })
72
80
vim .api .nvim_win_call (M .popup_win , function ()
73
81
vim .api .nvim_buf_set_lines (0 , 0 , - 1 , true , { line })
74
- for _ , extmark in ipairs (extmarks ) do
82
+
83
+ -- copy also right-aligned icons
84
+ for _ , extmark in ipairs (icon_extmarks ) do
85
+ local details = extmark [4 ]
86
+ if details then
87
+ vim .api .nvim_buf_set_extmark (0 , icon_ns_id , 0 , 0 , {
88
+ virt_text = details .virt_text ,
89
+ virt_text_pos = details .virt_text_pos ,
90
+ hl_mode = details .hl_mode ,
91
+ })
92
+ end
93
+ end
94
+
95
+ for _ , extmark in ipairs (hl_extmarks ) do
75
96
-- nvim 0.10 luadoc is incorrect: vim.api.keyset.get_extmark_item is missing the extmark_id at the start
76
97
77
98
--- @cast extmark table
@@ -82,13 +103,16 @@ local function show()
82
103
83
104
if type (details ) == " table" then
84
105
if vim .fn .has (" nvim-0.11" ) == 1 and vim .hl and vim .hl .range then
85
- vim .hl .range (0 , ns_id , details .hl_group , { 0 , col }, { 0 , details .end_col , }, {})
106
+ vim .hl .range (0 , hl_ns_id , details .hl_group , { 0 , col }, { 0 , details .end_col , }, {})
86
107
else
87
- vim .api .nvim_buf_add_highlight (0 , ns_id , details .hl_group , 0 , col , details .end_col ) --- @diagnostic disable-line : deprecated
108
+ vim .api .nvim_buf_add_highlight (0 , hl_ns_id , details .hl_group , 0 , col , details .end_col ) --- @diagnostic disable-line : deprecated
88
109
end
89
110
end
90
111
end
91
- vim .cmd ([[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=wipe ]] )
112
+ vim .cmd ([[ setlocal nowrap noswapfile nobuflisted buftype=nofile bufhidden=wipe ]] )
113
+ if opts .view .cursorline then
114
+ vim .cmd ([[ setlocal cursorline cursorlineopt=both ]] )
115
+ end
92
116
end )
93
117
end
94
118
@@ -114,7 +138,7 @@ M.setup = function(opts)
114
138
pattern = { " NvimTree_*" },
115
139
callback = function ()
116
140
if utils .is_nvim_tree_buf (0 ) then
117
- show ()
141
+ show (opts )
118
142
end
119
143
end ,
120
144
})
0 commit comments