From 80cb31f75aaef306933f7b8f5efd7483f116c9a5 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sat, 18 Jan 2025 17:16:00 +0100 Subject: [PATCH] feat: copy current line if there is no selection closes #160 --- src/tui/editor.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 7be1f41..a9c78e0 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -2287,9 +2287,17 @@ pub const Editor = struct { pub const cut_meta = .{ .description = "Cut selection or current line to clipboard" }; pub fn copy(self: *Self, _: Context) Result { + const primary = self.get_primary(); const root = self.buf_root() catch return; var first = true; var text = std.ArrayList(u8).init(self.allocator); + if (self.cursels.items.len == 1) + if (primary.selection) |_| {} else { + const sel = primary.enable_selection(); + try move_cursor_begin(root, &sel.begin, self.metrics); + try move_cursor_end(root, &sel.end, self.metrics); + try move_cursor_right(root, &sel.end, self.metrics); + }; for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { if (cursel.selection) |sel| { const copy_text = try copy_selection(root, sel, self.allocator, self.metrics);