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 {

View file

@ -270,22 +270,27 @@ const cmds = struct {
self.select_next(.up);
self.menu.activate_selected();
}
pub const goto_prev_file_meta = .{ .description = "Navigate to previous file in the file list" };
pub fn goto_next_file(self: *Self, _: Ctx) Result {
self.select_next(.down);
self.menu.activate_selected();
}
pub const goto_next_file_meta = .{ .description = "Navigate to next file in the file list" };
pub fn select_prev_file(self: *Self, _: Ctx) Result {
self.select_next(.up);
}
pub const select_prev_file_meta = .{ .description = "Select previous file in the file list" };
pub fn select_next_file(self: *Self, _: Ctx) Result {
self.select_next(.down);
}
pub const select_next_file_meta = .{ .description = "Select next file in the file list" };
pub fn goto_selected_file(self: *Self, _: Ctx) Result {
if (self.menu.selected == null) return tp.exit_error(error.NoSelectedFile, @errorReturnTrace());
self.menu.activate_selected();
}
pub const goto_selected_file_meta = .{ .interactive = false };
};

View file

@ -196,14 +196,17 @@ const cmds = struct {
pub fn home_menu_down(self: *Self, _: Ctx) Result {
self.menu.select_down();
}
pub const home_menu_down_meta = .{ .interactive = false };
pub fn home_menu_up(self: *Self, _: Ctx) Result {
self.menu.select_up();
}
pub const home_menu_up_meta = .{ .interactive = false };
pub fn home_menu_activate(self: *Self, _: Ctx) Result {
self.menu.activate_selected();
}
pub const home_menu_activate_meta = .{ .interactive = false };
pub fn home_sheeran(self: *Self, _: Ctx) Result {
self.fire = if (self.fire) |*fire| ret: {
@ -211,6 +214,7 @@ const cmds = struct {
break :ret null;
} else try Fire.init(self.allocator, self.plane);
}
pub const home_sheeran_meta = .{ .interactive = false };
};
const Fire = struct {

View file

@ -221,16 +221,19 @@ const cmds = struct {
return tp.exit("unsaved changes");
try tp.self_pid().send("quit");
}
pub const quit_meta = .{ .description = "Quit (exit) Flow Control" };
pub fn quit_without_saving(_: *Self, _: Ctx) Result {
try tp.self_pid().send("quit");
}
pub const quit_without_saving_meta = .{ .description = "Quit without saving" };
pub fn open_project_cwd(self: *Self, _: Ctx) Result {
try project_manager.open(".");
if (self.top_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" });
if (self.bottom_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" });
}
pub const open_project_cwd_meta = .{ .interactive = false };
pub fn open_project_dir(self: *Self, ctx: Ctx) Result {
var project_dir: []const u8 = undefined;
@ -242,6 +245,7 @@ const cmds = struct {
if (self.top_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" });
if (self.bottom_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" });
}
pub const open_project_dir_meta = .{ .interactive = false };
pub fn change_project(self: *Self, ctx: Ctx) Result {
var project_dir: []const u8 = undefined;
@ -269,6 +273,7 @@ const cmds = struct {
try tp.self_pid().send(.{ "cmd", "navigate", .{ .file = file_path } });
}
}
pub const change_project_meta = .{ .interactive = false };
pub fn navigate(self: *Self, ctx: Ctx) Result {
tui.reset_drag_context();
@ -339,6 +344,7 @@ const cmds = struct {
}
tui.need_render();
}
pub const navigate_meta = .{ .interactive = false };
pub fn open_help(self: *Self, _: Ctx) Result {
tui.reset_drag_context();
@ -346,17 +352,20 @@ const cmds = struct {
try command.executeName("open_scratch_buffer", command.fmt(.{ "help.md", @embedFile("help.md") }));
tui.need_render();
}
pub const open_help_meta = .{ .description = "Open help" };
pub fn open_config(_: *Self, _: Ctx) Result {
const file_name = try root.get_config_file_name();
try tp.self_pid().send(.{ "cmd", "navigate", .{ .file = file_name } });
}
pub const open_config_meta = .{ .description = "Edit configuration file" };
pub fn restore_session(self: *Self, _: Ctx) Result {
try self.create_editor();
try self.read_restore_info();
tui.need_render();
}
pub const restore_session_meta = .{ .interactive = false };
pub fn toggle_panel(self: *Self, _: Ctx) Result {
if (self.is_panel_view_showing(logview))
@ -368,38 +377,47 @@ const cmds = struct {
else
try self.toggle_panel_view(logview, false);
}
pub const toggle_panel_meta = .{ .description = "Toggle panel" };
pub fn toggle_logview(self: *Self, _: Ctx) Result {
try self.toggle_panel_view(logview, false);
}
pub const toggle_logview_meta = .{ .interactive = false };
pub fn show_logview(self: *Self, _: Ctx) Result {
try self.toggle_panel_view(logview, true);
}
pub const show_logview_meta = .{ .description = "View log" };
pub fn toggle_inputview(self: *Self, _: Ctx) Result {
try self.toggle_panel_view(@import("inputview.zig"), false);
}
pub const toggle_inputview_meta = .{ .description = "Toggle raw input log" };
pub fn toggle_inspector_view(self: *Self, _: Ctx) Result {
try self.toggle_panel_view(@import("inspector_view.zig"), false);
}
pub const toggle_inspector_view_meta = .{ .description = "Toggle inspector view" };
pub fn show_inspector_view(self: *Self, _: Ctx) Result {
try self.toggle_panel_view(@import("inspector_view.zig"), true);
}
pub const show_inspector_view_meta = .{ .interactive = false };
pub fn jump_back(self: *Self, _: Ctx) Result {
try self.location_history.back(location_jump);
}
pub const jump_back_meta = .{ .description = "Navigate back to previous history location" };
pub fn jump_forward(self: *Self, _: Ctx) Result {
try self.location_history.forward(location_jump);
}
pub const jump_forward_meta = .{ .description = "Navigate forward to next history location" };
pub fn show_home(self: *Self, _: Ctx) Result {
return self.create_home();
}
pub const show_home_meta = .{ .interactive = false };
pub fn gutter_mode_next(self: *Self, _: Ctx) Result {
const tui_ = tui.current();
@ -424,6 +442,7 @@ const cmds = struct {
gutter.relative = lnr;
}
}
pub const gutter_mode_next_meta = .{ .description = "Next gutter mode" };
pub fn goto_next_file_or_diagnostic(self: *Self, ctx: Ctx) Result {
if (self.is_panel_view_showing(filelist_view)) {
@ -435,6 +454,7 @@ const cmds = struct {
try command.executeName("goto_next_diagnostic", ctx);
}
}
pub const goto_next_file_or_diagnostic_meta = .{ .description = "Navigate to next file or diagnostic location" };
pub fn goto_prev_file_or_diagnostic(self: *Self, ctx: Ctx) Result {
if (self.is_panel_view_showing(filelist_view)) {
@ -446,6 +466,7 @@ const cmds = struct {
try command.executeName("goto_prev_diagnostic", ctx);
}
}
pub const goto_prev_file_or_diagnostic_meta = .{ .description = "Navigate to previous file or diagnostic location" };
pub fn add_diagnostic(self: *Self, ctx: Ctx) Result {
var file_path: []const u8 = undefined;
@ -480,6 +501,7 @@ const cmds = struct {
ed.Diagnostic.to_severity(severity),
);
}
pub const add_diagnostic_meta = .{ .interactive = false };
pub fn clear_diagnostics(self: *Self, ctx: Ctx) Result {
var file_path: []const u8 = undefined;
@ -492,6 +514,7 @@ const cmds = struct {
if (self.file_list_type == .diagnostics and self.is_panel_view_showing(filelist_view))
try self.toggle_panel_view(filelist_view, false);
}
pub const clear_diagnostics_meta = .{ .interactive = false };
pub fn show_diagnostics(self: *Self, _: Ctx) Result {
const editor = self.editor orelse return;
@ -509,6 +532,7 @@ const cmds = struct {
);
}
}
pub const show_diagnostics_meta = .{ .description = "Show diagnostics panel" };
};
pub fn handle_editor_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result {

View file

@ -310,22 +310,27 @@ const cmds_ = struct {
pub fn w(self: *Self, _: Ctx) Result {
try self.cmd("save_file", .{});
}
pub const w_meta = .{ .description = "w (write file)" };
pub fn q(self: *Self, _: Ctx) Result {
try self.cmd("quit", .{});
}
pub const q_meta = .{ .description = "w (quit)" };
pub fn @"q!"(self: *Self, _: Ctx) Result {
try self.cmd("quit_without_saving", .{});
}
pub const @"q!_meta" = .{ .description = "q! (quit without saving)" };
pub fn wq(self: *Self, _: Ctx) Result {
try self.cmd("save_file", .{});
try self.cmd("quit", .{});
}
pub const wq_meta = .{ .description = "wq (write file and quit)" };
pub fn @"wq!"(self: *Self, _: Ctx) Result {
self.cmd("save_file", .{}) catch {};
try self.cmd("quit_without_saving", .{});
}
pub const @"wq!_meta" = .{ .description = "wq! (write file and quit without saving)" };
};

View file

@ -662,26 +662,32 @@ const cmds_ = struct {
pub fn w(self: *Self, _: Ctx) Result {
try self.cmd("save_file", .{});
}
pub const w_meta = .{ .description = "w (write file)" };
pub fn q(self: *Self, _: Ctx) Result {
try self.cmd("quit", .{});
}
pub const q_meta = .{ .description = "w (quit)" };
pub fn @"q!"(self: *Self, _: Ctx) Result {
try self.cmd("quit_without_saving", .{});
}
pub const @"q!_meta" = .{ .description = "q! (quit without saving)" };
pub fn wq(self: *Self, _: Ctx) Result {
try self.cmd("save_file", .{});
try self.cmd("quit", .{});
}
pub const wq_meta = .{ .description = "wq (write file and quit)" };
pub fn o(self: *Self, _: Ctx) Result {
try self.cmd("open_file", .{});
}
pub const o_meta = .{ .description = "o (open file)" };
pub fn @"wq!"(self: *Self, _: Ctx) Result {
self.cmd("save_file", .{}) catch {};
try self.cmd("quit_without_saving", .{});
}
pub const @"wq!_meta" = .{ .description = "wq! (write file and quit without saving)" };
};

View file

@ -662,26 +662,32 @@ const cmds_ = struct {
pub fn w(self: *Self, _: Ctx) Result {
try self.cmd("save_file", .{});
}
pub const w_meta = .{ .description = "w (write file)" };
pub fn q(self: *Self, _: Ctx) Result {
try self.cmd("quit", .{});
}
pub const q_meta = .{ .description = "w (quit)" };
pub fn @"q!"(self: *Self, _: Ctx) Result {
try self.cmd("quit_without_saving", .{});
}
pub const @"q!_meta" = .{ .description = "q! (quit without saving)" };
pub fn wq(self: *Self, _: Ctx) Result {
try self.cmd("save_file", .{});
try self.cmd("quit", .{});
}
pub const wq_meta = .{ .description = "wq (write file and quit)" };
pub fn o(self: *Self, _: Ctx) Result {
try self.cmd("open_file", .{});
}
pub const o_meta = .{ .description = "o (open file)" };
pub fn @"wq!"(self: *Self, _: Ctx) Result {
self.cmd("save_file", .{}) catch {};
try self.cmd("quit_without_saving", .{});
}
pub const @"wq!_meta" = .{ .description = "wq! (write file and quit without saving)" };
};

View file

@ -310,22 +310,27 @@ const cmds_ = struct {
pub fn w(self: *Self, _: Ctx) Result {
try self.cmd("save_file", .{});
}
pub const w_meta = .{ .description = "w (write file)" };
pub fn q(self: *Self, _: Ctx) Result {
try self.cmd("quit", .{});
}
pub const q_meta = .{ .description = "w (quit)" };
pub fn @"q!"(self: *Self, _: Ctx) Result {
try self.cmd("quit_without_saving", .{});
}
pub const @"q!_meta" = .{ .description = "q! (quit without saving)" };
pub fn wq(self: *Self, _: Ctx) Result {
try self.cmd("save_file", .{});
try self.cmd("quit", .{});
}
pub const wq_meta = .{ .description = "wq (write file and quit)" };
pub fn @"wq!"(self: *Self, _: Ctx) Result {
self.cmd("save_file", .{}) catch {};
try self.cmd("quit_without_saving", .{});
}
pub const @"wq!_meta" = .{ .description = "wq! (write file and quit without saving)" };
};

View file

@ -626,22 +626,27 @@ const cmds_ = struct {
pub fn w(self: *Self, _: Ctx) Result {
try self.cmd("save_file", .{});
}
pub const w_meta = .{ .description = "w (write file)" };
pub fn q(self: *Self, _: Ctx) Result {
try self.cmd("quit", .{});
}
pub const q_meta = .{ .description = "w (quit)" };
pub fn @"q!"(self: *Self, _: Ctx) Result {
try self.cmd("quit_without_saving", .{});
}
pub const @"q!_meta" = .{ .description = "q! (quit without saving)" };
pub fn wq(self: *Self, _: Ctx) Result {
try self.cmd("save_file", .{});
try self.cmd("quit", .{});
}
pub const wq_meta = .{ .description = "wq (write file and quit)" };
pub fn @"wq!"(self: *Self, _: Ctx) Result {
self.cmd("save_file", .{}) catch {};
try self.cmd("quit_without_saving", .{});
}
pub const @"wq!_meta" = .{ .description = "wq! (write file and quit without saving)" };
};

View file

@ -572,25 +572,30 @@ const cmds_ = struct {
const Ctx = command.Context;
const Result = command.Result;
pub fn @"w"(self: *Self, _: Ctx) Result {
pub fn w(self: *Self, _: Ctx) Result {
try self.cmd("save_file", .{});
}
pub const w_meta = .{ .description = "w (write file)" };
pub fn @"q"(self: *Self, _: Ctx) Result {
pub fn q(self: *Self, _: Ctx) Result {
try self.cmd("quit", .{});
}
pub const q_meta = .{ .description = "w (quit)" };
pub fn @"q!"(self: *Self, _: Ctx) Result {
try self.cmd("quit_without_saving", .{});
}
pub const @"q!_meta" = .{ .description = "q! (quit without saving)" };
pub fn @"wq"(self: *Self, _: Ctx) Result {
pub fn wq(self: *Self, _: Ctx) Result {
try self.cmd("save_file", .{});
try self.cmd("quit", .{});
}
pub const wq_meta = .{ .description = "wq (write file and quit)" };
pub fn @"wq!"(self: *Self, _: Ctx) Result {
self.cmd("save_file", .{}) catch {};
try self.cmd("quit_without_saving", .{});
}
pub const @"wq!_meta" = .{ .description = "wq! (write file and quit without saving)" };
};

View file

@ -342,12 +342,15 @@ const cmds = struct {
pub fn open_recent_menu_down(self: *Self, _: Ctx) Result {
self.menu.select_down();
}
pub const open_recent_menu_down_meta = .{ .interactive = false };
pub fn open_recent_menu_up(self: *Self, _: Ctx) Result {
self.menu.select_up();
}
pub const open_recent_menu_up_meta = .{ .interactive = false };
pub fn open_recent_menu_activate(self: *Self, _: Ctx) Result {
self.menu.activate_selected();
}
pub const open_recent_menu_activate_meta = .{ .interactive = false };
};

View file

@ -439,6 +439,7 @@ pub fn Create(options: type) type {
self.menu.select_down();
self.selection_updated();
}
pub const palette_menu_down_meta = .{ .interactive = false };
pub fn palette_menu_up(self: *Self, _: Ctx) Result {
if (self.menu.selected) |selected| {
@ -452,6 +453,7 @@ pub fn Create(options: type) type {
self.menu.select_up();
self.selection_updated();
}
pub const palette_menu_up_meta = .{ .interactive = false };
pub fn palette_menu_pagedown(self: *Self, _: Ctx) Result {
if (self.total_items > self.view_rows) {
@ -463,6 +465,7 @@ pub fn Create(options: type) type {
self.menu.select_last();
self.selection_updated();
}
pub const palette_menu_pagedown_meta = .{ .interactive = false };
pub fn palette_menu_pageup(self: *Self, _: Ctx) Result {
if (self.view_pos > self.view_rows)
@ -473,15 +476,18 @@ pub fn Create(options: type) type {
self.menu.select_first();
self.selection_updated();
}
pub const palette_menu_pageup_meta = .{ .interactive = false };
pub fn palette_menu_activate(self: *Self, _: Ctx) Result {
self.menu.activate_selected();
}
pub const palette_menu_activate_meta = .{ .interactive = false };
pub fn palette_menu_cancel(self: *Self, _: Ctx) Result {
if (@hasDecl(options, "cancel")) try options.cancel(self);
try self.cmd("exit_overlay_mode", .{});
}
pub const palette_menu_cancel_meta = .{ .interactive = false };
};
};
}

View file

@ -559,12 +559,14 @@ const cmds = struct {
pub fn restart(_: *Self, _: Ctx) Result {
try tp.self_pid().send("restart");
}
pub const restart_meta = .{ .description = "Restart flow (without saving)" };
pub fn force_terminate(self: *Self, _: Ctx) Result {
self.deinit();
root.print_exit_status({}, "FORCE TERMINATE");
root.exit(99);
}
pub const force_terminate_meta = .{ .description = "Force quit without saving" };
pub fn set_theme(self: *Self, ctx: Ctx) Result {
var name: []const u8 = undefined;
@ -579,6 +581,7 @@ const cmds = struct {
self.logger.print("theme: {s}", .{self.theme.description});
try self.save_config();
}
pub const set_theme_meta = .{ .interactive = false };
pub fn theme_next(self: *Self, _: Ctx) Result {
self.theme = get_next_theme_by_name(self.theme.name);
@ -587,6 +590,7 @@ const cmds = struct {
self.logger.print("theme: {s}", .{self.theme.description});
try self.save_config();
}
pub const theme_next_meta = .{ .description = "Switch to next color theme" };
pub fn theme_prev(self: *Self, _: Ctx) Result {
self.theme = get_prev_theme_by_name(self.theme.name);
@ -595,6 +599,7 @@ const cmds = struct {
self.logger.print("theme: {s}", .{self.theme.description});
try self.save_config();
}
pub const theme_prev_meta = .{ .description = "Switch to previous color theme" };
pub fn toggle_whitespace(self: *Self, _: Ctx) Result {
self.config.show_whitespace = !self.config.show_whitespace;
@ -604,6 +609,7 @@ const cmds = struct {
const m = try tp.message.fmtbuf(&buf, .{ "show_whitespace", self.config.show_whitespace });
_ = try self.send_widgets(tp.self_pid(), m);
}
pub const toggle_whitespace_meta = .{ .description = "Toggle visible whitespace" };
pub fn toggle_input_mode(self: *Self, _: Ctx) Result {
self.config.input_mode = if (std.mem.eql(u8, self.config.input_mode, "flow"))
@ -617,6 +623,7 @@ const cmds = struct {
self.logger.print("input mode {s}", .{it.first()});
return enter_mode(self, Ctx.fmt(.{self.config.input_mode}));
}
pub const toggle_input_mode_meta = .{ .description = "Switch to next input mode" };
pub fn enter_mode(self: *Self, ctx: Ctx) Result {
var mode: []const u8 = undefined;
@ -647,26 +654,32 @@ const cmds = struct {
};
// self.logger.print("input mode: {s}", .{(self.input_mode orelse return).description});
}
pub const enter_mode_meta = .{ .interactive = false };
pub fn enter_mode_default(self: *Self, _: Ctx) Result {
return enter_mode(self, Ctx.fmt(.{self.config.input_mode}));
}
pub const enter_mode_default_meta = .{ .interactive = false };
pub fn open_command_palette(self: *Self, _: Ctx) Result {
return self.enter_overlay_mode(@import("mode/overlay/command_palette.zig").Type);
}
pub const open_command_palette_meta = .{ .interactive = false };
pub fn open_recent(self: *Self, _: Ctx) Result {
return self.enter_overlay_mode(@import("mode/overlay/open_recent.zig"));
}
pub const open_recent_meta = .{ .description = "Open recent file" };
pub fn open_recent_project(self: *Self, _: Ctx) Result {
return self.enter_overlay_mode(@import("mode/overlay/open_recent_project.zig").Type);
}
pub const open_recent_project_meta = .{ .description = "Open recent project" };
pub fn change_theme(self: *Self, _: Ctx) Result {
return self.enter_overlay_mode(@import("mode/overlay/theme_palette.zig").Type);
}
pub const change_theme_meta = .{ .description = "Select color theme" };
pub fn exit_overlay_mode(self: *Self, _: Ctx) Result {
if (self.input_mode_outer == null) return;
@ -676,30 +689,37 @@ const cmds = struct {
}
if (self.input_mode) |*mode| mode.deinit();
}
pub const exit_overlay_mode_meta = .{ .interactive = false };
pub fn find(self: *Self, ctx: Ctx) Result {
return enter_mini_mode(self, @import("mode/mini/find.zig"), ctx);
}
pub const find_meta = .{ .description = "Find in current file" };
pub fn find_in_files(self: *Self, ctx: Ctx) Result {
return enter_mini_mode(self, @import("mode/mini/find_in_files.zig"), ctx);
}
pub const find_in_files_meta = .{ .description = "Find in all project files" };
pub fn goto(self: *Self, ctx: Ctx) Result {
return enter_mini_mode(self, @import("mode/mini/goto.zig"), ctx);
}
pub const goto_meta = .{ .description = "Goto line" };
pub fn move_to_char(self: *Self, ctx: Ctx) Result {
return enter_mini_mode(self, @import("mode/mini/move_to_char.zig"), ctx);
}
pub const move_to_char_meta = .{ .description = "Move cursor to matching character" };
pub fn open_file(self: *Self, ctx: Ctx) Result {
return enter_mini_mode(self, @import("mode/mini/open_file.zig"), ctx);
}
pub const open_file_meta = .{ .description = "Open file" };
pub fn save_as(self: *Self, ctx: Ctx) Result {
return enter_mini_mode(self, @import("mode/mini/save_as.zig"), ctx);
}
pub const save_as_meta = .{ .description = "Save as" };
const MiniModeFactory = fn (Allocator, Ctx) error{ NotFound, OutOfMemory }!EventHandler;
@ -730,6 +750,7 @@ const cmds = struct {
}
if (self.input_mode) |*mode| mode.deinit();
}
pub const exit_mini_mode_meta = .{ .interactive = false };
};
pub const Mode = struct {