@@ -2,6 +2,7 @@ local config = require'nvim-tree.config'
2
2
local utils = require ' nvim-tree.utils'
3
3
local view = require ' nvim-tree.view'
4
4
local _padding = require ' nvim-tree.renderer.padding'
5
+ local _help = require ' nvim-tree.renderer.help'
5
6
6
7
local api = vim .api
7
8
359
360
360
361
local M = {}
361
362
362
- function M .draw_help ()
363
- local help_lines = {' HELP' }
364
- local help_hl = {{' NvimTreeRootFolder' , 0 , 0 , # help_lines [1 ]}}
365
- local mappings = vim .tbl_filter (function (v )
366
- return v .cb ~= nil and v .cb ~= " "
367
- end , view .View .mappings )
368
- local processed = {}
369
- for _ , b in pairs (mappings ) do
370
- local cb = b .cb
371
- local key = b .key
372
- local name
373
- if cb :sub (1 ,35 ) == view .nvim_tree_callback (' test' ):sub (1 ,35 ) then
374
- name = cb :match (" '[^']+'[^']*$" )
375
- name = name :match (" '[^']+'" )
376
- table.insert (processed , {key , name , true })
377
- else
378
- name = (b .name ~= nil ) and b .name or cb
379
- name = ' "' .. name .. ' "'
380
- table.insert (processed , {key , name , false })
381
- end
382
- end
383
- table.sort (processed , function (a ,b )
384
- return (a [3 ] == b [3 ]
385
- and (a [2 ] < b [2 ] or (a [2 ] == b [2 ] and # a [1 ] < # b [1 ])))
386
- or (a [3 ] and not b [3 ])
387
- end )
388
-
389
- local num = 0
390
- for _ , val in pairs (processed ) do
391
- local keys = type (val [1 ]) == " string" and {val [1 ]} or val [1 ]
392
- local map_name = val [2 ]
393
- local builtin = val [3 ]
394
- for _ , key in pairs (keys ) do
395
- num = num + 1
396
- local bind_string = string.format (" %6s : %s" , key , map_name )
397
- table.insert (help_lines , bind_string )
398
-
399
- local hl_len = math.max (6 , string.len (key )) + 2
400
- table.insert (help_hl , {' NvimTreeFolderName' , num , 0 , hl_len })
401
-
402
- if not builtin then
403
- table.insert (help_hl , {' NvimTreeFileRenamed' , num , hl_len , - 1 })
404
- end
405
- end
406
- end
407
- return help_lines , help_hl
408
- end
409
-
410
363
function M .draw (tree , reload )
411
364
if not api .nvim_buf_is_loaded (view .View .bufnr ) then return end
412
365
local cursor
@@ -425,7 +378,7 @@ function M.draw(tree, reload)
425
378
end
426
379
427
380
if view .is_help_ui () then
428
- lines , hl = M . draw_help ()
381
+ lines , hl = _help . compute_lines ()
429
382
end
430
383
api .nvim_buf_set_option (view .View .bufnr , ' modifiable' , true )
431
384
api .nvim_buf_set_lines (view .View .bufnr , 0 , - 1 , false , lines )
0 commit comments