Skip to content

fix(vi): enter visual mode through command#1089

Draft
matystroia wants to merge 1 commit into
nushell:mainfrom
matystroia:vi-mode-visual-command
Draft

fix(vi): enter visual mode through command#1089
matystroia wants to merge 1 commit into
nushell:mainfrom
matystroia:vi-mode-visual-command

Conversation

@matystroia
Copy link
Copy Markdown

Problem:

Entering visual mode does not actually select char/grapheme under cursor. Thus you have to do something like vlh to actually move selection to cursor. This happens because the parser eats the v input and sets mode manually instead of it going through the usual Command -> EditCommand pipeline.

Solution:

  • Add EditCommand::SelectChar that sets selection anchor to current cursor position
  • Add Command::EnterViVisual that maps to EditCommand::SelectChar

Mode change still happens in parser, but now through the return value of changes_mode.

@kronberger-droid
Copy link
Copy Markdown
Collaborator

One behavior shift worth knowing about is that the old v path emitted ReedlineEvent::Esc, which closed any open menus. The new path skips that, could you preserve it by changing Command::EnterViVisual mapping:

Self::EnterViVisual => vec![
    ReedlineOption::Event(ReedlineEvent::Esc),
    ReedlineOption::Edit(EditCommand::SelectChar),
],

Also a couple of test before merge?

  • Editor-level: EditCommand::SelectChar sets selection_anchor
  • End-to-end: v then U on a fresh buffer capitalizes the grapheme under the cursor etc.

Also the EditCommand::SelectChar has a trailing comma.

Afterwards I am fine with landing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants