harpoon
harpoon copied to clipboard
Switching between buffers/marks has a noticeable lag
After the fix in #530, every BufLeave
-event causes a write of the updated cursor-position to disk. I'm noticing a bit of a lag, when this happens on my machine :(
Can this event be made in the background and/or be delayed, so that it doesn't impact UX that much?!
Here's a simple/dirty fix - using a timer - which ignores subsequent triggers of the same event, inside of a given timeframe:
diff --git a/lua/harpoon/config.lua b/lua/harpoon/config.lua
index 316ec43..b575d18 100644
--- a/lua/harpoon/config.lua
+++ b/lua/harpoon/config.lua
@@ -240,10 +240,15 @@ function M.get_default_config()
item.context.row = pos[1]
item.context.col = pos[2]
- Extensions.extensions:emit(
- Extensions.event_names.POSITION_UPDATED,
- item
- )
+ if not list.timer then
+ list.timer = vim.defer_fn(function()
+ Extensions.extensions:emit(
+ Extensions.event_names.POSITION_UPDATED,
+ item
+ )
+ list.timer = nil
+ end, 500)
+ end
end
end,
The final solution might want to keep all the updates in memory, until the timer is triggered and then emit all the updates at once and write them to disk!? Maybe this could be a user-configuration?!
Maybe there could be an additional DELAYED_POSITION_UPDATED
-event, which could be used for internal operations, such as writing the data? Then, extension-writers could either use the synchronous POSITION_UPDATED
-event or asynchronous DELAYED_POSITION_UPDATED
-event!?
Just thinking out loud :)
Also, writing the cursor-positions (non-crucial) when Neovim exits - similar to :h shada-write
- would work for me too.