Skip to content

Commit 3ff8d5c

Browse files
committed
fix: move jump target should offset in row first, then in cell
1 parent 80adcd5 commit 3ff8d5c

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

lua/hop-yank/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ M.paste_char1 = function(opts)
6969
return
7070
end
7171

72-
jump_target.move_jump_target(target, opts.hint_offset)
72+
jump_target.move_jump_target(target, 0, opts.hint_offset)
7373

7474
require('hop-yank.yank').paste_from(target, opts.yank_register)
7575
end)

lua/hop/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function M.move_cursor_to(jt, opts)
212212
jt.cursor.col = jt.cursor.col + 1
213213
end
214214

215-
jump_target.move_jump_target(jt, opts.hint_offset)
215+
jump_target.move_jump_target(jt, 0, opts.hint_offset)
216216

217217
-- Update the jump list
218218
-- There is bug with set extmark neovim/neovim#17861

lua/hop/jump_target.lua

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -215,26 +215,13 @@ function M.sort_indirect_jump_targets(indirect_jump_targets, opts)
215215
end
216216

217217
-- Apply an offset on jump target
218-
-- Always offset in cell first, then in line
218+
-- Always offset in row first, then in cell
219219
---@param jt JumpTarget
220-
---@param offset_cell WindowCell|nil
221220
---@param offset_row WindowRow|nil
222-
function M.move_jump_target(jt, offset_cell, offset_row)
223-
local dcell = offset_cell or 0
221+
---@param offset_cell WindowCell|nil
222+
function M.move_jump_target(jt, offset_row, offset_cell)
224223
local drow = offset_row or 0
225-
226-
if dcell ~= 0 then
227-
local line = vim.api.nvim_buf_get_lines(jt.buffer, jt.cursor.row - 1, jt.cursor.row, false)[1]
228-
local line_cells = vim.fn.strdisplaywidth(line)
229-
---@type WindowCell
230-
local new_cell = vim.fn.strdisplaywidth(line:sub(1, jt.cursor.col)) + dcell
231-
if new_cell >= line_cells then
232-
new_cell = line_cells
233-
elseif new_cell < 0 then
234-
new_cell = 0
235-
end
236-
jt.cursor.col = vim.fn.byteidx(line, window.cell2char(line, new_cell))
237-
end
224+
local dcell = offset_cell or 0
238225

239226
if drow ~= 0 then
240227
---@type WindowRow
@@ -248,6 +235,19 @@ function M.move_jump_target(jt, offset_cell, offset_row)
248235
jt.cursor.row = new_row
249236
end
250237
end
238+
239+
if dcell ~= 0 then
240+
local line = vim.api.nvim_buf_get_lines(jt.buffer, jt.cursor.row - 1, jt.cursor.row, false)[1]
241+
local line_cells = vim.fn.strdisplaywidth(line)
242+
---@type WindowCell
243+
local new_cell = vim.fn.strdisplaywidth(line:sub(1, jt.cursor.col)) + dcell
244+
if new_cell >= line_cells then
245+
new_cell = line_cells
246+
elseif new_cell < 0 then
247+
new_cell = 0
248+
end
249+
jt.cursor.col = vim.fn.byteidx(line, window.cell2char(line, new_cell))
250+
end
251251
end
252252

253253
return M

0 commit comments

Comments
 (0)