refactor: identify mode inside hx on bracket matching

This commit is contained in:
Igor Támara 2025-11-17 17:44:40 -05:00 committed by CJ van den Berg
parent 3d0a0571c2
commit fd3401748e
2 changed files with 5 additions and 4 deletions

View file

@ -463,7 +463,7 @@
["x", "extend_line_below"],
["m m", "match_brackets", "helix_sel_mode"],
["m m", "match_brackets"],
["m a", "match", "select_textobject_around"],
["m i", "match", "select_textobject_inner"],
["m d", "match", "surround_delete"],

View file

@ -209,11 +209,12 @@ const cmds_ = struct {
}
pub const split_selection_on_newline_meta: Meta = .{ .description = "Add cursor to each line in selection helix" };
pub fn match_brackets(_: *void, ctx: Ctx) Result {
pub fn match_brackets(_: *void, _: Ctx) Result {
const mv = tui.mainview() orelse return;
const ed = mv.get_active_editor() orelse return;
const root = ed.buf_root() catch return;
try ed.with_cursels_const_once_arg(root, &match_bracket, ctx);
const m = tui.input_mode().?.*.name;
try ed.with_cursels_const_once_arg(root, &match_bracket, command.fmt(.{m}));
ed.clamp();
}
pub const match_brackets_meta: Meta = .{ .description = "Goto matching bracket" };
@ -493,7 +494,7 @@ const cmds_ = struct {
fn match_bracket(root: Buffer.Root, cursel: *CurSel, ctx: command.Context, metrics: Buffer.Metrics) error{Stop}!void {
var symbol: []const u8 = undefined;
const mode: enum { helix_sel_mode, helix_nor_mode } = if ((ctx.args.match(.{tp.extract(&symbol)}) catch false) and
std.mem.eql(u8, @tagName(.helix_sel_mode), symbol)) .helix_sel_mode else .helix_nor_mode;
std.mem.eql(u8, "SEL", symbol)) .helix_sel_mode else .helix_nor_mode;
if (mode == .helix_sel_mode) {
const begin: Cursor = if (cursel.selection) |sel| sel.begin else cursel.*.cursor;