Compare commits

..

No commits in common. "fc8642768d5b61dd414b8252ae3d9b5bae5e9b50" and "e76c47e1a6c9c30846449c967bc1f073783d7cbc" have entirely different histories.

3 changed files with 48 additions and 34 deletions

View file

@ -201,7 +201,6 @@
["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(root, primary, .exclude_eol); try self.select_line_at_cursor(primary);
self.selection_drag_initial = primary.selection; self.selection_drag_initial = primary.selection;
self.clamp_mouse(); self.clamp_mouse();
} }
@ -2678,8 +2678,13 @@ 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 and primary.selection == null) if (self.cursels.items.len == 1)
try self.select_line_at_cursor(root, primary, .include_eol); 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);
};
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);
@ -2693,8 +2698,19 @@ 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 and primary.selection == null) if (self.cursels.items.len == 1)
try self.select_line_at_cursor(root, primary, .include_eol); 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,
};
};
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;
@ -3015,23 +3031,6 @@ 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);
@ -3861,10 +3860,9 @@ 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_at_cursor(root, cursel, .hold_cursor); try self.select_line_around_cursor(cursel);
self.collapse_cursors(); self.collapse_cursors();
self.clamp(); self.clamp();
@ -4104,19 +4102,21 @@ pub const Editor = struct {
return sel; return sel;
} }
fn select_line_at_cursor(self: *Self, root: Buffer.Root, cursel: *CurSel, mode: enum { include_eol, exclude_eol, hold_cursor }) !void { fn select_line_at_cursor(self: *Self, cursel: *CurSel) !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 {};
switch (mode) { cursel.cursor = sel.end;
.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 => {},
} pub fn select_line_around_cursor(self: *Self, cursel: *CurSel) !void {
switch (mode) { const root = try self.buf_root();
.hold_cursor => {}, const sel = try cursel.enable_selection(root, self.metrics);
else => cursel.cursor = sel.end, 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,4 +140,19 @@ 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" };
}; };