From fd3401748ec5f56233de466704a44255cae53d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20T=C3=A1mara?= Date: Mon, 17 Nov 2025 17:44:40 -0500 Subject: [PATCH] refactor: identify mode inside hx on bracket matching --- src/keybind/builtin/helix.json | 2 +- src/tui/mode/helix.zig | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/keybind/builtin/helix.json b/src/keybind/builtin/helix.json index bceb127..a76828c 100644 --- a/src/keybind/builtin/helix.json +++ b/src/keybind/builtin/helix.json @@ -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"], diff --git a/src/tui/mode/helix.zig b/src/tui/mode/helix.zig index 2c49306..ed631ad 100644 --- a/src/tui/mode/helix.zig +++ b/src/tui/mode/helix.zig @@ -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;