chore: move window picker configuration in setup

This commit is contained in:
kiyan 2022-02-21 22:19:35 +01:00
parent 3920e56164
commit 69867f4a00
4 changed files with 65 additions and 60 deletions

View File

@ -44,24 +44,10 @@ let g:nvim_tree_highlight_opened_files = 1 "0 by default, will enable folder and
let g:nvim_tree_root_folder_modifier = ':~' "This is the default. See :help filename-modifiers for more options
let g:nvim_tree_add_trailing = 1 "0 by default, append a trailing slash to folder names
let g:nvim_tree_group_empty = 1 " 0 by default, compact folders that only contain a single folder into one node in the file tree
let g:nvim_tree_disable_window_picker = 1 "0 by default, will disable the window picker.
let g:nvim_tree_icon_padding = ' ' "one space by default, used for rendering the space between the icon and the filename. Use with caution, it could break rendering if you set an empty string depending on your font.
let g:nvim_tree_symlink_arrow = ' >> ' " defaults to ' ➛ '. used as a separator between symlinks' source and target.
let g:nvim_tree_respect_buf_cwd = 1 "0 by default, will change cwd of nvim-tree to that of new buffer's when opening nvim-tree.
let g:nvim_tree_create_in_closed_folder = 1 "0 by default, When creating files, sets the path of a file when cursor is on a closed folder to the parent folder when 0, and inside the folder when 1.
let g:nvim_tree_window_picker_exclude = {
\ 'filetype': [
\ 'notify',
\ 'packer',
\ 'qf'
\ ],
\ 'buftype': [
\ 'terminal'
\ ]
\ }
" Dictionary of buffer option names mapped to a list of option values that
" indicates to the window picker that the buffer's window should not be
" selectable.
let g:nvim_tree_special_files = { 'README.md': 1, 'Makefile': 1, 'MAKEFILE': 1 } " List of filenames that gets highlighted with NvimTreeSpecialFile
let g:nvim_tree_show_icons = {
\ 'git': 1,
@ -183,6 +169,17 @@ require'nvim-tree'.setup {
},
open_file = {
quit_on_open = false,
window_picker = {
enable = true,
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
exclude = {
filetype = {
"notify",
"packer",
"qf"
}
}
}
}
}
}

View File

@ -135,6 +135,17 @@ function.
},
open_file = {
quit_on_open = false,
window_picker = {
enable = true,
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
exclude = {
filetype = {
"notify",
"packer",
"qf"
}
}
}
},
}
}
@ -390,6 +401,25 @@ Here is a list of the options available in the setup call:
type: `boolean`
default: `false`
- |actions.open_file.window_picker|: window picker configuration
- |actions.open_file.window_picker.enable|: Enable the feature. If the
feature is not enabled, files will open in window from which you
last opened the tree.
type: `boolean`
default: `true`
- |actions.open_file.window_picker.chars|: A string of chars used as
identifiers by the window picker.
type: `string`
default: `"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"`
- |actions.open_file.window_picker.exclude|: Table of buffer option names
mapped to a list of option values taht indicates to the picker that the
buffer's window should not be selectable.
type: `table`
default: `{ filetype = { "packer", "qf", "notify" } }`
==============================================================================
OPTIONS *nvim-tree-options*
@ -513,29 +543,6 @@ default table is
["README.md"] = true,
["readme.md"] = true,
}
|g:nvim_tree_disable_window_picker| *g:nvim_tree_disable_window_picker*
Can be 0 or 1. When 1, will disable the window picker. Files will open in the
window from which you last opened NvimTree.
|g:nvim_tree_window_picker_chars| *g:nvim_tree_window_picker_chars*
A string of chars used as identifiers by the window picker.
`"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"` by default.
|g:nvim_tree_window_picker_exclude| *g:nvim_tree_window_picker_exclude*
Dictionary of buffer option names mapped to a list of option values that
indicates to the window picker that the buffer's window should not be
selectable. The default table is
>
{
filetype = {
"packer",
"qf"
}
}
<
|g:nvim_tree_icon_padding| *g:nvim_tree_icon_padding*

View File

@ -349,6 +349,11 @@ local DEFAULT_OPTS = {
},
open_file = {
quit_on_open = vim.g.nvim_tree_quit_on_open == 1,
window_picker = {
enable = vim.g.nvim_tree_disable_window_picker ~= 1,
chars = vim.g.nvim_tree_window_picker_chars,
exclude = vim.g.nvim_tree_window_picker_exclude,
}
}
}
}

View File

@ -6,6 +6,17 @@ local view = require'nvim-tree.view'
local M = {
quit_on_open = false,
window_picker = {
enable = true,
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
exclude = {
filetype = {
"notify",
"packer",
"qf"
}
}
}
}
local function get_split_cmd()
@ -22,19 +33,6 @@ local function get_split_cmd()
return 'top'
end
local function window_picker_exclude()
if type(vim.g.nvim_tree_window_picker_exclude) == "table" then
return vim.g.nvim_tree_window_picker_exclude
end
return {
filetype = {
"notify",
"packer",
"qf"
}
}
end
---Get user to pick a window. Selectable windows are all windows in the current
---tabpage that aren't NvimTree.
---@return integer|nil -- If a valid window was picked, return its id. If an
@ -44,11 +42,10 @@ local function pick_window()
local tabpage = api.nvim_get_current_tabpage()
local win_ids = api.nvim_tabpage_list_wins(tabpage)
local tree_winid = view.get_winnr(tabpage)
local exclude = window_picker_exclude()
local selectable = vim.tbl_filter(function (id)
local bufid = api.nvim_win_get_buf(id)
for option, v in pairs(exclude) do
for option, v in pairs(M.window_picker.exclude) do
local ok, option_value = pcall(api.nvim_buf_get_option, bufid, option)
if ok and vim.tbl_contains(v, option_value) then
return false
@ -65,11 +62,6 @@ local function pick_window()
if #selectable == 0 then return -1 end
if #selectable == 1 then return selectable[1] end
local chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
if vim.g.nvim_tree_window_picker_chars then
chars = tostring(vim.g.nvim_tree_window_picker_chars):upper()
end
local i = 1
local win_opts = {}
local win_map = {}
@ -78,7 +70,7 @@ local function pick_window()
-- Setup UI
for _, id in ipairs(selectable) do
local char = chars:sub(i, i)
local char = M.window_picker.chars:sub(i, i)
local ok_status, statusline = pcall(api.nvim_win_get_option, id, "statusline")
local ok_hl, winhl = pcall(api.nvim_win_get_option, id, "winhl")
@ -94,7 +86,7 @@ local function pick_window()
)
i = i + 1
if i > #chars then break end
if i > #M.window_picker.chars then break end
end
vim.cmd("redraw")
@ -164,7 +156,7 @@ function M.fn(mode, filename)
local win_ids = api.nvim_tabpage_list_wins(tabpage)
local target_winid
if vim.g.nvim_tree_disable_window_picker == 1 or mode == "edit_no_picker" then
if not M.window_picker.enable or mode == "edit_no_picker" then
target_winid = lib.target_winid
else
target_winid = pick_window()
@ -234,6 +226,10 @@ end
function M.setup(opts)
M.quit_on_open = opts.actions.open_file.quit_on_open
if opts.actions.open_file.window_picker.chars then
opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper()
end
M.window_picker = vim.tbl_extend('force', M.window_picker, opts.actions.open_file.window_picker)
end
return M