Skip to content

fix(hint): nolazyredraw#76

Open
ivanbrennan wants to merge 1 commit intoanuvyklack:masterfrom
ivanbrennan:nolazyredraw
Open

fix(hint): nolazyredraw#76
ivanbrennan wants to merge 1 commit intoanuvyklack:masterfrom
ivanbrennan:nolazyredraw

Conversation

@ivanbrennan
Copy link
Copy Markdown

Fix a rendering issue that causes the cursor to appear at the end of the hint if lazyredraw is enabled and hint is shown in the echo area.

Problem

If a hydra shows its hint in the echo area (config.hint.type = 'cmdline') and the user has lazyredraw on, the hint renders correctly when first invoked, but any subsequent action (within the hydra) causes the cursor to appear at the end of the hint.
image

Solution

Add an on_enter function to the default config to turn lazyredraw off for the duration of the hydra.


Minimal reproducible example

The problem can be demonstrated (prior to this commit) by invoking nvim like,

nvim -u minimal.lua +'call append(0, "1234")' +'goto 1'

with the following minimal.lua init file:

vim.opt.lazyredraw = true
vim.opt.wrap = false -- allow horizontal scrolling
local hydra = require('hydra')
hydra({
  name = 'scroll',
  mode = 'n',
  body = 'z',
  heads = { { 'l', 'zl' }, { 'h', 'zh' } },
  config = { hint = { type = 'cmdline' } },
})

Type zl to invoke the hydra, and the hint is drawn correctly.
image

Type l to scroll again, and now the cursor is drawn at the end of the hint.
image

When 'lazyredraw' is on, hydra hints don't always render correctly in
the cmdline. Specifically, the hint will render correctly when first
invoking the hydra, but any subsequent actions cause a block cursor to
appear at the end of the hint (and disappear from the active window).

This can be demonstrated (prior to this commit) by invoking nvim like,

  nvim -u minimal.lua +'call append(0, "1234")' +'goto 1'

with the following minimal.lua init file:

  vim.opt.lazyredraw = true
  vim.opt.wrap = false -- allow horizontal scrolling
  local hydra = require('hydra')
  hydra({
    name = 'scroll',
    mode = 'n',
    body = 'z',
    heads = { { 'l', 'zl' }, { 'h', 'zh' } },
    config = { hint = { type = 'cmdline' } },
  })

Type 'zl' to invoke the hydra, and the hint is drawn correctly. Type
either 'l' or 'h' to scroll again, and now the cursor is drawn to the
right of the hint in the echo area.
ivanbrennan added a commit to ivanbrennan/nixbox that referenced this pull request Feb 13, 2023
Using my fork to address lazyredraw issue.
See anuvyklack/hydra.nvim#76
@folke
Copy link
Copy Markdown

folke commented Feb 14, 2023

Just don't set lazyredraw? That option is not meant to be set by a user.
I don't think a plugin should take care of that tbh.

 'lazyredraw' 'lz'	boolean	(default off)
			global
	When this option is set, the screen will not be redrawn while
	executing macros, registers and other commands that have not been
	typed.  Also, updating the window title is postponed.  To force an
	update use |:redraw|.
	This may occasionally cause display errors.  It is only meant to be set
	temporarily when performing an operation where redrawing may cause
	flickering or cause a slow down.

@ivanbrennan
Copy link
Copy Markdown
Author

@folke Some users set lazyredraw to improve the performance of macros. It does seem there's been some back and forth on how advisable it is to do so, e.g.

Your point is valid, and this is a bit beyond the plugin's responsibility. But I think it's worth mentioning the issue (and solution) in the docs. I ended up bisecting my configuration before finally identifying lazyredraw as the root cause.

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