From c8626bf1aa1d19b52c8cf0e3cda50eb11a66fd39 Mon Sep 17 00:00:00 2001 From: MisanthropicBit Date: Wed, 8 Jan 2025 20:51:44 +0100 Subject: [PATCH] Always use cursor relative movement Also for api functions --- lua/winmove/init.lua | 2 +- lua/winmove/layout.lua | 24 +++++++----------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/lua/winmove/init.lua b/lua/winmove/init.lua index 3b12ef2..1f53233 100644 --- a/lua/winmove/init.lua +++ b/lua/winmove/init.lua @@ -203,7 +203,7 @@ local function move_window(win_id, dir) ---@cast target_win_id -nil if not layout.are_siblings(win_id, target_win_id) then - dir = layout.get_sibling_relative_dir(win_id, target_win_id, dir, winmove.current_mode()) + dir = layout.get_sibling_relative_dir(win_id, target_win_id, dir) end winutil.wincall_no_events( diff --git a/lua/winmove/layout.lua b/lua/winmove/layout.lua index b6c6b0f..30ffb00 100644 --- a/lua/winmove/layout.lua +++ b/lua/winmove/layout.lua @@ -17,7 +17,11 @@ local function get_cursor_screen_position(win_id) local win_row, win_col = unpack(vim.api.nvim_win_get_position(win_id)) -- Get cursor position in local window space - local row, col = vim.fn.winline(), vim.fn.wincol() + local row, col + + vim.api.nvim_win_call(win_id, function() + row, col = vim.fn.winline(), vim.fn.wincol() + end) return win_row + row, win_col + col end @@ -167,24 +171,10 @@ end ---@param source_win_id integer ---@param target_win_id integer ---@param dir winmove.Direction ----@param mode winmove.Mode? ---@return winmove.Direction -function layout.get_sibling_relative_dir(source_win_id, target_win_id, dir, mode) - local grow, gcol +function layout.get_sibling_relative_dir(source_win_id, target_win_id, dir) local bbox = window_bounding_box(target_win_id) - - if mode == Mode.Move then - grow, gcol = get_cursor_screen_position(source_win_id) - else - -- Not in move mode, move relative to the middle of the window in global - -- coordinates - local win_row, win_col = unpack(vim.api.nvim_win_get_position(source_win_id)) - local height = bbox.bottom - bbox.top - local width = bbox.right - bbox.left - - grow, gcol = win_row + height / 2, win_col + width / 2 - end - + local grow, gcol = get_cursor_screen_position(source_win_id) local vertical = winutil.is_horizontal(dir) local pos = 0 local extents = {} ---@type integer[]