[vim/vim] Vim selects an "inner tag" text object (e.g., with "vit") incorrectly sometimes (Issue #15043)

9 views
Skip to first unread message

asheq-svmx

unread,
Jun 18, 2024, 5:33:40 PM (yesterday) Jun 18
to vim/vim, Subscribed

Steps to reproduce

Start with this text: <div id="animals >> mammals >> tigers">Hello</div>

(Note that the id attribute of the div has some > characters in it)

Put the cursor on the H and then type vit

Vim selects > mammals >> tigers">Hello

Expected behaviour

Vim should select Hello

Version of Vim

9.0.981

Environment

Operating system: mac 13.2.1
Terminal: kitty
$TERM: xterm-kitty
Shell: bash

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/15043@github.com>

Christian Brabandt

unread,
8:23 AM (14 hours ago) 8:23 AM
to vim/vim, Subscribed

Wow, that is a very bad example. The following patch fixes it (will create a PR soon):

diff --git a/src/textobject.c b/src/textobject.c
index 1890d7c83..aa2db0770 100644
--- a/src/textobject.c
+++ b/src/textobject.c
@@ -1426,15 +1426,22 @@ again:

     if (!do_include)
     {
-       // Exclude the start tag.
+       // Exclude the start tag,
+       // but skip over '>' if it appears in quotes
+       int in_quotes = FALSE;
        curwin->w_cursor = start_pos;
        while (inc_cursor() >= 0)
-           if (*ml_get_cursor() == '>')
+       {
+           p = ml_get_cursor();
+           if (*p == '>' && !in_quotes)
            {
                inc_cursor();
                start_pos = curwin->w_cursor;
                break;
            }
+           else if (*p == '"' || *p == '\'')
+               in_quotes = !in_quotes;
+       }
        curwin->w_cursor = end_pos;

        // If we are in Visual mode and now have the same text as before set


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/15043/2178568840@github.com>

Christian Brabandt

unread,
2:29 PM (8 hours ago) 2:29 PM
to vim/vim, Subscribed

Closed #15043 as completed via ca7f93e.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/15043/issue_event/13219818517@github.com>

Reply all
Reply to author
Forward
0 new messages