From 7af0c7ff716ee5d40c10b9e9d80254368c83ed4c Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sun, 2 Nov 2025 19:24:04 +0100 Subject: [PATCH] fix: improve dupe_cursel_down to correctly handle duplicating at EOF closes #346 --- src/tui/editor.zig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index ba27a3e..dc89c6a 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -3605,12 +3605,20 @@ pub const Editor = struct { fn dupe_cursel_down(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { var root = root_; const sel: Selection = if (cursel.selection) |sel_| sel_ else Selection.line_from_cursor(cursel.cursor, root, self.metrics); - cursel.disable_selection(root, self.metrics); var sfa = std.heap.stackFallback(4096, self.allocator); const sfa_allocator = sfa.get(); const text = copy_selection(root, sel, sfa_allocator, self.metrics) catch return error.Stop; defer sfa_allocator.free(text); + cursel.cursor = sel.end; + if (cursel.selection) |_| { + cursel.disable_selection(root, self.metrics); + } else { + var test_eof = sel.end; + test_eof.move_right(root, self.metrics) catch { // test for EOF + root = self.insert(root, cursel, "\n", allocator) catch return error.Stop; + }; + } root = self.insert(root, cursel, text, allocator) catch return error.Stop; cursel.selection = .{ .begin = sel.end, .end = cursel.cursor }; return root;