feat: closing and saving including multiple in helix mode

Review of devlogs to use internal functions to also:

* select next and prev word
* select to start en of doc
* delete to end of line
* Add Cursor to next line
* Show diagnostics
* Show references
This commit is contained in:
Igor Támara 2025-09-26 07:35:49 -05:00 committed by CJ van den Berg
parent a5d3eb18f3
commit d695d69383
2 changed files with 67 additions and 4 deletions

View file

@ -71,7 +71,7 @@
["A", ["enter_mode", "insert"], ["move_end"]],
["O", ["enter_mode", "insert"], ["smart_insert_line_before"]],
["C", "copy_selection_on_next_line"],
["C", "add_cursor_down"],
["S", "split_selection"],
["X", "extend_to_line_bounds"],
["?", "rfind"],
@ -129,7 +129,7 @@
["g s", "smart_move_begin"],
["g d", "goto_definition"],
["g y", "goto_type_definition"],
["g r", "goto_reference"],
["g r", "references"],
["g i", "goto_implementation"],
["g t", "goto_window_top"],
["g c", "goto_window_center"],
@ -218,7 +218,7 @@
["space b", "switch_buffers"],
["space j", "jumplist_picker"],
["space s", "symbol_picker"],
["space d", "diagnostics_picker"],
["space d", "show_diagnostics"],
["space a", "code_action"],
["space '", "last_picker"],
["space y", "copy"],
@ -253,6 +253,7 @@
["ctrl+y", "redo"],
["ctrl+c", "enter_mode", "normal"],
["ctrl+o", "run_ls"],
["ctrl+k", "delete_to_end"],
["escape", "enter_mode", "normal"]
]
},
@ -263,6 +264,12 @@
"selection": "inclusive",
"init_command": ["enable_selection"],
"press": [
["b", "select_word_left"],
["w", "select_word_right"],
["g g", "select_buffer_begin"],
["g e", "select_buffer_end"],
["ctrl+b", "select_page_up"],
["ctrl+f", "select_page_down"],
["ctrl+u", "select_half_page_up"],
@ -505,7 +512,7 @@
["space b", "switch_buffers"],
["space j", "jumplist_picker"],
["space s", "symbol_picker"],
["space d", "diagnostics_picker"],
["space d", "show_diagnostics"],
["space a", "code_action"],
["space '", "last_picker"],
["space y", "copy"],

View file

@ -40,6 +40,11 @@ const cmds_ = struct {
}
pub const q_meta: Meta = .{ .description = "q (quit)" };
pub fn qa(_: *void, _: Ctx) Result {
try cmd("quit", .{});
}
pub const qa_meta: Meta = .{ .description = "qa (close all)" };
pub fn @"q!"(_: *void, _: Ctx) Result {
try cmd("quit_without_saving", .{});
}
@ -60,6 +65,52 @@ const cmds_ = struct {
}
pub const x_meta: Meta = .{ .description = "x (write/save file and quit)" };
// This one needs some help, the intention is to close only the current buffer
// , if is the only buffer, exit...
// TODO
// pub fn @"x!"(_: *void, _: Ctx) Result {
// try cmd("save_file", .{});
// try cmd("close_file_without_saving", .{});
// }
// pub const @"x!_meta": Meta = .{ .description = "x! (write/save file and close forcefully, ignoring unsaved changes)" };
pub fn wa(_: *void, _: Ctx) Result {
if (tui.get_buffer_manager()) |bm|
bm.save_all() catch |e| return tp.exit_error(e, @errorReturnTrace());
}
pub const wa_meta: Meta = .{ .description = "wa (save all)" };
pub fn xa(_: *void, _: Ctx) Result {
if (tui.get_buffer_manager()) |bm| {
bm.save_all() catch |e| return tp.exit_error(e, @errorReturnTrace());
try cmd("quit", .{});
}
}
pub const xa_meta: Meta = .{ .description = "xa (write all and quit)" };
pub fn @"xa!"(_: *void, _: Ctx) Result {
if (tui.get_buffer_manager()) |bm| {
bm.save_all() catch {};
try cmd("quit_without_saving", .{});
}
}
pub const @"xa!_meta": Meta = .{ .description = "xa! (write all and quit forcefully, ignoring unsaved changes)" };
pub fn wqa(_: *void, _: Ctx) Result {
if (tui.get_buffer_manager()) |bm|
bm.save_all() catch |e| return tp.exit_error(e, @errorReturnTrace());
try cmd("quit", .{});
}
pub const wqa_meta: Meta = .{ .description = "wqa (write all and quit)" };
pub fn @"wqa!"(_: *void, _: Ctx) Result {
if (tui.get_buffer_manager()) |bm| {
bm.save_all() catch {};
try cmd("quit_without_saving", .{});
}
}
pub const @"wqa!_meta": Meta = .{ .description = "wqa! (write all and quit forcefully, ignoring unsaved changes)" };
pub fn rl(_: *void, _: Ctx) Result {
try cmd("reload_file", .{});
}
@ -96,6 +147,11 @@ const cmds_ = struct {
}
pub const bc_meta: Meta = .{ .description = "bc (Close buffer/tab)" };
pub fn @"bc!"(_: *void, _: Ctx) Result {
try cmd("close_file_without_saving", .{});
}
pub const @"bc!_meta": Meta = .{ .description = "bc! (Close buffer/tab forcefully, ignoring changes)" };
pub fn save_selection(_: *void, _: Ctx) Result {
const logger = log.logger("helix-mode");
defer logger.deinit();