VSCodeVim / Vim

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

Failing to change cursor and display --REPLACE-- mode at the bottom "status bar" when I hit `r` to enter replace mode. `R` works as expected. #6211

Open guhan-balaji opened 3 years ago

guhan-balaji commented 3 years ago

Steps to reproduce: 1) Enter "r" when in normal mode, and work in replace mode. 2) Enter "shift + r" when u come back to normal mode for contrast.

Screenshots:

2021-02-27 (3) When I press "r", it functions properly but fails to change the cursor and it doesn't prompt --REPLACE-- at the bottom. (As you can see above)^

========================================================================

2021-02-27 (2) On the other hand "Shift + r" (batch replace) works as expected. (As you can see above)^

J-Fields commented 3 years ago

It shouldn't display -- REPLACE --, as r doesn't put you in Replace mode, you remain in Normal mode. Neovim does change the cursor though, we should probably replicate that behavior.

facundobatista commented 3 months ago

Yes, please, the cursor when doing r should change like when doing R, as vim does. Thanks!!

facundobatista commented 3 months ago

I've been exploring the code a little and differentiate the cursor for r and R is not that easy.

We're handling "r + anychar" as a single action, so we don't control how the cursor looks "after r but before anychar:

export class ActionReplaceCharacter extends BaseCommand {
  modes = [Mode.Normal];
  keys = ['r', '<character>'];
  ...

We could have something like a transient mode, and one hand do:

@RegisterAction
export class CommandReplaceAtCursorFromNormalMode extends BaseCommand {
  modes = [Mode.Normal];
  keys = ['r'];

  public override async exec(position: Position, vimState: VimState): Promise<void> {
    await vimState.setCurrentMode(Mode.OneCharReplace);
  }
}

... and then ...

@RegisterAction
export class ActionReplaceCharacter extends BaseCommand {
  modes = [Mode.OneCharReplace];
  keys = ['<character>'];
  override createsUndoPoint = true;
  override runsOnceForEachCountPrefix = false;

  public override async exec(position: Position, vimState: VimState): Promise<void> {
    const toReplace = this.keysPressed[0];
    ...

BUT

Thanks for all anyway! Hope this can be achievable.