File tree 3 files changed +26
-0
lines changed
3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ local lazy = require('smart-splits.lazy')
2
2
local config = lazy .require_on_index (' smart-splits.config' ) --[[ @as SmartSplitsConfig]]
3
3
local mux = lazy .require_on_exported_call (' smart-splits.mux' ) --[[ @as SmartSplitsMultiplexer]]
4
4
local utils = require (' smart-splits.utils' )
5
+ local mux_utils = require (' smart-splits.mux.utils' )
5
6
local types = require (' smart-splits.types' )
6
7
local Direction = types .Direction
7
8
local AtEdgeBehavior = types .AtEdgeBehavior
@@ -489,4 +490,11 @@ end, {
489
490
Direction .down ,
490
491
})
491
492
493
+ function M .move_cursor_previous_win ()
494
+ local win = mux_utils .get_previous_win ()
495
+ if win then
496
+ vim .api .nvim_set_current_win (win )
497
+ end
498
+ end
499
+
492
500
return M
Original file line number Diff line number Diff line change 21
21
Direction .down ,
22
22
})
23
23
24
+ M .move_cursor_previous_win = lazy .require_on_exported_call (' smart-splits.api' ).move_cursor_previous_win
25
+
24
26
M .start_resize_mode = function ()
25
27
require (' smart-splits.resize-mode' ).start_resize_mode ()
26
28
end
Original file line number Diff line number Diff line change @@ -35,11 +35,27 @@ function M.are_we_gui()
35
35
return current_ui ~= nil and not current_ui .stdin_tty and not current_ui .stdout_tty
36
36
end
37
37
38
+ local prev_win = nil
39
+
40
+ --- Return the buf ID of the previous buffer, if there is one
41
+ --- @return number | nil
42
+ function M .get_previous_win ()
43
+ return prev_win
44
+ end
45
+
38
46
--- Initialization for mux capabilities.
39
47
--- If selected mux has an `on_init` or `on_exit`,
40
48
--- call `on_init` and set up autocmds to call `on_init` on `VimResume`
41
49
--- and `on_exit` on `VimSuspend` and `VimLeavePre`.
42
50
function M .startup ()
51
+ -- buffer tracking for "previous buffer"
52
+ vim .api .nvim_create_autocmd (' WinLeave' , {
53
+ callback = function ()
54
+ prev_win = tonumber (vim .api .nvim_get_current_win ())
55
+ end ,
56
+ })
57
+
58
+ -- multiplexer startup/shutdown events
43
59
local mux = require (' smart-splits.mux' ).get ()
44
60
if not mux then
45
61
return
You can’t perform that action at this time.
0 commit comments