Skip to content

Commit

Permalink
Add swap mode (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
MisanthropicBit authored Nov 19, 2024
1 parent 2dfb721 commit c9cdb33
Show file tree
Hide file tree
Showing 26 changed files with 1,634 additions and 482 deletions.
86 changes: 68 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<br />
<h1>winmove.nvim</h1>
<p><i>Easily move windows around</i></p>
<p><i>Easily move and swap windows</i></p>
<p>
<img src="https://img.shields.io/badge/version-0.1.0-blue?style=flat-square" />
<a href="https://luarocks.org/modules/misanthropicbit/winmove.nvim">
Expand Down Expand Up @@ -65,27 +65,46 @@ active during modes.

```lua
require('winmove').configure({
highlights = {
move = "Search", -- Highlight group for move mode
},
wrap_around = true, -- Wrap around edges when moving windows
keymaps = {
help = "?", -- Open floating window with help for the current mode
help_close = "q", -- Close the floating help window
quit = "q", -- Quit current mode
toggle_mode = "<tab>", -- Toggle between modes when in a mode
},
modes = {
move = {
left = "h", -- Move window left
down = "j", -- Move window down
up = "k", -- Move window up
right = "l", -- Move window right
far_left = "H", -- Move window far left and maximize it
far_down = "J", -- Move window down and maximize it
far_up = "K", -- Move window up and maximize it
far_right = "L", -- Move window right and maximize it
split_left = "sh", -- Create a split with the window on the left
split_down = "sj", -- Create a split with the window below
split_up = "sk", -- Create a split with the window above
split_right = "sl", -- Create a split with the window on the right
highlight = "Visual", -- Highlight group for move mode
at_edge = {
horizontal = at_edge.AtEdge.None, -- Behaviour at horizontal edges
vertical = at_edge.AtEdge.None, -- Behaviour at vertical edges
},
keymaps = {
left = "h", -- Move window left
down = "j", -- Move window down
up = "k", -- Move window up
right = "l", -- Move window right
far_left = "H", -- Move window far left and maximize it
far_down = "J", -- Move window down and maximize it
far_up = "K", -- Move window up and maximize it
far_right = "L", -- Move window right and maximize it
split_left = "sh", -- Create a split with the window on the left
split_down = "sj", -- Create a split with the window below
split_up = "sk", -- Create a split with the window above
split_right = "sl", -- Create a split with the window on the right
},
},
swap = {
highlight = "Substitute", -- Highlight group for swap mode
at_edge = {
horizontal = at_edge.AtEdge.None, -- Behaviour at horizontal edges
vertical = at_edge.AtEdge.None, -- Behaviour at vertical edges
},
keymaps = {
left = "h", -- Swap left
down = "j", -- Swap down
up = "k", -- Swap up
right = "l", -- Swap right
},
},
},
})
Expand Down Expand Up @@ -125,7 +144,7 @@ Get the current version of `winmove`.

#### `winmove.current_mode`

Check which mode is currently active. Returns `"move"` or `nil`.
Check which mode is currently active. Returns `"move"`, `"swap"`, or `nil`.

#### `winmove.start_mode`

Expand All @@ -137,6 +156,7 @@ winmove.start_mode(mode)

-- Example:
winmove.start_mode(winmove.Mode.Move)
winmove.start_mode("swap")
winmove.start_mode("move")
```

Expand Down Expand Up @@ -184,6 +204,36 @@ winmove.move_window_far(win_id, dir)
winmove.move_window_far(1000, "h")
```

#### `winmove.swap_window_in_direction`

Swap a window in a given direction (does not need to be the current window).

```lua
---@param win_id integer
---@param dir winmove.Direction
winmove.swap_window_in_direction(win_id, dir)

-- Example:
winmove.swap_window_in_direction(1000, "j")
winmove.swap_window_in_direction(1000, "l")
```

#### `winmove.swap_window`

Swap a window (does not need to be the current window). When called the first
time, highlights the selected window for swapping. When called the second time
with another window will swap the two selected windows.

```lua
---@param win_id integer
---@param dir winmove.Direction
winmove.swap_window(win_id, dir)

-- Example:
winmove.swap_window(1000)
winmove.swap_window(1000)
```

## Contributing

See [here](/CONTRIBUTING.md).
Expand Down
19 changes: 18 additions & 1 deletion lua/winmove/at_edge.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
local at_edge = {}

---@enum winmove.AtEdge
return {
at_edge.AtEdge = {
None = "none",
Wrap = "wrap",
MoveToTab = "move_to_tab",
}

---@param value any
---@return boolean
function at_edge.is_valid_behaviour(value)
if type(value) ~= "string" then
return false
end

return value == at_edge.AtEdge.None
or value == at_edge.AtEdge.Wrap
or value == at_edge.AtEdge.MoveToTab
end

return at_edge
Loading

0 comments on commit c9cdb33

Please sign in to comment.