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

strange cursor move when telescope closes #2319

Open
Tracked by #2850
Martinits opened this issue Jan 12, 2023 · 6 comments · Fixed by #2336 · May be fixed by #2850
Open
Tracked by #2850

strange cursor move when telescope closes #2319

Martinits opened this issue Jan 12, 2023 · 6 comments · Fixed by #2336 · May be fixed by #2850
Labels
bug Something isn't working

Comments

@Martinits
Copy link

Description

When telescope closes, the cursor will strangely move right by 1 column. That will influence some other plugins like https://github.com/AckslD/nvim-neoclip.lua . Neoclip uses telescope to provide a selection of yank history, and paste the selected item where it launched. This strange move makes neoclip paste to a wrong position.(AckslD/nvim-neoclip.lua#96).
Also, if you launch require('telescope.builtin').help_tag, choose one and close the help window, the cursor will move right.

Neovim version

NVIM v0.8.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by builduser

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Operating system and version

archlinux

Telescope version / branch / rev

master

checkhealth telescope

telescope: require("telescope.health").check()
========================================================================
## Checking for required plugins
  - OK: plenary installed.
  - OK: nvim-treesitter installed.

## Checking external dependencies
  - OK: rg: found ripgrep 13.0.0
  - OK: fd: found fd 8.6.0

## ===== Installed extensions =====

## Telescope Extension: `fzf`
  - OK: lib working as expected
  - OK: file_sorter correctly configured
  - OK: generic_sorter correctly configured

## Telescope Extension: `macroscope`
  - INFO: No healthcheck provided

## Telescope Extension: `neoclip`
  - INFO: No healthcheck provided

Steps to reproduce

  • nvim -nu minimal.lua
  • type something
  • place cursor to somewhere you remember
  • :Telescope help_tags, and choose any
  • close help window
  • cursor will move right

Expected behavior

No response

Actual behavior

described above

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      {
        'nvim-telescope/telescope.nvim',
        requires = {
          'nvim-lua/plenary.nvim',
          { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' },
        },
      },
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
      display = { non_interactive = true },
    },
  }
end
_G.load_config = function()
  require('telescope').setup()
  require('telescope').load_extension('fzf')
  -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing Telescope and dependencies.")
  vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end
load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
@Martinits Martinits added the bug Something isn't working label Jan 12, 2023
@cristiansofronie
Copy link
Contributor

This is weird. The problem seems to be when calling actions.close. The
function contains the following line which sets the cursor:

pcall(a.nvim_win_set_cursor, original_win_id, { original_cursor[1], original_cursor[2] + 1 })

If I would wrap it in defer_fn the cursor would be shifted all the times,
that is also when hitting or . If I wrap the vim.cmd calls from
internal.man_pages and internal.help_tags in defer_fn the problem would
go away.

The following line in actions.close gets the cursor position where to move:

local cursor_valid, original_cursor = pcall(a.nvim_win_get_cursor, original_win_id)

I printed the position to the screen and it seems to be correct in both cases.
I used :lua print(vim.inspect(vim.api.nvim_win_get_cursor(0))) before calling
the picker and checked the value with the one shown by the
print(vim.inspect(original_cursor)) I inserted after the call to
nvim_win_get_cursor.

The problem as far as I can tell seems to be with nvim_win_set_cursor having
some weird race conditions.

@cristiansofronie
Copy link
Contributor

If in actions.close I replace:

pcall(a.nvim_win_set_cursor, original_win_id, { original_cursor[1], original_cursor[2] + 1})

with

vim.defer_fn(function()
  pcall(a.nvim_win_set_cursor, original_win_id, { original_cursor[1], original_cursor[2] })
end, 0)

The + 1 was added in commit b4c45e8. But if
we defer the call to nvim_win_set_cursor it doesn't seem to be required any
more.

@Martinits
Copy link
Author

I can confirm that will fix this issue.

@Conni2461
Copy link
Member

needs to be reverted in #2538 because it broke custom actions that rely that the picker is actually closed with actions.close

@Conni2461 Conni2461 reopened this May 25, 2023
@danielo515
Copy link

@Conni2461 is there a plan to re-fix this issue?

@jamestrew
Copy link
Contributor

This column off by one error also happens when opening files in normal mode.

@jamestrew jamestrew linked a pull request Jan 6, 2024 that will close this issue
7 tasks
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
5 participants