Add angle bracket textobject actions

This commit is contained in:
UnsaltedScholar 2026-04-12 17:56:19 -04:00 committed by CJ van den Berg
parent 1769342e23
commit 1e7d595309
3 changed files with 84 additions and 0 deletions

View file

@ -44,6 +44,7 @@ pub const char_pairs = [_]struct { []const u8, []const u8 }{
.{ "`", "`" },
.{ "(", ")" },
.{ "[", "]" },
.{ "<", ">" },
.{ "{", "}" },
.{ "", "" },
.{ "", "" },
@ -56,6 +57,7 @@ pub const char_pairs = [_]struct { []const u8, []const u8 }{
pub const open_close_pairs = [_]struct { []const u8, []const u8 }{
.{ "(", ")" },
.{ "[", "]" },
.{ "<", ">" },
.{ "{", "}" },
.{ "", "" },
.{ "", "" },

View file

@ -86,6 +86,8 @@
["di)", "cut_inside_parentheses"],
["di[", "cut_inside_square_brackets"],
["di]", "cut_inside_square_brackets"],
["di<LT>", "cut_inside_angle_brackets"],
["di<GT>", "cut_inside_angle_brackets"],
["di{", "cut_inside_braces"],
["di}", "cut_inside_braces"],
["di'", "cut_inside_single_quotes"],
@ -96,6 +98,8 @@
["da)", "cut_around_parentheses"],
["da[", "cut_around_square_brackets"],
["da]", "cut_around_square_brackets"],
["da<LT>", "cut_around_angle_brackets"],
["da<GT>", "cut_around_angle_brackets"],
["da{", "cut_around_braces"],
["da}", "cut_around_braces"],
["da'", "cut_around_single_quotes"],
@ -112,6 +116,8 @@
["ci)", ["enter_mode", "insert"], ["cut_inside_parentheses"]],
["ci[", ["enter_mode", "insert"], ["cut_inside_square_brackets"]],
["ci]", ["enter_mode", "insert"], ["cut_inside_square_brackets"]],
["ci<LT>", ["enter_mode", "insert"], ["cut_inside_angle_brackets"]],
["ci<GT>", ["enter_mode", "insert"], ["cut_inside_angle_brackets"]],
["ci{", ["enter_mode", "insert"], ["cut_inside_braces"]],
["ci}", ["enter_mode", "insert"], ["cut_inside_braces"]],
["ci'", ["enter_mode", "insert"], ["cut_inside_single_quotes"]],
@ -122,6 +128,8 @@
["ca)", ["enter_mode", "insert"], ["cut_around_parentheses"]],
["ca[", ["enter_mode", "insert"], ["cut_around_square_brackets"]],
["ca]", ["enter_mode", "insert"], ["cut_around_square_brackets"]],
["ca<LT>", ["enter_mode", "insert"], ["cut_around_angle_brackets"]],
["ca<GT>", ["enter_mode", "insert"], ["cut_around_angle_brackets"]],
["ca{", ["enter_mode", "insert"], ["cut_around_braces"]],
["ca}", ["enter_mode", "insert"], ["cut_around_braces"]],
["ca'", ["enter_mode", "insert"], ["cut_around_single_quotes"]],
@ -134,6 +142,8 @@
["yi)", ["copy_inside_parentheses"], ["cancel"]],
["yi[", ["copy_inside_square_brackets"], ["cancel"]],
["yi]", ["copy_inside_square_brackets"], ["cancel"]],
["yi<LT>", ["copy_inside_angle_brackets"], ["cancel"]],
["yi<GT>", ["copy_inside_angle_brackets"], ["cancel"]],
["yi{", ["copy_inside_braces"], ["cancel"]],
["yi}", ["copy_inside_braces"], ["cancel"]],
["yi'", ["copy_inside_single_quotes"], ["cancel"]],
@ -144,6 +154,8 @@
["ya)", ["copy_around_parentheses"], ["cancel"]],
["ya[", ["copy_around_square_brackets"], ["cancel"]],
["ya]", ["copy_around_square_brackets"], ["cancel"]],
["ya<LT>", ["copy_around_angle_brackets"], ["cancel"]],
["ya<GT>", ["copy_around_angle_brackets"], ["cancel"]],
["ya{", ["copy_around_braces"], ["cancel"]],
["ya}", ["copy_around_braces"], ["cancel"]],
["ya'", ["copy_around_single_quotes"], ["cancel"]],
@ -224,6 +236,8 @@
["i)", "select_inside_parentheses"],
["i[", "select_inside_square_brackets"],
["i]", "select_inside_square_brackets"],
["i<LT>", "select_inside_angle_brackets"],
["i<GT>", "select_inside_angle_brackets"],
["i{", "select_inside_braces"],
["i}", "select_inside_braces"],
["i'", "select_inside_single_quotes"],
@ -234,6 +248,8 @@
["a)", "select_around_parentheses"],
["a[", "select_around_square_brackets"],
["a]", "select_around_square_brackets"],
["a<LT>", "select_around_angle_brackets"],
["a<GT>", "select_around_angle_brackets"],
["a{", "select_around_braces"],
["a}", "select_around_braces"],
["a'", "select_around_single_quotes"],

View file

@ -202,6 +202,24 @@ const cmds_ = struct {
}
pub const select_around_square_brackets_meta: Meta = .{ .description = "Select around []" };
pub fn select_inside_angle_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(root, select_inside_angle_brackets_textobject, ed.metrics);
}
pub const select_inside_angle_brackets_meta: Meta = .{ .description = "Select inside <>" };
pub fn select_around_angle_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(root, select_around_angle_brackets_textobject, ed.metrics);
}
pub const select_around_angle_brackets_meta: Meta = .{ .description = "Select around <>" };
pub fn select_inside_braces(_: *void, _: Ctx) Result {
const mv = tui.mainview() orelse return;
const ed = mv.get_active_editor() orelse return;
@ -316,6 +334,26 @@ const cmds_ = struct {
}
pub const cut_around_square_brackets_meta: Meta = .{ .description = "Cut around []" };
pub fn cut_inside_angle_brackets(_: *void, ctx: 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(root, select_inside_angle_brackets_textobject, ed.metrics);
try ed.cut_internal_vim(ctx);
}
pub const cut_inside_angle_brackets_meta: Meta = .{ .description = "Cut inside <>" };
pub fn cut_around_angle_brackets(_: *void, ctx: 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(root, select_around_angle_brackets_textobject, ed.metrics);
try ed.cut_internal_vim(ctx);
}
pub const cut_around_angle_brackets_meta: Meta = .{ .description = "Cut around <>" };
pub fn cut_inside_braces(_: *void, ctx: Ctx) Result {
const mv = tui.mainview() orelse return;
const ed = mv.get_active_editor() orelse return;
@ -436,6 +474,26 @@ const cmds_ = struct {
}
pub const copy_around_square_brackets_meta: Meta = .{ .description = "Copy around []" };
pub fn copy_inside_angle_brackets(_: *void, ctx: 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(root, select_inside_angle_brackets_textobject, ed.metrics);
try ed.copy_internal_vim(ctx);
}
pub const copy_inside_angle_brackets_meta: Meta = .{ .description = "Copy inside <>" };
pub fn copy_around_angle_brackets(_: *void, ctx: 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(root, select_around_angle_brackets_textobject, ed.metrics);
try ed.copy_internal_vim(ctx);
}
pub const copy_around_angle_brackets_meta: Meta = .{ .description = "Copy around <>" };
pub fn copy_inside_braces(_: *void, ctx: Ctx) Result {
const mv = tui.mainview() orelse return;
const ed = mv.get_active_editor() orelse return;
@ -575,6 +633,14 @@ fn select_around_square_brackets_textobject(root: Buffer.Root, cursel: *CurSel,
return try select_scope_textobject(root, cursel, metrics, "[", "]", .around);
}
fn select_inside_angle_brackets_textobject(root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics) !void {
return try select_scope_textobject(root, cursel, metrics, "<", ">", .inside);
}
fn select_around_angle_brackets_textobject(root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics) !void {
return try select_scope_textobject(root, cursel, metrics, "<", ">", .around);
}
fn select_inside_braces_textobject(root: Buffer.Root, cursel: *CurSel, metrics: Buffer.Metrics) !void {
return try select_scope_textobject(root, cursel, metrics, "{", "}", .inside);
}