diff --git a/src/keybind/builtin/flow.json b/src/keybind/builtin/flow.json index 9e0c3cd..4edfb38 100644 --- a/src/keybind/builtin/flow.json +++ b/src/keybind/builtin/flow.json @@ -201,6 +201,7 @@ ["shift+kp_page_down", "select_page_down"], ["shift+enter", "smart_insert_line_before"], ["shift+backspace", "delete_backward"], + ["ctrl+shift+k", "delete_line"], ["shift+tab", "unindent"], ["f2", "rename_symbol"], ["f3", "goto_next_match"], diff --git a/src/tui/editor.zig b/src/tui/editor.zig index ca0ed0f..948ac8b 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -2406,7 +2406,7 @@ pub const Editor = struct { primary.disable_selection(root, self.metrics); self.selection_mode = .line; primary.cursor.move_abs(root, &self.view, @intCast(y), @intCast(x), self.metrics) catch return; - try self.select_line_at_cursor(primary); + try self.select_line_at_cursor(root, primary, .exclude_eol); self.selection_drag_initial = primary.selection; self.clamp_mouse(); } @@ -2678,13 +2678,8 @@ pub const Editor = struct { const primary = self.get_primary(); const b = self.buf_for_update() catch return; var root = b.root; - if (self.cursels.items.len == 1) - if (primary.selection) |_| {} else { - const sel = primary.enable_selection(root, self.metrics) catch return; - 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); - }; + if (self.cursels.items.len == 1 and primary.selection == null) + try self.select_line_at_cursor(root, primary, .include_eol); for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { const cut_text, root = try self.cut_selection(root, cursel, tui.clipboard_allocator()); tui.clipboard_add_chunk(cut_text); @@ -2698,19 +2693,8 @@ pub const Editor = struct { const primary = self.get_primary(); const b = self.buf_for_update() catch return; var root = b.root; - if (self.cursels.items.len == 1) - if (primary.selection) |_| {} else { - const sel = primary.enable_selection(root, self.metrics) catch return; - try move_cursor_begin(root, &sel.begin, self.metrics); - move_cursor_end(root, &sel.end, self.metrics) catch |e| switch (e) { - error.Stop => {}, - else => return e, - }; - move_cursor_right(root, &sel.end, self.metrics) catch |e| switch (e) { - error.Stop => {}, - else => return e, - }; - }; + if (self.cursels.items.len == 1 and primary.selection == null) + try self.select_line_at_cursor(root, primary, .include_eol); var count: usize = 0; for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { count += 1; @@ -3031,6 +3015,23 @@ pub const Editor = struct { } pub const delete_to_end_meta: Meta = .{ .description = "Delete to end of line" }; + pub fn delete_line(self: *Self, _: Context) Result { + const b = try self.buf_for_update(); + var root = b.root; + for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { + const col = cursel.cursor.col; + const target = cursel.cursor.target; + try self.select_line_at_cursor(root, cursel, .include_eol); + root = try self.delete_selection(root, cursel, b.allocator); + cursel.cursor.col = col; + cursel.cursor.target = target; + cursel.cursor.clamp_to_buffer(root, self.metrics); + }; + try self.update_buf(root); + self.clamp(); + } + pub const delete_line_meta: Meta = .{ .description = "Delete current line" }; + pub fn cut_to_end_vim(self: *Self, _: Context) Result { const b = try self.buf_for_update(); const root = try self.cut_to(move_cursor_end_vim, b.root); @@ -3860,9 +3861,10 @@ pub const Editor = struct { pub const enable_selection_meta: Meta = .{ .description = "Enable selection" }; pub fn select_line_vim(self: *Self, _: Context) Result { + const root = try self.buf_root(); self.selection_mode = .line; for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| - try self.select_line_around_cursor(cursel); + try self.select_line_at_cursor(root, cursel, .hold_cursor); self.collapse_cursors(); self.clamp(); @@ -4102,21 +4104,19 @@ pub const Editor = struct { return sel; } - fn select_line_at_cursor(self: *Self, cursel: *CurSel) !void { - const root = try self.buf_root(); + fn select_line_at_cursor(self: *Self, root: Buffer.Root, cursel: *CurSel, mode: enum { include_eol, exclude_eol, hold_cursor }) !void { const sel = try cursel.enable_selection(root, self.metrics); sel.normalize(); try move_cursor_begin(root, &sel.begin, self.metrics); move_cursor_end(root, &sel.end, self.metrics) catch {}; - cursel.cursor = sel.end; - } - - pub fn select_line_around_cursor(self: *Self, cursel: *CurSel) !void { - const root = try self.buf_root(); - const sel = try cursel.enable_selection(root, self.metrics); - sel.normalize(); - try move_cursor_begin(root, &sel.begin, self.metrics); - try move_cursor_end(root, &sel.end, self.metrics); + switch (mode) { + .include_eol => move_cursor_right(root, &sel.end, self.metrics) catch {}, // catch{} because may be impossible to get eol (e.g., we're at eof) + else => {}, + } + switch (mode) { + .hold_cursor => {}, + else => cursel.cursor = sel.end, + } } fn selection_reverse(_: Buffer.Root, cursel: *CurSel) !void { diff --git a/src/tui/mode/vim.zig b/src/tui/mode/vim.zig index 9cefd76..38eacbe 100644 --- a/src/tui/mode/vim.zig +++ b/src/tui/mode/vim.zig @@ -140,19 +140,4 @@ const cmds_ = struct { } pub const copy_line_meta: Meta = .{ .description = "Copies the current line" }; - - pub fn delete_line(self: *void, ctx: Ctx) Result { - _ = self; // autofix - _ = ctx; // autofix - //TODO - return undefined; - //try self.move_begin(ctx); - //const b = try self.buf_for_update(); - //var root = try self.delete_to(move_cursor_end, b.root, b.allocator); - //root = try self.delete_to(move_cursor_right, b.root, b.allocator); - //try self.delete_forward(ctx); - //try self.update_buf(root); - //self.clamp(); - } - pub const delete_line_meta: Meta = .{ .description = "Delete the current line without copying" }; };