feat: if buffer is dirty show save button in tabs instead of close
This commit is contained in:
parent
cf806b23ab
commit
00bbeaedf9
1 changed files with 18 additions and 3 deletions
|
@ -27,6 +27,8 @@ const @"style.config" = struct {
|
||||||
dirty_indicator_fg: ?colors = null,
|
dirty_indicator_fg: ?colors = null,
|
||||||
close_icon: []const u8 = "",
|
close_icon: []const u8 = "",
|
||||||
close_icon_fg: colors = .Error,
|
close_icon_fg: colors = .Error,
|
||||||
|
save_icon: []const u8 = "",
|
||||||
|
save_icon_fg: ?colors = null,
|
||||||
|
|
||||||
spacer: []const u8 = "|",
|
spacer: []const u8 = "|",
|
||||||
spacer_fg: colors = .active_bg,
|
spacer_fg: colors = .active_bg,
|
||||||
|
@ -325,6 +327,7 @@ const Tab = struct {
|
||||||
buffer_ref: usize,
|
buffer_ref: usize,
|
||||||
tab_style: *const Style,
|
tab_style: *const Style,
|
||||||
close_pos: ?c_uint = null,
|
close_pos: ?c_uint = null,
|
||||||
|
save_pos: ?c_uint = null,
|
||||||
|
|
||||||
const Mode = enum { active, inactive, selected };
|
const Mode = enum { active, inactive, selected };
|
||||||
|
|
||||||
|
@ -356,6 +359,10 @@ const Tab = struct {
|
||||||
tp.self_pid().send(.{ "cmd", "close_buffer", .{buffer.get_file_path()} }) catch {};
|
tp.self_pid().send(.{ "cmd", "close_buffer", .{buffer.get_file_path()} }) catch {};
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
if (self.save_pos) |save_pos| if (pos.col == save_pos) {
|
||||||
|
tp.self_pid().send(.{ "cmd", "save_buffer", .{buffer.get_file_path()} }) catch {};
|
||||||
|
return;
|
||||||
|
};
|
||||||
tp.self_pid().send(.{ "cmd", "navigate", .{ .file = buffer.get_file_path() } }) catch {};
|
tp.self_pid().send(.{ "cmd", "navigate", .{ .file = buffer.get_file_path() } }) catch {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -498,10 +505,18 @@ const Tab = struct {
|
||||||
_ = btn.plane.putstr(btn.opts.label) catch {};
|
_ = btn.plane.putstr(btn.opts.label) catch {};
|
||||||
_ = btn.plane.putstr(" ") catch {};
|
_ = btn.plane.putstr(" ") catch {};
|
||||||
self.close_pos = null;
|
self.close_pos = null;
|
||||||
|
self.save_pos = null;
|
||||||
if (btn.hover) {
|
if (btn.hover) {
|
||||||
btn.plane.set_style(.{ .fg = self.tab_style.close_icon_fg.from_theme(theme) });
|
if (is_dirty) {
|
||||||
self.close_pos = btn.plane.cursor_x();
|
if (self.tab_style.save_icon_fg) |color|
|
||||||
_ = btn.plane.putstr(self.tabbar.tab_style.close_icon) catch {};
|
btn.plane.set_style(.{ .fg = color.from_theme(theme) });
|
||||||
|
self.save_pos = btn.plane.cursor_x();
|
||||||
|
_ = btn.plane.putstr(self.tabbar.tab_style.save_icon) catch {};
|
||||||
|
} else {
|
||||||
|
btn.plane.set_style(.{ .fg = self.tab_style.close_icon_fg.from_theme(theme) });
|
||||||
|
self.close_pos = btn.plane.cursor_x();
|
||||||
|
_ = btn.plane.putstr(self.tabbar.tab_style.close_icon) catch {};
|
||||||
|
}
|
||||||
} else if (is_dirty) {
|
} else if (is_dirty) {
|
||||||
if (self.tab_style.dirty_indicator_fg) |color|
|
if (self.tab_style.dirty_indicator_fg) |color|
|
||||||
btn.plane.set_style(.{ .fg = color.from_theme(theme) });
|
btn.plane.set_style(.{ .fg = color.from_theme(theme) });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue