Compare commits

...

9 commits

3 changed files with 34 additions and 48 deletions

View file

@ -201,6 +201,7 @@
["shift+kp_page_down", "select_page_down"], ["shift+kp_page_down", "select_page_down"],
["shift+enter", "smart_insert_line_before"], ["shift+enter", "smart_insert_line_before"],
["shift+backspace", "delete_backward"], ["shift+backspace", "delete_backward"],
["ctrl+shift+k", "delete_line"],
["shift+tab", "unindent"], ["shift+tab", "unindent"],
["f2", "rename_symbol"], ["f2", "rename_symbol"],
["f3", "goto_next_match"], ["f3", "goto_next_match"],

View file

@ -2406,7 +2406,7 @@ pub const Editor = struct {
primary.disable_selection(root, self.metrics); primary.disable_selection(root, self.metrics);
self.selection_mode = .line; self.selection_mode = .line;
primary.cursor.move_abs(root, &self.view, @intCast(y), @intCast(x), self.metrics) catch return; 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.selection_drag_initial = primary.selection;
self.clamp_mouse(); self.clamp_mouse();
} }
@ -2678,13 +2678,8 @@ pub const Editor = struct {
const primary = self.get_primary(); const primary = self.get_primary();
const b = self.buf_for_update() catch return; const b = self.buf_for_update() catch return;
var root = b.root; var root = b.root;
if (self.cursels.items.len == 1) if (self.cursels.items.len == 1 and primary.selection == null)
if (primary.selection) |_| {} else { try self.select_line_at_cursor(root, primary, .include_eol);
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);
};
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
const cut_text, root = try self.cut_selection(root, cursel, tui.clipboard_allocator()); const cut_text, root = try self.cut_selection(root, cursel, tui.clipboard_allocator());
tui.clipboard_add_chunk(cut_text); tui.clipboard_add_chunk(cut_text);
@ -2698,19 +2693,8 @@ pub const Editor = struct {
const primary = self.get_primary(); const primary = self.get_primary();
const b = self.buf_for_update() catch return; const b = self.buf_for_update() catch return;
var root = b.root; var root = b.root;
if (self.cursels.items.len == 1) if (self.cursels.items.len == 1 and primary.selection == null)
if (primary.selection) |_| {} else { try self.select_line_at_cursor(root, primary, .include_eol);
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,
};
};
var count: usize = 0; var count: usize = 0;
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
count += 1; count += 1;
@ -3031,6 +3015,23 @@ pub const Editor = struct {
} }
pub const delete_to_end_meta: Meta = .{ .description = "Delete to end of line" }; 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 { pub fn cut_to_end_vim(self: *Self, _: Context) Result {
const b = try self.buf_for_update(); const b = try self.buf_for_update();
const root = try self.cut_to(move_cursor_end_vim, b.root); 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 const enable_selection_meta: Meta = .{ .description = "Enable selection" };
pub fn select_line_vim(self: *Self, _: Context) Result { pub fn select_line_vim(self: *Self, _: Context) Result {
const root = try self.buf_root();
self.selection_mode = .line; self.selection_mode = .line;
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| 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.collapse_cursors();
self.clamp(); self.clamp();
@ -4102,21 +4104,19 @@ pub const Editor = struct {
return sel; return sel;
} }
fn select_line_at_cursor(self: *Self, cursel: *CurSel) !void { fn select_line_at_cursor(self: *Self, root: Buffer.Root, cursel: *CurSel, mode: enum { include_eol, exclude_eol, hold_cursor }) !void {
const root = try self.buf_root();
const sel = try cursel.enable_selection(root, self.metrics); const sel = try cursel.enable_selection(root, self.metrics);
sel.normalize(); sel.normalize();
try move_cursor_begin(root, &sel.begin, self.metrics); try move_cursor_begin(root, &sel.begin, self.metrics);
move_cursor_end(root, &sel.end, self.metrics) catch {}; move_cursor_end(root, &sel.end, self.metrics) catch {};
cursel.cursor = sel.end; 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,
} }
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);
} }
fn selection_reverse(_: Buffer.Root, cursel: *CurSel) !void { fn selection_reverse(_: Buffer.Root, cursel: *CurSel) !void {

View file

@ -140,19 +140,4 @@ const cmds_ = struct {
} }
pub const copy_line_meta: Meta = .{ .description = "Copies the current line" }; 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" };
}; };