From 8f089672da184d491b64883300b98c54121ac217 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Fri, 1 Aug 2025 23:29:30 +0200 Subject: [PATCH] feat: collapse whitespace to the right of the cursor in smart_insert_line --- src/tui/editor.zig | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 706f68d..e432ab8 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -4468,8 +4468,18 @@ pub const Editor = struct { var writer = stream.writer(allocator); _ = try writer.write("\n"); try self.generate_leading_ws(&writer, leading_ws); - const root_ = try self.insert(root, cursel, stream.items, b_allocator); - return self.collapse_trailing_ws_line(root_, row, b_allocator); + var root_ = try self.insert(root, cursel, stream.items, b_allocator); + root_ = self.collapse_trailing_ws_line(root_, row, b_allocator); + const leading_ws_ = find_first_non_ws(root_, cursel.cursor.row, self.metrics); + if (leading_ws_ > leading_ws and leading_ws_ > cursel.cursor.col) { + const sel = try cursel.enable_selection(root_, self.metrics); + sel.* = .{ + .begin = .{ .row = cursel.cursor.row, .col = cursel.cursor.col }, + .end = .{ .row = cursel.cursor.row, .col = leading_ws_ }, + }; + root_ = self.delete_selection(root_, cursel, b_allocator) catch root_; + } + return root_; } pub fn smart_insert_line(self: *Self, _: Context) Result {