telescope-insert-path.nvim icon indicating copy to clipboard operation
telescope-insert-path.nvim copied to clipboard

Cursor position at second to last

Open uloco opened this issue 11 months ago • 1 comments

whatever command I use, my cursor always lands at the second to last position of the inserted path.

what/ever/path/i/inserted
                       ^---- my cursor lands here

uloco avatar Jan 09 '25 22:01 uloco

Thanks for reporting the bug!

Can you please provide a reproducible config? It may be due to some vim settings you use.

With the below config it works as expected. You may add some option in the config.

(run like nvim -u repro.lua)

-- repro.lua
vim.env.GIT_CONFIG_GLOBAL = ""
vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    {
      "nvim-telescope/telescope.nvim",
      dependencies = {
        "kiyoon/telescope-insert-path.nvim",
      },
      config = function()
        local path_actions = require("telescope_insert_path")

        require("telescope").setup({
          defaults = {
            mappings = {
              n = {
                ["["] = path_actions.insert_reltobufpath_visual,
                ["]"] = path_actions.insert_abspath_visual,
                ["{"] = path_actions.insert_reltobufpath_insert,
                ["}"] = path_actions.insert_abspath_insert,
                ["-"] = path_actions.insert_reltobufpath_normal,
                ["="] = path_actions.insert_abspath_normal,
              },
            },
          },
        })
      end,
    },
  },
})

kiyoon avatar Jan 10 '25 02:01 kiyoon

Hello,

Using the same repro.lua file but with the following mapping:

            mappings = {
              i = {
                ["{"] = path_actions.insert_reltobufpath_insert,
              },
            },

(of course that is weird to map } in insert mode, but that "works")

Hitting Ctrl-R and then i (to insert before the cursor) gives me the following behavior:

  • the cursor is at the second-to-last character of the inserted path (just as reported in this issue)
  • the inserted path is actually inserted after the cursor
  • I end up in normal mode, not in insert mode

Maybe there is something off with coming out of insert mode from Telescope?

Reylak avatar Jul 04 '25 12:07 Reylak

I think it this related to this Telescope bug: https://github.com/nvim-telescope/telescope.nvim/issues/2319. It looks like we need to use vim.schedule to manipulate the cursor.

Reylak avatar Jul 04 '25 15:07 Reylak