11local M = {}
22
33local utils = require (" nvim-tree.utils" )
4+ local view = require (" nvim-tree.view" )
45
56local function hide (win )
67 if win then
@@ -32,7 +33,7 @@ local function effective_win_width()
3233 return win_width - win_info [1 ].textoff
3334end
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
@@ -50,6 +51,12 @@ local function show()
5051 end
5152
5253 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+
5360 local win_width = effective_win_width ()
5461
5562 if text_width < win_width then
@@ -66,12 +73,26 @@ local function show()
6673 style = " minimal" ,
6774 border = " none"
6875 })
76+ vim .wo [M .popup_win ].winhl = view .View .winopts .winhl
6977
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 })
7280 vim .api .nvim_win_call (M .popup_win , function ()
7381 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
7596 -- nvim 0.10 luadoc is incorrect: vim.api.keyset.get_extmark_item is missing the extmark_id at the start
7697
7798 --- @cast extmark table
@@ -82,13 +103,16 @@ local function show()
82103
83104 if type (details ) == " table" then
84105 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 , }, {})
86107 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
88109 end
89110 end
90111 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
92116 end )
93117end
94118
@@ -114,7 +138,7 @@ M.setup = function(opts)
114138 pattern = { " NvimTree_*" },
115139 callback = function ()
116140 if utils .is_nvim_tree_buf (0 ) then
117- show ()
141+ show (opts )
118142 end
119143 end ,
120144 })
0 commit comments