diff --git a/lua/Navigator/init.lua b/lua/Navigator/init.lua index 4c87dd0..6794f84 100644 --- a/lua/Navigator/init.lua +++ b/lua/Navigator/init.lua @@ -122,4 +122,47 @@ function Nav.previous() n.navigate('p') end +---Resize down split/pane +---@usage [[ +---require('Navigator').size_down() +--- +----- With keybinding +---vim.keymap.set({'n', 't'}, '', require('Navigator').size_down) +---@usage ]] +function Nav.size_down() + n.resize('j') +end + +---Resize up split/pane +---@usage [[ +---require('Navigator').size_up() +--- +----- With keybinding +---vim.keymap.set({'n', 't'}, '', require('Navigator').size_up) +---@usage ]] +function Nav.size_up() + n.resize('k') +end + +---Resize left split/pane +---@usage [[ +---require('Navigator').size_left() +--- +----- With keybinding +---vim.keymap.set({'n', 't'}, '', require('Navigator').size_left) +---@usage ]] +function Nav.size_left() + n.resize('h') +end + +---Resize right split/pane +---@usage [[ +---require('Navigator').size_right() +--- +----- With keybinding +---vim.keymap.set({'n', 't'}, '', require('Navigator').size_right) +---@usage ]] +function Nav.size_right() + n.resize('l') +end return Nav diff --git a/lua/Navigator/mux/vi.lua b/lua/Navigator/mux/vi.lua index 350e512..aeefd6f 100644 --- a/lua/Navigator/mux/vi.lua +++ b/lua/Navigator/mux/vi.lua @@ -32,4 +32,11 @@ function Vi:navigate(direction) return self end +---Navigate inside neovim +---@param direction Direction See |navigator.api.Direction| +---@return Vi +function Vi:size(direction) + cmd('resize ' .. direction) + return self +end return Vi diff --git a/lua/Navigator/mux/wezterm.lua b/lua/Navigator/mux/wezterm.lua index 8afdcef..7ad2395 100644 --- a/lua/Navigator/mux/wezterm.lua +++ b/lua/Navigator/mux/wezterm.lua @@ -49,4 +49,12 @@ function WezTerm:navigate(direction) return self end +---Resize pane in wezterm +---@param direction Direction See |navigator.api.Direction| +---@return WezTerm +function WezTerm:size(direction) + self.execute(string.format('adjust-pane-size %s', self.direction[direction])) + return self +end + return WezTerm diff --git a/lua/Navigator/navigate.lua b/lua/Navigator/navigate.lua index 12af69b..08a71c3 100644 --- a/lua/Navigator/navigate.lua +++ b/lua/Navigator/navigate.lua @@ -99,4 +99,37 @@ function N.navigate(direction) end end +---For smoothly resizing neovim splits and mux panes +---@param direction string +function N.resize(direction) + -- window id before navigation + local cur_win = A.nvim_get_current_win() + + local mux_last_pane = N.last_pane + if not mux_last_pane then + if direction == 'h' then + cmd('vertical resize -8') + elseif direction == 'l' then + cmd('vertical resize +8') + elseif direction == 'k' then + cmd('resize -8') + elseif direction == 'j' then + cmd('resize +8') + end + -- If we only want to resize inside vim + -- then we don't need to do anything in mux + return + end + + -- After navigation, if the old window and new window matches + local at_edge = cur_win == A.nvim_get_current_win() + + -- then we can assume that we hit the edge + -- there is mux pane besided the edge + -- So we can navigate to the mux pane + if back_to_mux(at_edge) then + N.config.mux:size(direction) + end +end + return N diff --git a/plugin/Navigator.lua b/plugin/Navigator.lua index 54a37df..2e5c7e1 100644 --- a/plugin/Navigator.lua +++ b/plugin/Navigator.lua @@ -7,3 +7,8 @@ ucmd('NavigatorRight', N.right, {}) ucmd('NavigatorUp', N.up, {}) ucmd('NavigatorDown', N.down, {}) ucmd('NavigatorPrevious', N.previous, {}) + +ucmd('NavigatorSizeLeft', N.size_left, {}) +ucmd('NavigatorSizeRight', N.size_right, {}) +ucmd('NavigatorSizeUp', N.size_up, {}) +ucmd('NavigatorSizeDown', N.size_down, {})