VSCodeVim / Vim

:star: Vim for Visual Studio Code
http://aka.ms/vscodevim
MIT License
13.73k stars 1.31k forks source link

vit operation error selected character > #9137

Open lfire opened 1 month ago

lfire commented 1 month ago

Describe the bug The selected character was error, when press vit in normal mode.As shown below:

image

The lower part of the figure shows how it looks in vim, which is correct.

To Reproduce Steps to reproduce the behavior:

  1. get a vue file with code like:

        <li
          v-for="item in diseases"
          :key="item.name"
          class="ellipsis"
          aria-role="button"
          :aria-label="item.name"
          @click="toDisease(item)"
        >
          {{ item.name }}
          <span class="btn-link" />
        </li>
  2. move cursor into li tag

  3. presse vit on normal mode

commit: f1e16e1e6214d7c44d078b1f0607b2388f29d729 date: 2024-07-09T22:07:54.982Z Electron: 29.4.0 ElectronBuildId: 9728852 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Darwin arm64 23.5.0

Additional context Add any other context about the problem here.

lfire commented 1 month ago

And vat operation cannot select span tags

HenryTSZ commented 1 month ago

I think it's probably caused by the code here: L998

https://github.com/VSCodeVim/Vim/blob/e3993621a1eda03678a2b116e893f3810d0d5f06/src/mode/modeHandler.ts#L990-L1002

The meaning of this code is that if the starting position is chosen as the end of the line, it needs to be moved one character to the left

So we will select the '>' option in the start tag

I feel like there's no problem with the handling here, after all, Vim's cursor is on the character, so it can't appear at the end of the line, only on the last character

HenryTSZ commented 1 month ago

@J-Fields

Can we use the built-in functionality of VSCode for tag manipulation?

https://github.com/VSCodeVim/Vim/blob/e3993621a1eda03678a2b116e893f3810d0d5f06/src/actions/motion.ts#L2303-L2343

I will replace the code above with the code below

abstract class MoveTagMatch extends ExpandingSelection {
  override modes = [Mode.Normal, Mode.Visual, Mode.VisualBlock];
  protected includeTag = false;
  override isJump = true;

  public override async execAction(position: Position, vimState: VimState): Promise<IMovement> {
    await vscode.commands.executeCommand('editor.emmet.action.balanceIn');
    const selection = vimState.editor.selection;
    return { start: selection.start, stop: selection.end };
  }
}

The selection range here is correct, but after executing the code to correct the cursor position, the range is incorrect again

So is there any way we can avoid executing the subsequent correction code? I think we just need to execute it up to this point, and then we just need to execute v/c/d/y

PS: Including this bug #8872, I think the same solution can also be used