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

Flashing display during paragraph movement #99

Closed
3 tasks done
ColinKennedy opened this issue Aug 10, 2024 · 5 comments · Fixed by #90
Closed
3 tasks done

Flashing display during paragraph movement #99

ColinKennedy opened this issue Aug 10, 2024 · 5 comments · Fixed by #90
Labels
bug Something isn't working

Comments

@ColinKennedy
Copy link

ColinKennedy commented Aug 10, 2024

Have you done all of these?

  • I am using the latest version of the plugin.
  • I have checked the wiki.
  • I have checked previous issues(even closed ones).

Describe the bug
When pressing { or } the markview plugin changes back to ASCII, causing a flash on the screen.

Neovim version

NVIM v0.11.0-dev-345+g3e6cec0be
Build type: Release
LuaJIT 2.1.1720049189
Run "nvim -V1 -v" for more info
nvim --version
# Output

Are you using a distro?
No

To Reproduce
Steps to reproduce the bug:

  1. Load this reproduction.lua file
-- 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 = {
  {
      "justinmk/vim-ipmotion",
      config = function()
          vim.g.ip_skipfold = 1
      end,
      keys = {
          { "{", desc = "Go to the previous paragraph including whitespace." },
          { "}", desc = "Go to the next paragraph including whitespace." },
      },
  },
  {
      "OXY2DEV/markview.nvim",
      config = true,
      lazy = false,      -- Recommended

      dependencies = {
          "nvim-treesitter/nvim-treesitter",

          "nvim-tree/nvim-web-devicons"
      }
  },
  {
      "nvim-treesitter/nvim-treesitter",
      build = ":TSUpdate",
      config = function()
        require("nvim-treesitter.configs").setup {
            ensure_installed = {
                "html",
                "markdown",
            }
        }
      end,
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})
  1. Open a markdown document.
## Requires
- lazy.nvim requires git 2.27+ so that it can used the --filter=blob:none
    - Reference: https://stackoverflow.com/a/51411174
    - Install on CentOS 7 with: https://computingforgeeks.com/install-git-2-on-centos-7/
- Requires jedi-language-server to be installed (for null-ls)
- For debugging [debugpy](https://pypi.org/project/debugpy)
- Requires [fd](https://github.com/sharkdp/fd), for searching folder with :FzfCd / <leader>cD

## Optional Requires
- Anything that `:checkhealth` recommends
- [fswatch](https://github.com/emcrisostomo/fswatch), for better LSP file change performance
    - Reference: https://github.com/neovim/neovim/pull/27347


## Mappings
### Workspace switching
1. mode
2. mapping
3. description

Move around with } and { keys

Expected behavior
No flashing

Actual behavior
The windows flashes as you move. I enabled hybrid_modes = { "n" }, so that the flashing will stop though it isn't my preferred mode.

I'm guessing the reason for the flash is because markview seems to disable its extmarks when the user goes into command-line mode, which I think vim-ipmotion has to do in order to call its vimscript paragraph function. So the bug outlined here I think would happen with basically any mapping that calls out to vim / lua.

Edit: I also got the flashing to stop by adding modes = { "n", "no", "c" }, to the configuration

Recording
(Warning: Flashing colors)

2024-08-10.09-47-43.mp4
@ColinKennedy ColinKennedy added the bug Something isn't working label Aug 10, 2024
@OXY2DEV
Copy link
Owner

OXY2DEV commented Aug 10, 2024

Not really much I can do about it since keymaps are supposed to use <cmd> to run commands instead of directly using :(this introduces similar visual bugs in plugins using vim.ui_attach()).

@ColinKennedy
Copy link
Author

I wouldn't know exactly how but https://github.com/MeanderingProgrammer/render-markdown.nvim manages this without any particular changes on my side.

2024-08-10.10-42-43.mp4

@OXY2DEV
Copy link
Owner

OXY2DEV commented Aug 10, 2024

Because that plugin lacks the ability to run on any mode.

@ColinKennedy
Copy link
Author

ColinKennedy commented Aug 10, 2024

If the flashing occurs due to a sort of "auto-toggle" that this plugin implements then I can see a route forward.

The cause of the flashing is due to rapid inputs to <cmd>. If this plugin adds a (small interval) debounce to whatever is handling the display toggling then flashes that are caused by multiple, rapid <cmd> calls will stop. Since the auto-toggle is debounced, longer interactive command calls like when a user manually types out :%s/foo/bar/g will still display the underlying ASCII text as intended. What do you think?

Edit: To be clear about the suggestion, the code would basically be like, instead of

-- Some code ...
do_the_auto_toggle()

It'd instead be something like

local function debounce_trailing(fn, ms, first)
    -- The usual debouncer logic
    local save_mode = get_vim_current_mode()  -- normal, command-line, etc

    local run_if_in_same_mode = function()
        local current_mode = get_vim_current_mode()  -- normal, command-line, etc        

        if current_mode == saved_mode then
            fn()
        end
    end

    -- Normal debouncy-type logic.
    -- Shortened to be concise - Real implementation is shown at https://gist.github.com/runiq/31aa5c4bf00f8e0843cd267880117201
    timer:start(ms, 0, function()
        pcall(vim.schedule_wrap(run_if_in_same_mode), unpack(argv, 1, argc))
    end)

    -- etc etc
end

local toggler = debounce_trailing(do_the_auto_toggle, 50)

-- Some code ...
toggler()

So if the user has already exited the mode that they were in when the toggler was initially called, the toggle is skipped. e.g. if they enter <cmd> and exit it really quickly, don't flash on the user's screen. But if they're in the same mode, they need the auto-toggle

@MeanderingProgrammer
Copy link

Because that plugin lacks the ability to run on any mode

My plugin can in fact run in any and all modes, this is incorrect

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
None yet
Development

Successfully merging a pull request may close this issue.

3 participants