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

bug: Flash remains active after `{action}{motion — 't'/'T', 'f/F'}` is completed

Open svranesevic opened this issue 3 years ago • 11 comments

Did you check docs and existing issues?

  • [X] I have read all the flash.nvim docs
  • [X] I have searched the existing issues of flash.nvim
  • [X] I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

0.9.1

Operating system/version

MacOS 12.2.1

Describe the bug

When using {action}{motion — 't'/'T', 'f/F'} — eg. yank until opening parentheses yt(, flash.nvim remains active after motion is completed.

Steps To Reproduce

  1. Open new buffer and paste:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  1. Go to first character
  2. Execute {action}{motion}: yt,
  3. "Lorem ipsum dolor sit amet" is yanked to register
  4. 🐛 flash.nvim remains "active" like when it is invoked with 't'/'T', 'f/F' alone

Expected Behavior

When using {action}{motion — 't'/'T', 'f/F'}, flash.nvim is not active after motion is completed.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  { "folke/flash.nvim", opts = {} },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
vim.cmd.set("clipboard=unnamedplus")

svranesevic avatar Jun 21 '23 12:06 svranesevic

That's on purpose. When moving, changing buffers, pressing <esc> or doing anything else, the highlights will clear.

folke avatar Jun 21 '23 12:06 folke

Is there any way this could be made a configurable option? I frequently use yt<char> and yf<char> and it is confusing when the backdrop and labels remain and it is an extra step to hit escape or intentionally move the cursor.

ranebrown avatar Jun 27 '23 13:06 ranebrown

Also found this a bit annoying. For example if you do something like dt( it remains in jump mode, but if you continue to move with ; etc then it will move, not work on the delete. I assume this can just be disabled by having the 'f'/'F'/'t'/'T' keys not using flash in operator pending mode?

edit: also it appears that ESC does not clear the highlights from 'f' highlight mode, which definitely doesn't help

triorph avatar Jun 27 '23 23:06 triorph

I'll make it configurable.

To repeat a delete, use . instead of ;.

@triorph highlights should clear on <esc> did you map <esc> in your install by any chance? What does :map <esc> say?

folke avatar Jun 28 '23 06:06 folke

Flash now hides when yanking with an ftFT motion

folke avatar Jun 28 '23 19:06 folke

@folke as far as I can see that feature only applies to "yank" operation. Is it possible to make it work with "delete" as well?

rasulomaroff avatar Jun 28 '23 19:06 rasulomaroff

🤦 yeah I was mapping to something else. My bad. I think I agree with rasulomaroff though that it'd be nice to change this behaviour for d as well as y. In fact I think its only really helpful for v so that'd be my preference. Even just as a configurable option would be good.

triorph avatar Jun 28 '23 22:06 triorph

This is now configurable. Check the docs for opts.modes.char.autohide.

While you're at it, I also invite everyone to try the new ftFT smart label mode :)

 opts = {
      modes = {
        char = {
          jump_labels = function(motion)
            -- never show jump labels by default
            -- return false
            -- Always show jump labels for ftFT
            return vim.v.count == 0 and motion:find("[ftFT]")
            -- Show jump labels for ftFT in operator-pending mode
            -- return vim.v.count == 0 and motion:find("[ftFT]") and vim.fn.mode(true):find("o")
          end,
        },
      },
    },

It combines ftFT searches with labels. You can still navigate clever-f style or use ;, , as well. A lot of labels are also excluded, so you can continue from the new position with any key like hjklia...

It pretty much combines the best of both worlds :) you can also only enable it for operator pending mode or any other conditions.

Let me know what you think!

folke avatar Jun 29 '23 11:06 folke

@folke I think I'm gonna need to take some days off to configure flash for me 🤣

This gets it work as expected:

autohide = function(motion)
  -- autohide flash when the operator is `y` or `d`
  return vim.fn.mode(true):find 'no' and (vim.v.operator == 'y' or vim.v.operator == 'd')
end

About jump_labels - I've tried and I like it! But I wonder why label.after not working there :) I would like to put a label right after the symbol I'm searching for. Here's my config for the char mode:

char = {
  autohide = function(motion)
    -- autohide flash when the operator is `y` or `d`
    return vim.fn.mode(true):find 'no' and (vim.v.operator == 'y' or vim.v.operator == 'd')
  end,
  jump_labels = function(motion)
    return vim.v.count == 0 and motion:find '[ftFT]' and vim.fn.mode(true):find 'o'
  end,
  label = { exclude = 'iardc', after = { 0, 1 } },
}

rasulomaroff avatar Jun 29 '23 13:06 rasulomaroff

Hi @rasulomaroff did you find a solution about the labels being shown after the symbol that you're searching for?

dpetka2001 avatar Jul 05 '23 14:07 dpetka2001

@dpetka2001 not really. Just checked it, still not applied. But should it at all? I'm not sure about that, but would be nice to have 🙂

rasulomaroff avatar Jul 05 '23 15:07 rasulomaroff