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

Getting a 'Column value outside range' when using HopChar1 on a soft wrapped line #84

Open
brneor opened this issue Aug 27, 2024 · 2 comments · May be fixed by #97
Open

Getting a 'Column value outside range' when using HopChar1 on a soft wrapped line #84

brneor opened this issue Aug 27, 2024 · 2 comments · May be fixed by #97

Comments

@brneor
Copy link

brneor commented Aug 27, 2024

Describe the bug
When I try to use the remaps to t on a line that is soft wrapped I get an error:

E5108: Error executing lua: /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:239: Column value outside
 range
stack traceback:
        [C]: in function 'nvim_win_set_cursor'
        /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:239: in function 'move_cursor_to'
        /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:259: in function 'callback'
        /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:363: in function 'refine_hints'
        /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:327: in function 'hint_with_callback'
        /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:258: in function 'hint_with_regex'
        /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:447: in function 'hint_char1'
        /root/.config/nvim/lua/plugins/hop.lua:51: in function </root/.config/nvim/lua/plugins/hop.lua:50>

To Reproduce

  1. Install hop.nvim
  2. Map t to <cmd>:lua require'hop'.hint_char1({direction = require'hop.hint'.HintDirection.AFTER_CURSOR,current_line_only = true, hint_offset = -1})<cr>
  3. Open any file that has a long line
  4. set wrap
  5. Go to the start of the long line, type t, a character that's on the wrapped part of the line and then the hop hint letter.
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "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
  -- stylua: ignore
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath })
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)

-- install plugins
local plugins = {
  { "AstroNvim/AstroNvim", import = "astronvim.plugins" },

  {
    "smoka7/hop.nvim",
    version = "*",
    event = "BufRead",
    config = function()
      require("hop").setup({
        keys = "tnplvmdhsefucwyxriao",
        multi_windows = false,
      })
      vim.api.nvim_set_keymap("", "s", "<cmd>HopWord<cr>", { silent = true })
      vim.api.nvim_set_keymap("", "h", "<cmd>HopChar2<cr>", { silent = true })
      vim.api.nvim_set_keymap("", "L", "<cmd>HopLine<cr>", { silent = true })
      vim.api.nvim_set_keymap("", "l", "<cmd>HopLineStart<cr>", { silent = true })
      vim.api.nvim_set_keymap("", "<C-w>", "<cmd>HopWordCurrentLineAC<cr>", { silent = true })
      vim.api.nvim_set_keymap("", "<C-b>", "<cmd>HopWordCurrentLineBC<cr>", { silent = true })
      vim.api.nvim_set_keymap(
        "",
        "f",
        "<cmd>:lua require'hop'.hint_char1({direction = require'hop.hint'.HintDirection.AFTER_CURSOR,current_line_only = true})<cr>",
        { silent = true }
      )
      vim.api.nvim_set_keymap(
        "",
        "F",
        "<cmd>:lua require'hop'.hint_char1({direction = require'hop.hint'.HintDirection.BEFORE_CURSOR,current_line_only = true})<cr>",
        { silent = true }
      )
      vim.api.nvim_set_keymap(
        "",
        "t",
        "<cmd>:lua require'hop'.hint_char1({direction = require'hop.hint'.HintDirection.AFTER_CURSOR,current_line_only = true,hint_offset = -1})<cr>",
        { silent = true }
      )
      vim.api.nvim_set_keymap(
        "",
        "T",
        "<cmd>:lua require'hop'.hint_char1({direction = require'hop.hint'.HintDirection.BEFORE_CURSOR,current_line_only = true,hint_offset = 1})<cr>",
        { silent = true }
      )
    end,
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- add anything else here (autocommands, vim.filetype, etc.)

Expected behavior
Cursor should jump to chosen character.

Screenshots

361463062-a50c2475-1e2a-4ca7-9e16-97cff9054c64.mp4

version (please complete the following information):

  • Nvim version: v0.10.1
  • hop.nvim version: v2.7.1

Additional context
Without setting the hint_offset the issue does not occurs. Also, I initially thought that was a AstroNvim issue and reported here. There's some insight from the dev there.

@myarcana
Copy link

myarcana commented Dec 22, 2024

This issue only happens if the line breaks earlier than the last column of the window, so you also :set linebreak to replicate this issue.

@brneor
Copy link
Author

brneor commented Dec 30, 2024

I tested the implementation and indeed solved my issue.

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

Successfully merging a pull request may close this issue.

2 participants