Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Add Resize panes #29

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions lua/Navigator/init.lua
Expand Up @@ -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'}, '<A-j>', 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'}, '<A-k>', 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'}, '<A-h>', 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'}, '<A-l>', require('Navigator').size_right)
---@usage ]]
function Nav.size_right()
n.resize('l')
end
return Nav
7 changes: 7 additions & 0 deletions lua/Navigator/mux/vi.lua
Expand Up @@ -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
8 changes: 8 additions & 0 deletions lua/Navigator/mux/wezterm.lua
Expand Up @@ -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
33 changes: 33 additions & 0 deletions lua/Navigator/navigate.lua
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to write this without repeating it in mux/vi.lua?

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
5 changes: 5 additions & 0 deletions plugin/Navigator.lua
Expand Up @@ -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, {})