feat(tabs): add tab.sync options (#1698)

* Sync closing of nvim-tree across tabs

* chore: remove vim.* "requires"

* Sync closing of nvim-tree across tabs

* Fix api.close calls

* Fix issue from merge

* Implement changes

* Finish todos and add close_all_tabs

* silently refactor options, add doc

* fix vinegar example

* Refactor close to work with tabid

* Close nvim tree if last buffer

* close and abandon all tabs on subsequent setup calls

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Wessel Blokzijl
2022-11-19 03:57:45 +01:00
committed by GitHub
parent 1837751efb
commit c49499413a
7 changed files with 120 additions and 43 deletions

View File

@@ -1,4 +1,5 @@
local Iterator = require "nvim-tree.iterators.node-iterator"
local notify = require "nvim-tree.notify"
local M = {
debouncers = {},
@@ -266,14 +267,20 @@ function M.table_create_missing(tbl, path)
return t
end
-- Move a value from src to dst if value is nil on dst
-- @param src to copy from
-- @param src_path dot separated string of sub-tables
-- @param src_pos value pos
-- @param dst to copy to
-- @param dst_path dot separated string of sub-tables, created when missing
-- @param dst_pos value pos
function M.move_missing_val(src, src_path, src_pos, dst, dst_path, dst_pos)
--- Move a value from src to dst if value is nil on dst.
--- Remove value from src
--- @param src table to copy from
--- @param src_path string dot separated string of sub-tables
--- @param src_pos string value pos
--- @param dst table to copy to
--- @param dst_path string dot separated string of sub-tables, created when missing
--- @param dst_pos string value pos
--- @param remove boolean default true
function M.move_missing_val(src, src_path, src_pos, dst, dst_path, dst_pos, remove)
if remove == nil then
remove = true
end
local ok, err = pcall(vim.validate, {
src = { src, "table" },
src_path = { src_path, "string" },
@@ -281,9 +288,11 @@ function M.move_missing_val(src, src_path, src_pos, dst, dst_path, dst_pos)
dst = { dst, "table" },
dst_path = { dst_path, "string" },
dst_pos = { dst_pos, "string" },
remove = { remove, "boolean" },
})
if not ok then
M.notify.warn("move_missing_val: " .. (err or "invalid arguments"))
notify.warn("move_missing_val: " .. (err or "invalid arguments"))
return
end
for pos in string.gmatch(src_path, "([^%.]+)%.*") do
@@ -304,7 +313,9 @@ function M.move_missing_val(src, src_path, src_pos, dst, dst_path, dst_pos)
dst[dst_pos] = src_val
end
src[src_pos] = nil
if remove then
src[src_pos] = nil
end
end
function M.format_bytes(bytes)