feat: add command to add cursors to all line ends
This commit is contained in:
parent
8f8d4b6145
commit
4585c5af62
6 changed files with 34 additions and 0 deletions
3
help.md
3
help.md
|
@ -142,6 +142,9 @@ cycle style of editing.
|
||||||
- Ctrl-Shift-l =>
|
- Ctrl-Shift-l =>
|
||||||
Add cursors to all matches
|
Add cursors to all matches
|
||||||
|
|
||||||
|
- Shift-Alt-i =>
|
||||||
|
Add cursors to line ends
|
||||||
|
|
||||||
- Ctrl-MouseLeft =>
|
- Ctrl-MouseLeft =>
|
||||||
Add cursor at mouse click
|
Add cursor at mouse click
|
||||||
|
|
||||||
|
|
|
@ -2098,6 +2098,33 @@ pub const Editor = struct {
|
||||||
try self.send_editor_jump_destination();
|
try self.send_editor_jump_destination();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_cursors_to_cursel_line_ends(self: *Self, root: Buffer.Root, cursel: *CurSel) !void {
|
||||||
|
var sel = cursel.enable_selection();
|
||||||
|
sel.normalize();
|
||||||
|
var row = sel.begin.row;
|
||||||
|
while (row <= sel.end.row) : (row += 1) {
|
||||||
|
const new_cursel = try self.cursels.addOne();
|
||||||
|
new_cursel.* = CurSel{
|
||||||
|
.selection = null,
|
||||||
|
.cursor = .{
|
||||||
|
.row = row,
|
||||||
|
.col = 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
new_cursel.*.?.cursor.move_end(root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_cursors_to_line_ends(self: *Self, _: command.Context) tp.result {
|
||||||
|
const root = self.buf_root() catch |e| return tp.exit_error(e);
|
||||||
|
const cursels = self.cursels.toOwnedSlice() catch |e| return tp.exit_error(e);
|
||||||
|
defer self.cursels.allocator.free(cursels);
|
||||||
|
for (cursels) |*cursel_| if (cursel_.*) |*cursel|
|
||||||
|
self.add_cursors_to_cursel_line_ends(root, cursel) catch |e| return tp.exit_error(e);
|
||||||
|
self.collapse_cursors();
|
||||||
|
self.clamp();
|
||||||
|
}
|
||||||
|
|
||||||
fn pull_cursel_up(self: *Self, root_: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root {
|
fn pull_cursel_up(self: *Self, root_: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root {
|
||||||
var root = root_;
|
var root = root_;
|
||||||
const saved = cursel.*;
|
const saved = cursel.*;
|
||||||
|
|
|
@ -152,6 +152,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
||||||
'F' => self.cmd("filter", command.fmt(.{ "zig", "fmt", "--stdin" })),
|
'F' => self.cmd("filter", command.fmt(.{ "zig", "fmt", "--stdin" })),
|
||||||
'S' => self.cmd("filter", command.fmt(.{ "sort", "-u" })),
|
'S' => self.cmd("filter", command.fmt(.{ "sort", "-u" })),
|
||||||
'V' => self.cmd("paste", .{}),
|
'V' => self.cmd("paste", .{}),
|
||||||
|
'I' => self.cmd("add_cursors_to_line_ends", .{}),
|
||||||
key.LEFT => self.cmd("move_scroll_left", .{}),
|
key.LEFT => self.cmd("move_scroll_left", .{}),
|
||||||
key.RIGHT => self.cmd("move_scroll_right", .{}),
|
key.RIGHT => self.cmd("move_scroll_right", .{}),
|
||||||
key.UP => self.cmd("add_cursor_up", .{}),
|
key.UP => self.cmd("add_cursor_up", .{}),
|
||||||
|
|
|
@ -152,6 +152,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
||||||
'F' => self.cmd("filter", command.fmt(.{ "zig", "fmt", "--stdin" })),
|
'F' => self.cmd("filter", command.fmt(.{ "zig", "fmt", "--stdin" })),
|
||||||
'S' => self.cmd("filter", command.fmt(.{ "sort", "-u" })),
|
'S' => self.cmd("filter", command.fmt(.{ "sort", "-u" })),
|
||||||
'V' => self.cmd("paste", .{}),
|
'V' => self.cmd("paste", .{}),
|
||||||
|
'I' => self.cmd("add_cursors_to_line_ends", .{}),
|
||||||
key.LEFT => self.cmd("move_scroll_left", .{}),
|
key.LEFT => self.cmd("move_scroll_left", .{}),
|
||||||
key.RIGHT => self.cmd("move_scroll_right", .{}),
|
key.RIGHT => self.cmd("move_scroll_right", .{}),
|
||||||
key.UP => self.cmd("add_cursor_up", .{}),
|
key.UP => self.cmd("add_cursor_up", .{}),
|
||||||
|
|
|
@ -157,6 +157,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
||||||
'F' => self.cmd("filter", command.fmt(.{ "zig", "fmt", "--stdin" })),
|
'F' => self.cmd("filter", command.fmt(.{ "zig", "fmt", "--stdin" })),
|
||||||
'S' => self.cmd("filter", command.fmt(.{ "sort", "-u" })),
|
'S' => self.cmd("filter", command.fmt(.{ "sort", "-u" })),
|
||||||
'V' => self.cmd("paste", .{}),
|
'V' => self.cmd("paste", .{}),
|
||||||
|
'I' => self.cmd("add_cursors_to_line_ends", .{}),
|
||||||
key.LEFT => self.cmd("move_scroll_left", .{}),
|
key.LEFT => self.cmd("move_scroll_left", .{}),
|
||||||
key.RIGHT => self.cmd("move_scroll_right", .{}),
|
key.RIGHT => self.cmd("move_scroll_right", .{}),
|
||||||
key.UP => self.cmd("add_cursor_up", .{}),
|
key.UP => self.cmd("add_cursor_up", .{}),
|
||||||
|
|
|
@ -155,6 +155,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
||||||
'F' => self.cmd("filter", command.fmt(.{ "zig", "fmt", "--stdin" })),
|
'F' => self.cmd("filter", command.fmt(.{ "zig", "fmt", "--stdin" })),
|
||||||
'S' => self.cmd("filter", command.fmt(.{ "sort", "-u" })),
|
'S' => self.cmd("filter", command.fmt(.{ "sort", "-u" })),
|
||||||
'V' => self.cmd("paste", .{}),
|
'V' => self.cmd("paste", .{}),
|
||||||
|
'I' => self.cmd("add_cursors_to_line_ends", .{}),
|
||||||
key.LEFT => self.cmd("move_scroll_left", .{}),
|
key.LEFT => self.cmd("move_scroll_left", .{}),
|
||||||
key.RIGHT => self.cmd("move_scroll_right", .{}),
|
key.RIGHT => self.cmd("move_scroll_right", .{}),
|
||||||
else => {},
|
else => {},
|
||||||
|
|
Loading…
Add table
Reference in a new issue