diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 9fe0104..9605564 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -1182,6 +1182,16 @@ const cmds = struct { _ = try self.widgets_widget.msg(.{"previous_tab"}); } pub const previous_tab_meta: Meta = .{ .description = "Switch to previous tab" }; + + pub fn move_tab_next(self: *Self, _: Ctx) Result { + _ = try self.widgets_widget.msg(.{"move_tab_next"}); + } + pub const move_tab_next_meta: Meta = .{ .description = "Move tab to next position" }; + + pub fn move_tab_previous(self: *Self, _: Ctx) Result { + _ = try self.widgets_widget.msg(.{"move_tab_previous"}); + } + pub const move_tab_previous_meta: Meta = .{ .description = "Move tab to previous position" }; }; pub fn handle_editor_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result { diff --git a/src/tui/status/tabs.zig b/src/tui/status/tabs.zig index 2072c73..c324f25 100644 --- a/src/tui/status/tabs.zig +++ b/src/tui/status/tabs.zig @@ -155,6 +155,10 @@ pub const TabBar = struct { self.select_next_tab(); } else if (try m.match(.{"previous_tab"})) { self.select_previous_tab(); + } else if (try m.match(.{"move_tab_next"})) { + self.move_tab_next(); + } else if (try m.match(.{"move_tab_previous"})) { + self.move_tab_previous(); } else if (try m.match(.{ "E", "open", tp.extract(&file_path), tp.more })) { self.active_buffer_ref = if (buffer_manager.get_buffer_for_file(file_path)) |buffer| buffer_manager.buffer_to_ref(buffer) @@ -277,6 +281,26 @@ pub const TabBar = struct { if (goto) |tab| navigate_to_tab(tab); } + fn move_tab_next(self: *Self) void { + tp.trace(tp.channel.debug, .{"move_tab_next"}); + for (self.tabs, 0..) |*tab, idx| if (tab.buffer_ref == self.active_buffer_ref and idx < self.tabs.len - 1) { + const tmp = self.tabs[idx + 1]; + self.tabs[idx + 1] = self.tabs[idx]; + self.tabs[idx] = tmp; + break; + }; + } + + fn move_tab_previous(self: *Self) void { + tp.trace(tp.channel.debug, .{"move_tab_previous"}); + for (self.tabs, 0..) |*tab, idx| if (tab.buffer_ref == self.active_buffer_ref and idx > 0) { + const tmp = self.tabs[idx - 1]; + self.tabs[idx - 1] = self.tabs[idx]; + self.tabs[idx] = tmp; + break; + }; + } + fn navigate_to_tab(tab: *const TabBarTab) void { const buffer_manager = tui.get_buffer_manager() orelse @panic("tabs no buffer manager"); if (buffer_manager.buffer_from_ref(tab.buffer_ref)) |buffer|