From 5babdd4017658bfd2b52ebf916c513ff914d1dc5 Mon Sep 17 00:00:00 2001 From: Son Pham-Ba Date: Fri, 29 Nov 2024 17:33:17 +0100 Subject: [PATCH] fix: smear between windows on same line Smear even if `smear_between_neighbor_lines` is true --- lua/smear_cursor/animation.lua | 17 ++++++++++++++++- lua/smear_cursor/events.lua | 7 ++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lua/smear_cursor/animation.lua b/lua/smear_cursor/animation.lua index 2800b09..32326b9 100644 --- a/lua/smear_cursor/animation.lua +++ b/lua/smear_cursor/animation.lua @@ -10,6 +10,12 @@ local current_position = { 0, 0 } local trailing_position = { 0, 0 } local animating = false +-- M.current_position = setmetatable({}, { +-- __index = function(_, key) +-- return current_position[key] +-- end, +-- }) + vim.defer_fn(function() local cursor_row, cursor_col = screen.get_screen_cursor_position() target_position = { cursor_row, cursor_col } @@ -61,7 +67,6 @@ local function animate() end M.change_target_position = function(row, col, jump) - jump = jump or (not config.smear_between_neighbor_lines and math.abs(row - current_position[1]) <= 1) if target_position[1] == row and target_position[2] == col then return end @@ -86,4 +91,14 @@ M.change_target_position = function(row, col, jump) end end +setmetatable(M, { + __index = function(_, key) + if key == "current_position" then + return current_position + else + return nil + end + end, +}) + return M diff --git a/lua/smear_cursor/events.lua b/lua/smear_cursor/events.lua index 28bffef..23b0027 100644 --- a/lua/smear_cursor/events.lua +++ b/lua/smear_cursor/events.lua @@ -7,7 +7,12 @@ local switching_buffer = false local function move_cursor() local row, col = screen.get_screen_cursor_position() - local jump = not config.smear_between_buffers and switching_buffer + local jump = (not config.smear_between_buffers and switching_buffer) + or ( + not config.smear_between_neighbor_lines + and not switching_buffer + and math.abs(row - animation.current_position[1]) <= 1 + ) animation.change_target_position(row, col, jump) switching_buffer = false