fix: quote textobject selects wrong pair when cursor is on closing quote

This commit is contained in:
CJ van den Berg 2026-04-13 19:02:53 +02:00
parent 76cc8260bb
commit afeca37f10

View file

@ -4071,9 +4071,15 @@ pub const Editor = struct {
quote: []const u8, quote: []const u8,
) error{Stop}!struct { struct { usize, usize }, struct { usize, usize } } { ) error{Stop}!struct { struct { usize, usize }, struct { usize, usize } } {
// Find nearest quote (prefer rightward) // If the cursor is already on a quote, use it directly as the anchor.
const anchor = // Otherwise find the nearest quote, preferring rightward.
find_unescaped_quote(root, original_cursor, metrics, .right, quote) catch find_unescaped_quote(root, original_cursor, metrics, .left, quote) catch return error.Stop; const cursor_egc, _, _ = root.egc_at(original_cursor.row, original_cursor.col, metrics) catch return error.Stop;
const anchor = if (std.mem.eql(u8, cursor_egc, quote))
original_cursor
else
find_unescaped_quote(root, original_cursor, metrics, .right, quote) catch
find_unescaped_quote(root, original_cursor, metrics, .left, quote) catch
return error.Stop;
const role = try quote_role_on_row(root, anchor, metrics, quote); const role = try quote_role_on_row(root, anchor, metrics, quote);