Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vi-mode incorrect cursor style when exiting visual mode #11705

Open
Subjective opened this issue May 22, 2023 · 2 comments
Open

vi-mode incorrect cursor style when exiting visual mode #11705

Subjective opened this issue May 22, 2023 · 2 comments
Labels
Bug Something isn't working

Comments

@Subjective
Copy link

Describe the bug

When switching out of visual mode, the cursor does not change back to a block.

Steps to reproduce

Minimal config:

# .zshrc
...
plugins+=(vi-mode)

VI_MODE_SET_CURSOR=true
...
  1. Enable the vi-mode plugin: plugins+=(vi-mode)
  2. Set VI_MODE_SET_CURSOR=true in .zshrc
  3. Enter visual select and hit escape
  4. The cursor doesn't change back to a block as it should in normal mode

Expected behavior

I would expect the cursor to remain a block when entering visual mode (or exiting visual mode) instead of switching into a vertical line.

Screenshots and recordings

Screen Recording 2023-05-21 at 6 05 46 PM

OS / Linux distribution

macOS 13.3

Zsh version

5.9

Oh My Zsh version

master (b06663d)

Terminal emulator

kitty

If using WSL on Windows, which version of WSL

None

Additional context

This seems to have been introduced by the fix for #11586 as removing the following lines resolves the issue:

function _visual-mode {
  typeset -g VI_KEYMAP=visual
  _vi-mode-set-cursor-shape-for-keymap "$VI_KEYMAP"
  zle .visual-mode
}
zle -N visual-mode _visual-mode
@Subjective Subjective added the Bug Something isn't working label May 22, 2023
@Subjective Subjective changed the title vi-mode visual mode cursor vi-mode visual mode cursor incorrect style May 22, 2023
@Subjective Subjective changed the title vi-mode visual mode cursor incorrect style vi-mode incorrect cursor style when exiting visual mode May 22, 2023
@okapia
Copy link

okapia commented May 22, 2023

If you want to detect visual mode reliably, use the zle-line-pre-redraw hook and test for [[ $KEYMAP = vicmd ]] && (( REGION_ACTIVE )). That maps to how zsh defined visual mode internally. Wrapping widgets should be a last resort because it tends to lose the effect of widget flags. That #11586 "fix" misses the visual-line-mode widget. And a user might use an emacs region widget or a custom widget. And it only detects entering visual-mode, not leaving it.

The cursor is a bit of a tricky issue with visual mode. If the cursor is done in reverse video and reverse is used for the selection they cancel each other out. Otherwise, a block cursor works best for vi-command mode including visual mode. But this user has configured a vertical bar for visual mode.

If you really want to wrap the visual-mode widget, consider making it conditional depending on whether the cursor is even configured to be different.

It's worse in emacs mode where the cursor position is part of the region at the beginning but not at the end. But I think there are fewer users of the emacs region and they don't configure their cursor so it tends not to come up.

@m-m-moradi
Copy link

m-m-moradi commented Jun 30, 2023

I faced the exact same issue, and I managed to resolve it by removing the code that was added in #11586. Would you @mcornella be able to offer any assistance about this?

before removing the code:
after

after removeing the code:
before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

3 participants