fix(#2109): floating help window (#2120)

* fix(#2109): floating help window

* fix(#2109): floating help window

* fix(#2109): floating help window

* fix(#2109): floating help window

* fix(#2109): floating help window

* fix(#2109): floating help window

* fix(#2109): floating help window

* fix(#2109): floating help window

* help float no border

Co-authored-by: gegoune <69750637+gegoune@users.noreply.github.com>

* Update lua/nvim-tree/help.lua

Co-authored-by: gegoune <69750637+gegoune@users.noreply.github.com>

* Update lua/nvim-tree/help.lua

Co-authored-by: gegoune <69750637+gegoune@users.noreply.github.com>

* Update lua/nvim-tree/help.lua

Co-authored-by: gegoune <69750637+gegoune@users.noreply.github.com>

* Update lua/nvim-tree/help.lua

Co-authored-by: gegoune <69750637+gegoune@users.noreply.github.com>

* fix(#2109): floating help window

* fix(#2109): floating help window

---------

Co-authored-by: gegoune <69750637+gegoune@users.noreply.github.com>
This commit is contained in:
Alexander Courtis
2023-04-15 14:59:30 +10:00
committed by GitHub
parent b601b5aa25
commit 0a144ba50a
8 changed files with 216 additions and 149 deletions

View File

@@ -1,89 +0,0 @@
local M = {}
local function tidy_lhs(lhs)
-- nvim_buf_get_keymap replaces leading "<" with "<lt>" e.g. "<lt>CTRL-v>"
lhs = lhs:gsub("^<lt>", "<")
-- shorten ctrls
if lhs:lower():match "^<ctrl%-" then
lhs = lhs:lower():gsub("^<ctrl%-", "<C%-")
end
-- uppercase ctrls
if lhs:lower():match "^<c%-" then
lhs = lhs:upper()
end
-- space is not escaped
lhs = lhs:gsub(" ", "<Space>")
return lhs
end
--- Remove prefix 'nvim-tree: '
--- Hardcoded to keep default_on_attach simple
--- @param desc string
--- @return string|nil
local function tidy_desc(desc)
return desc and desc:gsub("^nvim%-tree: ", "") or ""
end
-- sort lhs roughly as per :help index
local PAT_MOUSE = "^<.*Mouse"
local PAT_CTRL = "^<C%-"
local PAT_SPECIAL = "^<.+"
local function sort_lhs(a, b)
-- mouse last
if a:match(PAT_MOUSE) and not b:match(PAT_MOUSE) then
return false
elseif not a:match(PAT_MOUSE) and b:match(PAT_MOUSE) then
return true
end
-- ctrl first
if a:match(PAT_CTRL) and not b:match(PAT_CTRL) then
return true
elseif not a:match(PAT_CTRL) and b:match(PAT_CTRL) then
return false
end
-- special next
if a:match(PAT_SPECIAL) and not b:match(PAT_SPECIAL) then
return true
elseif not a:match(PAT_SPECIAL) and b:match(PAT_SPECIAL) then
return false
end
-- lowercase alpha characters only
return a:gsub("[^a-zA-Z]", ""):lower() < b:gsub("[^a-zA-Z]", ""):lower()
end
function M.compute_lines()
local help_lines = { "HELP" }
local help_hl = { { "NvimTreeRootFolder", 0, 0, #help_lines[1] } }
local buf_keymaps = vim.api.nvim_buf_get_keymap(vim.api.nvim_get_current_buf(), "")
local lines = vim.tbl_map(function(bkm)
return { lhs = tidy_lhs(bkm.lhs), desc = tidy_desc(bkm.desc) }
end, buf_keymaps)
table.sort(lines, function(a, b)
return sort_lhs(a.lhs, b.lhs)
end)
local num = 0
for _, p in pairs(lines) do
num = num + 1
local bind_string = string.format("%-5s %s", p.lhs, p.desc)
local hl_len = math.max(5, string.len(p.lhs))
table.insert(help_lines, bind_string)
table.insert(help_hl, { "NvimTreeFolderName", num, 0, hl_len })
table.insert(help_hl, { "NvimTreeFileRenamed", num, hl_len, -1 })
end
return help_lines, help_hl
end
return M

View File

@@ -7,7 +7,6 @@ local modified = require "nvim-tree.renderer.components.modified"
local _padding = require "nvim-tree.renderer.components.padding"
local icon_component = require "nvim-tree.renderer.components.icons"
local full_name = require "nvim-tree.renderer.components.full-name"
local help = require "nvim-tree.renderer.help"
local git = require "nvim-tree.renderer.components.git"
local Builder = require "nvim-tree.renderer.builder"
local live_filter = require "nvim-tree.live-filter"
@@ -60,27 +59,21 @@ function M.draw(unloaded_bufnr)
local cursor = vim.api.nvim_win_get_cursor(view.get_winnr())
icon_component.reset_config()
local lines, hl
local signs = {}
if view.is_help_ui() then
lines, hl = help.compute_lines()
else
lines, hl, signs = Builder.new(core.get_cwd())
:configure_root_label(M.config.root_folder_label)
:configure_trailing_slash(M.config.add_trailing)
:configure_special_files(M.config.special_files)
:configure_picture_map(picture_map)
:configure_opened_file_highlighting(M.config.highlight_opened_files)
:configure_modified_highlighting(M.config.highlight_modified)
:configure_icon_padding(M.config.icons.padding)
:configure_git_icons_placement(M.config.icons.git_placement)
:configure_modified_placement(M.config.icons.modified_placement)
:configure_symlink_destination(M.config.symlink_destination)
:configure_filter(live_filter.filter, live_filter.prefix)
:build_header(view.is_root_folder_visible(core.get_cwd()))
:build(core.get_explorer(), unloaded_bufnr)
:unwrap()
end
local lines, hl, signs = Builder.new(core.get_cwd())
:configure_root_label(M.config.root_folder_label)
:configure_trailing_slash(M.config.add_trailing)
:configure_special_files(M.config.special_files)
:configure_picture_map(picture_map)
:configure_opened_file_highlighting(M.config.highlight_opened_files)
:configure_modified_highlighting(M.config.highlight_modified)
:configure_icon_padding(M.config.icons.padding)
:configure_git_icons_placement(M.config.icons.git_placement)
:configure_modified_placement(M.config.icons.modified_placement)
:configure_symlink_destination(M.config.symlink_destination)
:configure_filter(live_filter.filter, live_filter.prefix)
:build_header(view.is_root_folder_visible(core.get_cwd()))
:build(core.get_explorer(), unloaded_bufnr)
:unwrap()
_draw(bufnr, lines, hl, signs)
@@ -90,13 +83,8 @@ function M.draw(unloaded_bufnr)
vim.api.nvim_win_set_cursor(view.get_winnr(), cursor)
end
if view.is_help_ui() then
diagnostics.clear()
marks.clear()
else
diagnostics.update()
marks.draw()
end
diagnostics.update()
marks.draw()
view.grow_from_content()