fix: correctly propagate eol mode to status bar widgets

This commit is contained in:
CJ van den Berg 2024-09-25 20:52:35 +02:00
parent fb0531de5c
commit 9080fd4826
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 17 additions and 6 deletions

View file

@ -1170,6 +1170,7 @@ pub const Editor = struct {
self.last.primary = primary.*; self.last.primary = primary.*;
self.last.dirty = dirty; self.last.dirty = dirty;
self.last.root = root; self.last.root = root;
self.last.eol_mode = eol_mode;
} }
fn send_editor_pos(self: *const Self, cursor: *const Cursor) !void { fn send_editor_pos(self: *const Self, cursor: *const Cursor) !void {
@ -3869,10 +3870,13 @@ pub const Editor = struct {
pub const to_lower_meta = .{ .description = "Convert selection or word to lower case" }; pub const to_lower_meta = .{ .description = "Convert selection or word to lower case" };
pub fn toggle_eol_mode(self: *Self, _: Context) Result { pub fn toggle_eol_mode(self: *Self, _: Context) Result {
if (self.buffer) |b| b.file_eol_mode = switch (b.file_eol_mode) { if (self.buffer) |b| {
b.file_eol_mode = switch (b.file_eol_mode) {
.lf => .crlf, .lf => .crlf,
.crlf => .lf, .crlf => .lf,
}; };
self.update_event() catch {};
}
} }
pub const toggle_eol_mode_meta = .{ .description = "Toggle end of line sequence" }; pub const toggle_eol_mode_meta = .{ .description = "Toggle end of line sequence" };
}; };

View file

@ -190,6 +190,7 @@ pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message
self.file_dirty = false; self.file_dirty = false;
self.name = root.abbreviate_home(&self.name_buf, self.name); self.name = root.abbreviate_home(&self.name_buf, self.name);
} else if (try m.match(.{ "E", "open", tp.extract(&file_path), tp.extract(&self.file_exists), tp.extract(&file_type), tp.extract(&file_icon), tp.extract(&self.file_color) })) { } else if (try m.match(.{ "E", "open", tp.extract(&file_path), tp.extract(&self.file_exists), tp.extract(&file_type), tp.extract(&file_icon), tp.extract(&self.file_color) })) {
self.eol_mode = .lf;
@memcpy(self.name_buf[0..file_path.len], file_path); @memcpy(self.name_buf[0..file_path.len], file_path);
self.name = self.name_buf[0..file_path.len]; self.name = self.name_buf[0..file_path.len];
@memcpy(self.file_type_buf[0..file_type.len], file_type); @memcpy(self.file_type_buf[0..file_type.len], file_type);
@ -207,6 +208,7 @@ pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message
self.column = 0; self.column = 0;
self.file_exists = true; self.file_exists = true;
self.file = false; self.file = false;
self.eol_mode = .lf;
self.show_project(); self.show_project();
} else if (try m.match(.{ "PRJ", "open" })) { } else if (try m.match(.{ "PRJ", "open" })) {
if (!self.file) if (!self.file)

View file

@ -34,8 +34,9 @@ fn on_click(_: *Self, _: *Button.State(Self)) void {
command.executeName("goto", .{}) catch {}; command.executeName("goto", .{}) catch {};
} }
pub fn layout(self: *Self, _: *Button.State(Self)) Widget.Layout { pub fn layout(self: *Self, btn: *Button.State(Self)) Widget.Layout {
return .{ .static = self.rendered.len }; const len = btn.plane.egc_chunk_width(self.rendered, 0);
return .{ .static = len };
} }
pub fn render(self: *Self, btn: *Button.State(Self), theme: *const Widget.Theme) bool { pub fn render(self: *Self, btn: *Button.State(Self), theme: *const Widget.Theme) bool {
@ -64,11 +65,15 @@ pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message
self.format(); self.format();
} else if (try m.match(.{ "E", "eol_mode", tp.extract(&eol_mode) })) { } else if (try m.match(.{ "E", "eol_mode", tp.extract(&eol_mode) })) {
self.eol_mode = @enumFromInt(eol_mode); self.eol_mode = @enumFromInt(eol_mode);
self.format();
} else if (try m.match(.{ "E", "open", tp.more })) {
self.eol_mode = .lf;
} else if (try m.match(.{ "E", "close" })) { } else if (try m.match(.{ "E", "close" })) {
self.lines = 0; self.lines = 0;
self.line = 0; self.line = 0;
self.column = 0; self.column = 0;
self.rendered = ""; self.rendered = "";
self.eol_mode = .lf;
} }
return false; return false;
} }