From 9080fd4826a08797dc58c625c045a42f2f59afc6 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Wed, 25 Sep 2024 20:52:35 +0200 Subject: [PATCH] fix: correctly propagate eol mode to status bar widgets --- src/tui/editor.zig | 12 ++++++++---- src/tui/status/filestate.zig | 2 ++ src/tui/status/linenumstate.zig | 9 +++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index c8916af..0d33f45 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -1170,6 +1170,7 @@ pub const Editor = struct { self.last.primary = primary.*; self.last.dirty = dirty; self.last.root = root; + self.last.eol_mode = eol_mode; } 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 fn toggle_eol_mode(self: *Self, _: Context) Result { - if (self.buffer) |b| b.file_eol_mode = switch (b.file_eol_mode) { - .lf => .crlf, - .crlf => .lf, - }; + if (self.buffer) |b| { + b.file_eol_mode = switch (b.file_eol_mode) { + .lf => .crlf, + .crlf => .lf, + }; + self.update_event() catch {}; + } } pub const toggle_eol_mode_meta = .{ .description = "Toggle end of line sequence" }; }; diff --git a/src/tui/status/filestate.zig b/src/tui/status/filestate.zig index aa1afd6..3def46a 100644 --- a/src/tui/status/filestate.zig +++ b/src/tui/status/filestate.zig @@ -190,6 +190,7 @@ pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message self.file_dirty = false; 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) })) { + self.eol_mode = .lf; @memcpy(self.name_buf[0..file_path.len], file_path); self.name = self.name_buf[0..file_path.len]; @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.file_exists = true; self.file = false; + self.eol_mode = .lf; self.show_project(); } else if (try m.match(.{ "PRJ", "open" })) { if (!self.file) diff --git a/src/tui/status/linenumstate.zig b/src/tui/status/linenumstate.zig index 3646f57..359457f 100644 --- a/src/tui/status/linenumstate.zig +++ b/src/tui/status/linenumstate.zig @@ -34,8 +34,9 @@ fn on_click(_: *Self, _: *Button.State(Self)) void { command.executeName("goto", .{}) catch {}; } -pub fn layout(self: *Self, _: *Button.State(Self)) Widget.Layout { - return .{ .static = self.rendered.len }; +pub fn layout(self: *Self, btn: *Button.State(Self)) Widget.Layout { + 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 { @@ -64,11 +65,15 @@ pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message self.format(); } else if (try m.match(.{ "E", "eol_mode", tp.extract(&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" })) { self.lines = 0; self.line = 0; self.column = 0; self.rendered = ""; + self.eol_mode = .lf; } return false; }