feat: add move_tab_next/_previous commands
This commit is contained in:
parent
e053a0dcf4
commit
89e9fd7b83
2 changed files with 34 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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|
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue