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

Horizontal cursor position clobbered #4

Closed
ribru17 opened this issue Mar 31, 2023 · 7 comments
Closed

Horizontal cursor position clobbered #4

ribru17 opened this issue Mar 31, 2023 · 7 comments

Comments

@ribru17
Copy link
Contributor

ribru17 commented Mar 31, 2023

Hi and thanks for the great plugin! One small bug I noticed: when using this plugin, my horizontal cursor position is not saved in normal mode, same problem found here or here. I really like this plugin but this issue bugs me so hopefully it can be fixed, thank you!! (P.S. when disabling the plugin, horizontal cursor position is again saved correctly)

@Bekaboo
Copy link
Owner

Bekaboo commented Mar 31, 2023

Hi, thanks for reporting this issue. Unfortunately I cannot reproduce this bug.

The following is the behavior of this plugin under normal mode, is this what you expected? If not, please provide the minimal config that can reproduce this bug and screen recording:

simplescreenrecorder-2023-03-31_09.49.22.mp4

@ribru17
Copy link
Contributor Author

ribru17 commented Mar 31, 2023

Should've mentioned that this bug doesn't occur when using $ to set cursor to last column of the line, sorry. Here's a demo with MRE.
https://user-images.githubusercontent.com/55766287/229184947-2f1b1f2c-26ac-4b12-b726-340f4b551901.mp4

-- ~/.config/nvim/init.lua
local lazypath = vim.fn.stdpath("data") .. "/lazy/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",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

-- load installed plugins and their configurations
require("lazy").setup("plugins", {
  performance = {
    cache = {
      enabled = true,
    },
    reset_packpath = true,
    rtp = {
      reset = true,
      disabled_plugins = {
        "gzip",
        "matchit",
        "matchparen",
        "netrwPlugin",
        "tarPlugin",
        "tohtml",
        "tutor",
        "zipPlugin",
      },
    },
  },
})
-- ~/.config/nvim/lua/plugins/ui.lua
return {
  {
    'Bekaboo/deadcolumn.nvim',
    event = { 'BufReadPre', 'BufNewFile' },
    opts = {
      blending = {
        threshold = 0.75,
      },
      warning = {
        colorcode = '#ED8796',
      }
    }
  }
}

@ribru17
Copy link
Contributor Author

ribru17 commented Mar 31, 2023

I found a naive solution which is to remove the WinScrolled and CursorMoved events from the redraw_colorcolumn autocmd (this function somehow causes the editor to forget the cursor position) but I don't think this should be an accepted solution because it will of course break the plugin for users that want the color column to show in the normal mode scope. I think some vim api function is causing this breakage perhaps but I don't know which.

@Bekaboo
Copy link
Owner

Bekaboo commented Mar 31, 2023

Good catch, but the real problem here is not vim api functions, it is setting vim.wo.cc that make neovim forget the cursor position. If you comment out all commands that set vim.wo.cc in function redraw_colorcolumn, the bug disappears, but that is not what we want. I think it is a neovim issue and not related to this plugin.

The reason why I conclude the problem comes from option setting is that if you open neovim with nvim --clean somefile, first put your cursor at column, say, 10, then moves up and down, you can observe that the position is memorized; but if you put the cursor on an empty line then set an option in cmdline, for example, :set cc=30 or :set tw=79, the cursor position will be lost.

This is beyond deadcolumn.nvim and I don't think there is an easy fix to this, maybe we should report it to neovim. PR is welcome.

@ribru17
Copy link
Contributor Author

ribru17 commented Mar 31, 2023

Interesting, thanks for the response and quick fix. I also noticed that this can be fixed by saving and restoring the window state. I tested both methods and I think with this way the cursor is always saved even when switching tabs or buffers for example, which will cause the cursor to reset with the current fix. But definitely not a big issue as the main problem is largely fixed. Still, if you're interested I will link the change and up to you if you want to do anything with this, thanks again:
ribru17@7eca7b1

@Bekaboo
Copy link
Owner

Bekaboo commented Mar 31, 2023

Seems that it is a better solution, please make a PR and I will be happy to accept it.

PS: is it still necessary to check vim.wo.cc before setting it given that we now have winsaveview()? Haven't tested myself.

@ribru17
Copy link
Contributor Author

ribru17 commented Mar 31, 2023

Sounds good, I'll make a PR very soon, going to eat now. And I'm not sure: I'll test that as well. As of now I don't know anything about vim.wo.cc to tell you the truth.

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

No branches or pull requests

2 participants