From ac9b93984f222865c827e8677f362d0286b9d188 Mon Sep 17 00:00:00 2001 From: Will Hopkins Date: Sat, 9 Dec 2023 12:14:30 -0800 Subject: [PATCH] feat: add `sync_on_ui_close` option --- README.md | 4 +++- lua/harpoon/config.lua | 3 +++ lua/harpoon/list.lua | 2 -- lua/harpoon/ui.lua | 3 +++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d48ceb8..05ebdbe 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,8 @@ Settings can alter the experience of harpoon **Definition** ```lua ---@class HarpoonSettings ----@field save_on_toggle boolean defaults to true +---@field save_on_toggle boolean defaults to false +---@field sync_on_ui_close boolean defaults to false ---@field key (fun(): string) ``` @@ -184,6 +185,7 @@ Settings can alter the experience of harpoon ```lua settings = { save_on_toggle = false, + sync_on_ui_close = false, border_chars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, key = function() return vim.loop.cwd() diff --git a/lua/harpoon/config.lua b/lua/harpoon/config.lua index 578c785..10af4d2 100644 --- a/lua/harpoon/config.lua +++ b/lua/harpoon/config.lua @@ -27,12 +27,14 @@ M.DEFAULT_LIST = DEFAULT_LIST ---@class HarpoonSettings ---@field border_chars string[] defaults to { "─", "│", "─", "│", "╭", "╮", "╯", "╰" } ---@field save_on_toggle boolean defaults to true +---@field sync_on_ui_close? boolean ---@field ui_fallback_width number defaults 69, nice ---@field ui_width_ratio number defaults to 0.62569 ---@field key (fun(): string) ---@class HarpoonPartialSettings ---@field save_on_toggle? boolean +---@field sync_on_ui_close? boolean ---@field key? (fun(): string) ---@class HarpoonConfig @@ -56,6 +58,7 @@ function M.get_default_config() settings = { save_on_toggle = false, + sync_on_ui_close = false, border_chars = { "─", "│", diff --git a/lua/harpoon/list.lua b/lua/harpoon/list.lua index 62d7f9b..2e0130d 100644 --- a/lua/harpoon/list.lua +++ b/lua/harpoon/list.lua @@ -158,8 +158,6 @@ function HarpoonList:resolve_displayed(displayed) end self.items = new_list - - require("harpoon"):sync() end function HarpoonList:select(index, options) diff --git a/lua/harpoon/ui.lua b/lua/harpoon/ui.lua index 9d21c7d..65cdff4 100644 --- a/lua/harpoon/ui.lua +++ b/lua/harpoon/ui.lua @@ -153,6 +153,9 @@ function HarpoonUI:save() local list = Buffer.get_contents(self.bufnr) Logger:log("ui#save", list) self.active_list:resolve_displayed(list) + if self.settings.sync_on_ui_close then + require("harpoon"):sync() + end end ---@param settings HarpoonSettings