hydra.nvim icon indicating copy to clipboard operation
hydra.nvim copied to clipboard

fix(hint): nolazyredraw

Open ivanbrennan opened this issue 1 year ago • 2 comments

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

ivanbrennan avatar Feb 13 '23 02:02 ivanbrennan