targets.vim icon indicating copy to clipboard operation
targets.vim copied to clipboard

`ia` doesn't handle nested braces when arguments are put each on it's own line

Open nikitabobko opened this issue 2 years ago • 4 comments

foo(
    arg1,
    bar(),
    arg3
)

Put the cursor on bar and type vIa Expected:

foo(
    arg1,
    <selection>bar()</selection>,
    arg3
)

Actual: nothing is selected

nikitabobko avatar Jan 18 '22 23:01 nikitabobko

Just an observation that such an example works as expected if you put the cursor on arg2, but if you put it on bar then it doesn't work

foo(
    arg1,
    arg2
        .bar(),
    arg3
)

nikitabobko avatar Jan 18 '22 23:01 nikitabobko

That's because it's working on the empty argument inside of bar(<here>). But Vim doesn't allow you to select an empty selection (unfortunately). For example try cIa and it should put your cursor inside of that argument. To work on the whole outer argument bar() try v2Ia. :v:

wellle avatar Jan 19 '22 19:01 wellle

Thanks for the explanation. I would say that this behavior is misleading and I would rather prefer the one I suggested. But even if we assume that the current one is the correct behavior then the behavior is inconsistent. In case of one line call: foo(arg1, bar(baz), arg) via it selects bar(baz). But in multiline case:

foo(
  arg1,
  bar(baz),
  arg3
)

it selects baz

nikitabobko avatar Feb 05 '22 19:02 nikitabobko

The issue seems to be that the argument text object prioritizes to seek over using the current cursor position, but only if the argument list is spread over multiple lines. This is definitely inconsistent with other text objects.

If you compare it to the pairs text object:

foo(
    bar(
        zod
    )
)

If your cursor is on the "b" in "bar" and you press vi) it will select:

foo(
<selection>
    bar(
        zod
    )
</selection>
)

If the pairs text object acted like the argument text object here, it would instead select:

foo(
    bar(
<selection>
        zod
</selection>
    )
)

Hubro avatar Mar 23 '22 11:03 Hubro