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

plugin cause j/k position incorrect #73

Open
defpis opened this issue Aug 21, 2023 · 6 comments
Open

plugin cause j/k position incorrect #73

defpis opened this issue Aug 21, 2023 · 6 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@defpis
Copy link

defpis commented Aug 21, 2023

Current behavior:
屏幕录制2023-08-21 17 51 23

Desired behavior:
屏幕录制2023-08-21 17 50 51

@JoosepAlviste
Copy link
Owner

Hey @defpis! I can't quite reproduce this:

Screen.Recording.2023-09-12.at.21.56.21.mov

What exact keys are you pressing for the examples?

Could you create a minimal reproducible config using the minimal config? https://github.com/JoosepAlviste/nvim-ts-context-commentstring/blob/9bff161dfece6ecf3459e6e46ca42e49f9ed939f/utils/minimal_init.lua

@defpis
Copy link
Author

defpis commented Sep 14, 2023

Thanks for taking the time to check out the problem, any help would be appreciated.
There is minimal config:

local options = { -- :help options
  backup = false, -- Don't create a backup file
  clipboard = 'unnamedplus', -- Allow NeoVim to access system clipboard
  conceallevel = 0, -- Make `` visible in Markdown files
  fileencoding = 'utf-8', -- Use `utf-8` as encoding
  hlsearch = true, -- Highlight all matches on previous search pattern
  ignorecase = true, -- Ignore case in search patterns
  mouse = 'a', -- Allow the mouse to be used in NeoVim
  showmode = false, -- Hide NeoVim modes in the status bar
  showtabline = 2, -- Always show tabs
  smartcase = true, -- Ignore `ignorecase` if search pattern contains upper case characters
  smartindent = true, -- Make indenting smarter on newline
  splitbelow = true, -- Force all horizontal splits to go below current window
  splitright = true, -- Force all vertical splits to go to the right of current window
  swapfile = false, -- Don't create a swapfile
  termguicolors = true, -- Set term gui colors
  timeoutlen = 1000, -- Time to wait for a mapped sequence to complete (in milliseconds)
  updatetime = 300, -- Faster completion (4000ms default)
  writebackup = false, -- If a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited
  expandtab = true, -- Convert tabs to spaces
  shiftwidth = 2, -- The number of spaces inserted for each indentation
  tabstop = 2, -- Insert 2 spaces for a tab
  cursorline = true, -- Highlight the current line
  cursorlineopt = 'number', -- Hightlight the current line number
  number = true, -- Set numbered lines
  relativenumber = true, -- Set relative numbered lines
  signcolumn = 'yes', -- Always show the sign column, otherwise it would shift the text each time
  wrap = false, -- Display long lines as one
  scrolloff = 8, -- Minimal number of screen lines to keep above and below the cursor
  sidescrolloff = 8, -- Minimal number of screen columns to keep left and right the cursor
  cmdheight = 1, -- More space in the neovim command line for displaying messages
  pumheight = 10, -- Make popup menu smaller
  background = 'dark', -- Tell NeoVim what the background color is
  laststatus = 3, -- Use global statusline
}

for key, value in pairs(options) do
  vim.opt[key] = value
end



local lazy_path = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'

if not vim.loop.fs_stat(lazy_path) then
  vim.fn.system({
    'git',
    'clone',
    '--filter=blob:none',
    'https://github.com/folke/lazy.nvim.git',
    '--branch=stable',
    lazy_path,
  })
end

vim.opt.rtp:prepend(lazy_path)

require('lazy').setup({
  {
    'gbprod/yanky.nvim',
    config = function()
      require('yanky').setup({
        preserve_cursor_position = { enabled = true },
        highlight = { on_put = false, on_yank = false },
      })
    end,
  },
  {
    'phaazon/hop.nvim',
    branch = 'v2',
    config = function()
      require('hop').setup({ keys = 'etovxqpdygfblzhckisuran' })
    end,
  },
  -- {
  --   'numToStr/Comment.nvim',
  --   config = function()
  --     require('Comment').setup()

  --     -- local ft = require('Comment.ft')
  --     -- ft.set('json', { '// %s', '/* %s */' })
  --   end,
  -- },
  {
    'kylechui/nvim-surround',
    config = function()
      require('nvim-surround').setup()
    end,
  },
  { 'nvim-treesitter/nvim-treesitter-textobjects', dependencies = { 'nvim-treesitter' } },
  {
    'nvim-treesitter/nvim-treesitter',
    dependencies = { 'JoosepAlviste/nvim-ts-context-commentstring' }, -- FIXME: May cause j/k position incorrect
    config = function()
      require('nvim-treesitter.configs').setup({
        ensure_installed = {
          'lua',
          'typescript',
          'tsx',
          'javascript',
          'html',
          'css',
          'scss',
          'json',
          'jsonc',
          'yaml',
          'markdown',
        },
        incremental_selection = {
          enable = true,
          keymaps = {
            init_selection = '<Leader><CR>',
            node_incremental = '<CR>',
            node_decremental = '<BS>',
            scope_incremental = '<Leader><CR>',
          },
        },
        textobjects = {
          select = {
            enable = true,
            lookahead = true,
            keymaps = {
              ['af'] = '@function.outer',
              ['if'] = '@function.inner',
              ['aa'] = '@parameter.outer',
              ['ia'] = '@parameter.inner',
            },
          },
        },
        context_commentstring = { enable = true },
      })
    end,
  },
})

both terminal and vscode cursor can't move correct position.

@JoosepAlviste
Copy link
Owner

Thanks for the minimal config!

I tried it out, but still can't reproduce the issue:

Screen.Recording.2023-09-28.at.22.22.57.mov

To be honest, I don't have any ideas as to what might be going wrong 😕 Maybe we could get someone else to try to reproduce it?

I don't think that this plugin should affect j/k in any way as it just sets up an autocommand on CursorHold and that's it. Maybe there's something outside of Vim that's affecting it somehow?

@defpis
Copy link
Author

defpis commented Oct 7, 2023

Thank you. There may be a problem with my computer environment. I try to find the reason by myself, I close this issue.

@defpis defpis closed this as completed Oct 7, 2023
@expipiplus1
Copy link

expipiplus1 commented Oct 24, 2023

Can we reopen this please?

This is sensitive to updatetime. I can reproduce this with updatetime=100 and holding on an intermediate line for more than 100ms.

FWIW, disabling the CursorHold autocmd fixes it, but this is obviously undesireable (autocmd! context_commentstring_ft CursorHold)

@JoosepAlviste JoosepAlviste reopened this Oct 25, 2023
@JoosepAlviste
Copy link
Owner

JoosepAlviste commented Nov 18, 2023

I was able to reproduce this now, when using the CursorHold autocommand. It looks like setting an option inside CursorHold is causing the issue, e.g., here:

api.nvim_buf_set_option(0, 'commentstring', found_commentstring)

I did a quick search, but couldn't find any other issues or questions about this behaviour, so I unfortunately don't have a good solution for this yet.

I can recommend using a commenting plugin integration, though, and disabling the autocommand like described in the integrations wiki page: https://github.com/JoosepAlviste/nvim-ts-context-commentstring/wiki/Integrations

@JoosepAlviste JoosepAlviste added bug Something isn't working help wanted Extra attention is needed labels Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants