feat: add metadata to all commands

This commit is contained in:
CJ van den Berg 2024-09-17 22:58:35 +02:00
parent bdd16f43fb
commit d75dcd7b84
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
13 changed files with 221 additions and 6 deletions

View file

@ -475,6 +475,7 @@ pub const Editor = struct {
}
self.clamp();
}
pub const pop_cursor_meta = .{ .description = "Remove last added cursor" };
pub fn get_primary(self: *const Self) *CurSel {
var idx = self.cursels.items.len;
@ -534,9 +535,9 @@ pub const Editor = struct {
self.cancel_all_matches();
var sfa = std.heap.stackFallback(512, self.allocator);
const allocator = sfa.get();
const redo_meta = try self.store_current_undo_meta(allocator);
defer allocator.free(redo_meta);
const meta = b_mut.undo(redo_meta) catch |e| switch (e) {
const redo_metadata = try self.store_current_undo_meta(allocator);
defer allocator.free(redo_metadata);
const meta = b_mut.undo(redo_metadata) catch |e| switch (e) {
error.Stop => {
self.logger.print("nothing to undo", .{});
return;
@ -1767,6 +1768,7 @@ pub const Editor = struct {
return error.InvalidArgument;
return self.primary_drag(y, x);
}
pub const drag_to_meta = .{ .interactive = false };
pub fn secondary_click(self: *Self, y: c_int, x: c_int) !void {
return self.primary_drag(y, x);
@ -1860,6 +1862,7 @@ pub const Editor = struct {
else
self.scroll_up();
}
pub const scroll_up_pageup_meta = .{ .interactive = false };
pub fn scroll_down_pagedown(self: *Self, _: Context) Result {
if (self.fast_scroll)
@ -1867,6 +1870,7 @@ pub const Editor = struct {
else
self.scroll_down();
}
pub const scroll_down_pagedown_meta = .{ .interactive = false };
pub fn scroll_to(self: *Self, row: usize) void {
self.update_scroll_dest_abs(row);
@ -1881,14 +1885,17 @@ pub const Editor = struct {
pub fn scroll_view_center(self: *Self, _: Context) Result {
return self.scroll_view_offset(self.view.rows / 2);
}
pub const scroll_view_center_meta = .{ .description = "Scroll cursor to center/top/bottom of view" };
pub fn scroll_view_top(self: *Self, _: Context) Result {
return self.scroll_view_offset(scroll_cursor_min_border_distance);
}
pub const scroll_view_top_meta = .{ .interactive = false };
pub fn scroll_view_bottom(self: *Self, _: Context) Result {
return self.scroll_view_offset(if (self.view.rows > scroll_cursor_min_border_distance) self.view.rows - scroll_cursor_min_border_distance else 0);
}
pub const scroll_view_bottom_meta = .{ .interactive = false };
fn set_clipboard(self: *Self, text: []const u8) void {
if (self.clipboard) |old|
@ -1970,6 +1977,7 @@ pub const Editor = struct {
self.set_clipboard(text.items);
self.clamp();
}
pub const cut_meta = .{ .description = "Cut selection or current line to clipboard" };
pub fn copy(self: *Self, _: Context) Result {
const root = self.buf_root() catch return;
@ -1995,6 +2003,7 @@ pub const Editor = struct {
self.set_clipboard(text.items);
}
}
pub const copy_meta = .{ .description = "Copy selection to clipboard" };
pub fn paste(self: *Self, ctx: Context) Result {
var text: []const u8 = undefined;
@ -2029,11 +2038,13 @@ pub const Editor = struct {
self.clamp();
self.need_render();
}
pub const paste_meta = .{ .description = "Paste from internal clipboard" };
pub fn system_paste(self: *Self, _: Context) Result {
if (builtin.os.tag == .windows) return self.paste(.{});
tui.current().rdr.request_system_clipboard();
}
pub const system_paste_meta = .{ .description = "Paste from system clipboard" };
pub fn delete_forward(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
@ -2041,6 +2052,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const delete_forward_meta = .{ .description = "Delete next character" };
pub fn delete_backward(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
@ -2048,6 +2060,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const delete_backward_meta = .{ .description = "Delete previous character" };
pub fn delete_word_left(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
@ -2055,6 +2068,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const delete_word_left_meta = .{ .description = "Delete previous word" };
pub fn delete_word_right(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
@ -2062,6 +2076,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const delete_word_right_meta = .{ .description = "Delete next word" };
pub fn delete_to_begin(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
@ -2069,6 +2084,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const delete_to_begin_meta = .{ .description = "Delete to beginning of line" };
pub fn delete_to_end(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
@ -2076,6 +2092,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const delete_to_end_meta = .{ .description = "Delete to end of line" };
pub fn join_next_line(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
@ -2084,18 +2101,21 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const join_next_line_meta = .{ .description = "Join next line" };
pub fn move_left(self: *Self, _: Context) Result {
const root = try self.buf_root();
self.with_cursors_const(root, move_cursor_left) catch {};
self.clamp();
}
pub const move_left_meta = .{ .description = "Move cursor left" };
pub fn move_right(self: *Self, _: Context) Result {
const root = try self.buf_root();
self.with_cursors_const(root, move_cursor_right) catch {};
self.clamp();
}
pub const move_right_meta = .{ .description = "Move cursor right" };
fn move_cursor_left_vim(root: Buffer.Root, cursor: *Cursor, plane: Plane) error{Stop}!void {
move_cursor_left_unless(root, cursor, is_eol_left, plane);
@ -2110,12 +2130,14 @@ pub const Editor = struct {
self.with_cursors_const(root, move_cursor_left_vim) catch {};
self.clamp();
}
pub const move_left_vim_meta = .{ .description = "Move cursor left (vim)" };
pub fn move_right_vim(self: *Self, _: Context) Result {
const root = try self.buf_root();
self.with_cursors_const(root, move_cursor_right_vim) catch {};
self.clamp();
}
pub const move_right_vim_meta = .{ .description = "Move cursor right (vim)" };
fn move_cursor_word_begin(root: Buffer.Root, cursor: *Cursor, plane: Plane) error{Stop}!void {
if (is_non_word_char_at_cursor(root, cursor, plane)) {
@ -2181,18 +2203,21 @@ pub const Editor = struct {
self.with_cursors_const(root, move_cursor_word_left) catch {};
self.clamp();
}
pub const move_word_left_meta = .{ .description = "Move cursor left by word" };
pub fn move_word_right(self: *Self, _: Context) Result {
const root = try self.buf_root();
self.with_cursors_const(root, move_cursor_word_right) catch {};
self.clamp();
}
pub const move_word_right_meta = .{ .description = "Move cursor right by word" };
pub fn move_word_right_vim(self: *Self, _: Context) Result {
const root = try self.buf_root();
self.with_cursors_const(root, move_cursor_word_right_vim) catch {};
self.clamp();
}
pub const move_word_right_vim_meta = .{ .description = "Move cursor right by word (vim)" };
fn move_cursor_to_char_left(root: Buffer.Root, cursor: *Cursor, ctx: Context, plane: Plane) error{Stop}!void {
var egc: []const u8 = undefined;
@ -2229,18 +2254,21 @@ pub const Editor = struct {
self.with_cursors_const_arg(root, move_cursor_to_char_left, ctx) catch {};
self.clamp();
}
pub const move_to_char_left_meta = .{ .interactive = false };
pub fn move_to_char_right(self: *Self, ctx: Context) Result {
const root = try self.buf_root();
self.with_cursors_const_arg(root, move_cursor_to_char_right, ctx) catch {};
self.clamp();
}
pub const move_to_char_right_meta = .{ .interactive = false };
pub fn move_up(self: *Self, _: Context) Result {
const root = try self.buf_root();
self.with_cursors_const(root, move_cursor_up) catch {};
self.clamp();
}
pub const move_up_meta = .{ .description = "Move cursor up" };
pub fn add_cursor_up(self: *Self, _: Context) Result {
try self.push_cursor();
@ -2249,12 +2277,14 @@ pub const Editor = struct {
move_cursor_up(root, &primary.cursor, self.plane) catch {};
self.clamp();
}
pub const add_cursor_up_meta = .{ .description = "Add cursor up" };
pub fn move_down(self: *Self, _: Context) Result {
const root = try self.buf_root();
self.with_cursors_const(root, move_cursor_down) catch {};
self.clamp();
}
pub const move_down_meta = .{ .description = "Move cursor down" };
pub fn add_cursor_down(self: *Self, _: Context) Result {
try self.push_cursor();
@ -2263,6 +2293,7 @@ pub const Editor = struct {
move_cursor_down(root, &primary.cursor, self.plane) catch {};
self.clamp();
}
pub const add_cursor_down_meta = .{ .description = "Add cursor down" };
pub fn add_cursor_next_match(self: *Self, _: Context) Result {
try self.send_editor_jump_source();
@ -2281,6 +2312,7 @@ pub const Editor = struct {
self.clamp();
try self.send_editor_jump_destination();
}
pub const add_cursor_next_match_meta = .{ .description = "Add cursor at next highlighted match" };
pub fn add_cursor_all_matches(self: *Self, _: Context) Result {
if (self.matches.items.len == 0) return;
@ -2296,6 +2328,7 @@ pub const Editor = struct {
self.clamp();
try self.send_editor_jump_destination();
}
pub const add_cursor_all_matches_meta = .{ .description = "Add cursors to all highlighted matches" };
fn add_cursors_to_cursel_line_ends(self: *Self, root: Buffer.Root, cursel: *CurSel) !void {
var sel = cursel.enable_selection();
@ -2323,6 +2356,7 @@ pub const Editor = struct {
self.collapse_cursors();
self.clamp();
}
pub const add_cursors_to_line_ends_meta = .{ .description = "Add cursors to all lines in selection" };
fn pull_cursel_up(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root {
var root = root_;
@ -2349,6 +2383,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const pull_up_meta = .{ .description = "Pull line up" };
fn pull_cursel_down(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root {
var root = root_;
@ -2375,6 +2410,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const pull_down_meta = .{ .description = "Pull line down" };
fn dupe_cursel_up(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root {
var root = root_;
@ -2396,6 +2432,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const dupe_up_meta = .{ .description = "Duplicate line or selection up/backwards" };
fn dupe_cursel_down(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root {
var root = root_;
@ -2416,6 +2453,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const dupe_down_meta = .{ .description = "Duplicate line or selection down/forwards" };
fn toggle_cursel_prefix(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root {
var root = root_;
@ -2442,11 +2480,13 @@ pub const Editor = struct {
const root = try self.with_cursels_mut(b.root, toggle_cursel_prefix, b.allocator);
try self.update_buf(root);
}
pub const toggle_prefix_meta = .{ .interactive = false };
pub fn toggle_comment(self: *Self, _: Context) Result {
const comment = if (self.syntax) |syn| syn.file_type.comment else "//";
return self.toggle_prefix(command.fmt(.{comment}));
}
pub const toggle_comment_meta = .{ .description = "Toggle comment" };
fn indent_cursor(self: *Self, root: Buffer.Root, cursor: Cursor, allocator: Allocator) error{Stop}!Buffer.Root {
const space = " ";
@ -2475,6 +2515,7 @@ pub const Editor = struct {
const root = try self.with_cursels_mut(b.root, indent_cursel, b.allocator);
try self.update_buf(root);
}
pub const indent_meta = .{ .description = "Indent current line" };
fn unindent_cursor(self: *Self, root: Buffer.Root, cursel: *CurSel, cursor: Cursor, allocator: Allocator) error{Stop}!Buffer.Root {
const saved = cursel.*;
@ -2515,6 +2556,7 @@ pub const Editor = struct {
const root = try self.with_cursels_mut(b.root, unindent_cursel, b.allocator);
try self.update_buf(root);
}
pub const unindent_meta = .{ .description = "Unindent current line" };
pub fn move_scroll_up(self: *Self, _: Context) Result {
const root = try self.buf_root();
@ -2522,6 +2564,7 @@ pub const Editor = struct {
self.view.move_up() catch {};
self.clamp();
}
pub const move_scroll_up_meta = .{ .description = "Move and scroll up" };
pub fn move_scroll_down(self: *Self, _: Context) Result {
const root = try self.buf_root();
@ -2529,14 +2572,17 @@ pub const Editor = struct {
self.view.move_down(root) catch {};
self.clamp();
}
pub const move_scroll_down_meta = .{ .description = "Move and scroll down" };
pub fn move_scroll_left(self: *Self, _: Context) Result {
self.view.move_left() catch {};
}
pub const move_scroll_left_meta = .{ .description = "Scroll left" };
pub fn move_scroll_right(self: *Self, _: Context) Result {
self.view.move_right() catch {};
}
pub const move_scroll_right_meta = .{ .description = "Scroll right" };
pub fn move_scroll_page_up(self: *Self, _: Context) Result {
if (self.screen_cursor(&self.get_primary().cursor)) |cursor| {
@ -2548,6 +2594,7 @@ pub const Editor = struct {
return self.move_page_up(.{});
}
}
pub const move_scroll_page_up_meta = .{ .description = "Move and scroll page up" };
pub fn move_scroll_page_down(self: *Self, _: Context) Result {
if (self.screen_cursor(&self.get_primary().cursor)) |cursor| {
@ -2559,24 +2606,28 @@ pub const Editor = struct {
return self.move_page_down(.{});
}
}
pub const move_scroll_page_down_meta = .{ .description = "Move and scroll page down" };
pub fn smart_move_begin(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_cursors_const(root, smart_move_cursor_begin);
self.clamp();
}
pub const smart_move_begin_meta = .{ .description = "Move cursor to beginning of line (smart)" };
pub fn move_begin(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_cursors_const(root, move_cursor_begin);
self.clamp();
}
pub const move_begin_meta = .{ .description = "Move cursor to beginning of line" };
pub fn move_end(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_cursors_const(root, move_cursor_end);
self.clamp();
}
pub const move_end_meta = .{ .description = "Move cursor to end of line" };
pub fn move_page_up(self: *Self, _: Context) Result {
try self.send_editor_jump_source();
@ -2584,6 +2635,7 @@ pub const Editor = struct {
try self.with_cursors_and_view_const(root, move_cursor_page_up, &self.view);
self.clamp();
}
pub const move_page_up_meta = .{ .description = "Move cursor page up" };
pub fn move_page_down(self: *Self, _: Context) Result {
try self.send_editor_jump_source();
@ -2592,6 +2644,7 @@ pub const Editor = struct {
self.clamp();
try self.send_editor_jump_destination();
}
pub const move_page_down_meta = .{ .description = "Move cursor page down" };
pub fn move_buffer_begin(self: *Self, _: Context) Result {
try self.send_editor_jump_source();
@ -2600,6 +2653,7 @@ pub const Editor = struct {
self.clamp();
try self.send_editor_jump_destination();
}
pub const move_buffer_begin_meta = .{ .description = "Move cursor to start of file" };
pub fn move_buffer_end(self: *Self, _: Context) Result {
try self.send_editor_jump_source();
@ -2609,23 +2663,27 @@ pub const Editor = struct {
self.clamp();
try self.send_editor_jump_destination();
}
pub const move_buffer_end_meta = .{ .description = "Move cursor to end of file" };
pub fn cancel(self: *Self, _: Context) Result {
self.cancel_all_selections();
self.cancel_all_matches();
}
pub const cancel_meta = .{ .description = "Cancel current action" };
pub fn select_up(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_up);
self.clamp();
}
pub const select_up_meta = .{ .description = "Select up" };
pub fn select_down(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_down);
self.clamp();
}
pub const select_down_meta = .{ .description = "Select down" };
pub fn select_scroll_up(self: *Self, _: Context) Result {
const root = try self.buf_root();
@ -2633,6 +2691,7 @@ pub const Editor = struct {
self.view.move_up() catch {};
self.clamp();
}
pub const select_scroll_up_meta = .{ .description = "Select and scroll up" };
pub fn select_scroll_down(self: *Self, _: Context) Result {
const root = try self.buf_root();
@ -2640,72 +2699,84 @@ pub const Editor = struct {
self.view.move_down(root) catch {};
self.clamp();
}
pub const select_scroll_down_meta = .{ .description = "Select and scroll down" };
pub fn select_left(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_left);
self.clamp();
}
pub const select_left_meta = .{ .description = "Select left" };
pub fn select_right(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_right);
self.clamp();
}
pub const select_right_meta = .{ .description = "Select right" };
pub fn select_word_left(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_word_left);
self.clamp();
}
pub const select_word_left_meta = .{ .description = "Select left by word" };
pub fn select_word_right(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_word_right);
self.clamp();
}
pub const select_word_right_meta = .{ .description = "Select right by word" };
pub fn select_word_begin(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_word_begin);
self.clamp();
}
pub const select_word_begin_meta = .{ .description = "Select to beginning of word" };
pub fn select_word_end(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_word_end);
self.clamp();
}
pub const select_word_end_meta = .{ .description = "Select to end of word" };
pub fn select_to_char_left(self: *Self, ctx: Context) Result {
const root = try self.buf_root();
self.with_selections_const_arg(root, move_cursor_to_char_left, ctx) catch {};
self.clamp();
}
pub const select_to_char_left_meta = .{ .interactive = false };
pub fn select_to_char_right(self: *Self, ctx: Context) Result {
const root = try self.buf_root();
self.with_selections_const_arg(root, move_cursor_to_char_right, ctx) catch {};
self.clamp();
}
pub const select_to_char_right_meta = .{ .interactive = false };
pub fn select_begin(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_begin);
self.clamp();
}
pub const select_begin_meta = .{ .description = "Select to beginning of line" };
pub fn smart_select_begin(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, smart_move_cursor_begin);
self.clamp();
}
pub const smart_select_begin_meta = .{ .description = "Select to beginning of line (smart)" };
pub fn select_end(self: *Self, _: Context) Result {
const root = try self.buf_root();
try self.with_selections_const(root, move_cursor_end);
self.clamp();
}
pub const select_end_meta = .{ .description = "Select to end of line" };
pub fn select_buffer_begin(self: *Self, _: Context) Result {
try self.send_editor_jump_source();
@ -2714,6 +2785,7 @@ pub const Editor = struct {
self.clamp();
try self.send_editor_jump_destination();
}
pub const select_buffer_begin_meta = .{ .description = "Select to start of file" };
pub fn select_buffer_end(self: *Self, _: Context) Result {
try self.send_editor_jump_source();
@ -2722,6 +2794,7 @@ pub const Editor = struct {
self.clamp();
try self.send_editor_jump_destination();
}
pub const select_buffer_end_meta = .{ .description = "Select to end of file" };
pub fn select_page_up(self: *Self, _: Context) Result {
try self.send_editor_jump_source();
@ -2730,6 +2803,7 @@ pub const Editor = struct {
self.clamp();
try self.send_editor_jump_destination();
}
pub const select_page_up_meta = .{ .description = "Select page up" };
pub fn select_page_down(self: *Self, _: Context) Result {
try self.send_editor_jump_source();
@ -2738,6 +2812,7 @@ pub const Editor = struct {
self.clamp();
try self.send_editor_jump_destination();
}
pub const select_page_down_meta = .{ .description = "Select page down" };
pub fn select_all(self: *Self, _: Context) Result {
try self.send_editor_jump_source();
@ -2750,6 +2825,7 @@ pub const Editor = struct {
self.clamp();
try self.send_editor_jump_destination();
}
pub const select_all_meta = .{ .description = "Select all" };
fn select_word_at_cursor(self: *Self, cursel: *CurSel) !*Selection {
const root = try self.buf_root();
@ -2783,6 +2859,7 @@ pub const Editor = struct {
try self.with_cursels_const(root, selection_reverse);
self.clamp();
}
pub const selections_reverse_meta = .{ .description = "Reverse selection" };
pub fn insert_chars(self: *Self, ctx: Context) Result {
var chars: []const u8 = undefined;
@ -2796,6 +2873,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const insert_chars_meta = .{ .interactive = false };
pub fn insert_line(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
@ -2806,6 +2884,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const insert_line_meta = .{ .description = "Insert line" };
pub fn smart_insert_line(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
@ -2825,6 +2904,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const smart_insert_line_meta = .{ .description = "Insert line (smart)" };
pub fn insert_line_before(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
@ -2837,6 +2917,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const insert_line_before_meta = .{ .description = "Insert line before" };
pub fn smart_insert_line_before(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
@ -2859,6 +2940,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const smart_insert_line_before_meta = .{ .description = "Insert line before (smart)" };
pub fn insert_line_after(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
@ -2870,6 +2952,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const insert_line_after_meta = .{ .description = "Insert line after" };
pub fn smart_insert_line_after(self: *Self, _: Context) Result {
const b = try self.buf_for_update();
@ -2891,24 +2974,29 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const smart_insert_line_after_meta = .{ .description = "Insert line after (smart)" };
pub fn enable_fast_scroll(self: *Self, _: Context) Result {
self.fast_scroll = true;
}
pub const enable_fast_scroll_meta = .{ .description = "Enable fast scroll mode" };
pub fn disable_fast_scroll(self: *Self, _: Context) Result {
self.fast_scroll = false;
}
pub const disable_fast_scroll_meta = .{ .interactive = false };
pub fn enable_jump_mode(self: *Self, _: Context) Result {
self.jump_mode = true;
tui.current().rdr.request_mouse_cursor_pointer(true);
}
pub const enable_jump_mode_meta = .{ .description = "Enable jump/hover mode" };
pub fn disable_jump_mode(self: *Self, _: Context) Result {
self.jump_mode = false;
tui.current().rdr.request_mouse_cursor_text(true);
}
pub const disable_jump_mode_meta = .{ .interactive = false };
fn update_syntax(self: *Self) !void {
const frame = tracy.initZone(@src(), .{ .name = "editor update syntax" });
@ -2957,6 +3045,7 @@ pub const Editor = struct {
return self.logger.print("line {d}: {any}", .{ primary.cursor.row, e });
self.logger.print("line {d}:{s}", .{ primary.cursor.row, std.fmt.fmtSliceEscapeLower(tree.items) });
}
pub const dump_current_line_meta = .{ .description = "Debug: dump current line" };
pub fn dump_current_line_tree(self: *Self, _: Context) Result {
const root = self.buf_root() catch return;
@ -2967,16 +3056,19 @@ pub const Editor = struct {
return self.logger.print("line {d} ast: {any}", .{ primary.cursor.row, e });
self.logger.print("line {d} ast:{s}", .{ primary.cursor.row, std.fmt.fmtSliceEscapeLower(tree.items) });
}
pub const dump_current_line_tree_meta = .{ .description = "Debug: dump current line (tree)" };
pub fn undo(self: *Self, _: Context) Result {
try self.restore_undo();
self.clamp();
}
pub const undo_meta = .{ .description = "Undo" };
pub fn redo(self: *Self, _: Context) Result {
try self.restore_redo();
self.clamp();
}
pub const redo_meta = .{ .description = "Redo" };
pub fn open_buffer_from_file(self: *Self, ctx: Context) Result {
var file_path: []const u8 = undefined;
@ -2985,6 +3077,7 @@ pub const Editor = struct {
self.clamp();
} else return error.InvalidArgument;
}
pub const open_buffer_from_file_meta = .{ .interactive = false };
pub fn open_scratch_buffer(self: *Self, ctx: Context) Result {
var file_path: []const u8 = undefined;
@ -2994,6 +3087,7 @@ pub const Editor = struct {
self.clamp();
} else return error.InvalidArgument;
}
pub const open_scratch_buffer_meta = .{ .interactive = false };
pub fn save_file(self: *Self, _: Context) Result {
if (tui.current().config.enable_format_on_save) if (self.get_formatter()) |_| {
@ -3007,6 +3101,7 @@ pub const Editor = struct {
};
try self.save();
}
pub const save_file_meta = .{ .description = "Save file" };
pub fn save_file_as(self: *Self, ctx: Context) Result {
var file_path: []const u8 = undefined;
@ -3014,16 +3109,19 @@ pub const Editor = struct {
try self.save_as(file_path);
} else return error.InvalidArgument;
}
pub const save_file_as_meta = .{ .interactive = false };
pub fn close_file(self: *Self, _: Context) Result {
self.cancel_all_selections();
try self.close();
}
pub const close_file_meta = .{ .description = "Close file" };
pub fn close_file_without_saving(self: *Self, _: Context) Result {
self.cancel_all_selections();
try self.close_dirty();
}
pub const close_file_without_saving_meta = .{ .description = "Close file without saving" };
pub fn find_query(self: *Self, ctx: Context) Result {
var query: []const u8 = undefined;
@ -3032,6 +3130,7 @@ pub const Editor = struct {
self.clamp();
} else return error.InvalidArgument;
}
pub const find_query_meta = .{ .interactive = false };
fn find_in(self: *Self, query: []const u8, comptime find_f: ripgrep.FindF, write_buffer: bool) !void {
const root = try self.buf_root();
@ -3290,6 +3389,7 @@ pub const Editor = struct {
self.clamp();
}
}
pub const move_cursor_next_match_meta = .{ .description = "Move cursor to next hightlighted match" };
pub fn goto_next_match(self: *Self, ctx: Context) Result {
try self.send_editor_jump_source();
@ -3303,6 +3403,7 @@ pub const Editor = struct {
try self.move_cursor_next_match(ctx);
try self.send_editor_jump_destination();
}
pub const goto_next_match_meta = .{ .description = "Goto to next hightlighted match" };
pub fn move_cursor_prev_match(self: *Self, _: Context) Result {
const primary = self.get_primary();
@ -3317,6 +3418,7 @@ pub const Editor = struct {
self.clamp();
}
}
pub const move_cursor_prev_match_meta = .{ .description = "Move cursor to previous hightlighted match" };
pub fn goto_prev_match(self: *Self, ctx: Context) Result {
try self.send_editor_jump_source();
@ -3330,6 +3432,7 @@ pub const Editor = struct {
try self.move_cursor_prev_match(ctx);
try self.send_editor_jump_destination();
}
pub const goto_prev_match_meta = .{ .description = "Goto to previous hightlighted match" };
pub fn goto_next_diagnostic(self: *Self, _: Context) Result {
if (self.diagnostics.items.len == 0) {
@ -3345,6 +3448,7 @@ pub const Editor = struct {
}
return self.goto_diagnostic(&self.diagnostics.items[0]);
}
pub const goto_next_diagnostic_meta = .{ .description = "Goto to next diagnostic" };
pub fn goto_prev_diagnostic(self: *Self, _: Context) Result {
if (self.diagnostics.items.len == 0) {
@ -3362,6 +3466,7 @@ pub const Editor = struct {
if (i == 0) return self.goto_diagnostic(&self.diagnostics.items[self.diagnostics.items.len - 1]);
}
}
pub const goto_prev_diagnostic_meta = .{ .description = "Goto to previous diagnostic" };
fn goto_diagnostic(self: *Self, diag: *const Diagnostic) !void {
const root = self.buf_root() catch return;
@ -3397,6 +3502,7 @@ pub const Editor = struct {
self.clamp();
try self.send_editor_jump_destination();
}
pub const goto_line_meta = .{ .interactive = false };
pub fn goto_column(self: *Self, ctx: Context) Result {
var column: usize = 0;
@ -3407,6 +3513,7 @@ pub const Editor = struct {
try primary.cursor.move_to(root, primary.cursor.row, @intCast(if (column < 1) 0 else column - 1), self.plane.metrics());
self.clamp();
}
pub const goto_column_meta = .{ .interactive = false };
pub fn goto_line_and_column(self: *Self, ctx: Context) Result {
try self.send_editor_jump_source();
@ -3447,47 +3554,55 @@ pub const Editor = struct {
try self.send_editor_jump_destination();
self.need_render();
}
pub const goto_line_and_column_meta = .{ .interactive = false };
pub fn goto_definition(self: *Self, _: Context) Result {
const file_path = self.file_path orelse return;
const primary = self.get_primary();
return project_manager.goto_definition(file_path, primary.cursor.row, primary.cursor.col);
}
pub const goto_definition_meta = .{ .description = "Language: Goto definition" };
pub fn goto_declaration(self: *Self, _: Context) Result {
const file_path = self.file_path orelse return;
const primary = self.get_primary();
return project_manager.goto_declaration(file_path, primary.cursor.row, primary.cursor.col);
}
pub const goto_declaration_meta = .{ .description = "Language: Goto declaration" };
pub fn goto_implementation(self: *Self, _: Context) Result {
const file_path = self.file_path orelse return;
const primary = self.get_primary();
return project_manager.goto_implementation(file_path, primary.cursor.row, primary.cursor.col);
}
pub const goto_implementation_meta = .{ .description = "Language: Goto implementation" };
pub fn goto_type_definition(self: *Self, _: Context) Result {
const file_path = self.file_path orelse return;
const primary = self.get_primary();
return project_manager.goto_type_definition(file_path, primary.cursor.row, primary.cursor.col);
}
pub const goto_type_definition_meta = .{ .description = "Language: Goto type definition" };
pub fn references(self: *Self, _: Context) Result {
const file_path = self.file_path orelse return;
const primary = self.get_primary();
return project_manager.references(file_path, primary.cursor.row, primary.cursor.col);
}
pub const references_meta = .{ .description = "Language: Find all references" };
pub fn completion(self: *Self, _: Context) Result {
const file_path = self.file_path orelse return;
const primary = self.get_primary();
return project_manager.completion(file_path, primary.cursor.row, primary.cursor.col);
}
pub const completion_meta = .{ .description = "Language: Show completions at cursor" };
pub fn hover(self: *Self, _: Context) Result {
const primary = self.get_primary();
return self.hover_at(primary.cursor.row, primary.cursor.col);
}
pub const hover_meta = .{ .description = "Language: Show documentation for symbol (hover)" };
pub fn hover_at_abs(self: *Self, y: usize, x: usize) Result {
const row: usize = self.view.row + y;
@ -3545,6 +3660,7 @@ pub const Editor = struct {
return error.InvalidArgument;
self.get_primary().selection = sel;
}
pub const select_meta = .{ .interactive = false };
fn get_formatter(self: *Self) ?[]const []const u8 {
if (self.syntax) |syn| if (syn.file_type.formatter) |fmtr| if (fmtr.len > 0) return fmtr;
@ -3566,12 +3682,14 @@ pub const Editor = struct {
}
return tp.exit("no formatter");
}
pub const format_meta = .{ .description = "Language: Format file or selection" };
pub fn filter(self: *Self, ctx: Context) Result {
if (!try ctx.args.match(.{ tp.string, tp.more }))
return error.InvalidArgument;
try self.filter_cmd(ctx.args);
}
pub const filter_meta = .{ .interactive = false };
fn filter_cmd(self: *Self, cmd: tp.message) !void {
if (self.filter) |_| return error.Stop;
@ -3695,6 +3813,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const to_upper_meta = .{ .description = "Convert selection or word to upper case" };
fn to_lower_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root {
var root = root_;
@ -3724,6 +3843,7 @@ pub const Editor = struct {
try self.update_buf(root);
self.clamp();
}
pub const to_lower_meta = .{ .description = "Convert selection or word to lower case" };
};
pub fn create(allocator: Allocator, parent: Widget) !Widget {