Skip to content

Commit

Permalink
fix(jump): use nvim_win_set_cursor instead of vim.fn.cursor
Browse files Browse the repository at this point in the history
neovim/neovim#27858 thankfully fixed the
relevant bug, but only for the API function.

Closes #70
  • Loading branch information
ggandor committed Mar 18, 2024
1 parent 812604b commit 74b2ed7
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 75 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ require('leap.user').set_repeat_keys('<enter>', '<backspace>')
<details>
<summary>Workaround for the duplicate cursor bug when autojumping</summary>

Until https://github.com/neovim/neovim/issues/20793 is fixed:
For Neovim versions < 0.10 (https://github.com/neovim/neovim/issues/20793):

```lua
-- Hide the (real) cursor when leaping, and restore it afterwards.
Expand Down Expand Up @@ -418,7 +418,7 @@ some editor options while the plugin is active (`:h leap-events`).
<details>
<summary>Workaround for the duplicate cursor bug when autojumping</summary>

Until https://github.com/neovim/neovim/issues/20793 is fixed:
For Neovim versions < 0.10 (https://github.com/neovim/neovim/issues/20793):

```lua
-- Hide the (real) cursor when leaping, and restore it afterwards.
Expand Down
1 change: 1 addition & 0 deletions fnl/leap/highlight.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
{:priority self.priority.backdrop})))))


; NOTE: Can be removed once minimal required nvim version is >= 0.10. (#70)
(fn M.highlight-cursor [self]
"The cursor is down on the command line during `getchar`,
so we set a temporary highlight on it to see where we are."
Expand Down
9 changes: 6 additions & 3 deletions fnl/leap/jump.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@ the API), make the motion appear to behave as an inclusive one."
(pcall api.nvim_exec_autocmds "CursorMoved" {:group "matchup_matchparen"}))


(fn jump-to! [pos {: winid : add-to-jumplist? : mode
: offset : backward? : inclusive-op?}]
(fn jump-to! [[lnum col]
{: winid : add-to-jumplist? : mode : offset
: backward? : inclusive-op?}]
(local op-mode? (mode:match :o))
; Note: <C-o> will ignore this if the line has not changed (neovim#9874).
(when add-to-jumplist? (vim.cmd "norm! m`"))
(when (not= winid (api.nvim_get_current_win))
(api.nvim_set_current_win winid))
(vim.fn.cursor pos)

(api.nvim_win_set_cursor 0 [lnum (- col 1)]) ; (1,1) -> (1,0)

(when offset (add-offset! offset))
; Since Vim interprets our jump as an exclusive motion (:h exclusive),
; we need custom tweaks to behave as an inclusive one. (This is only
Expand Down
3 changes: 2 additions & 1 deletion fnl/leap/main.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ char separately.
(when-not count
(hl:apply-backdrop backward? ?target-windows))
(do ,...)
(hl:highlight-cursor)
(when (= (vim.fn.has "nvim-0.10") 0)
(hl:highlight-cursor))
(vim.cmd :redraw)))

; Helper functions ///
Expand Down
19 changes: 11 additions & 8 deletions lua/leap/jump.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

134 changes: 73 additions & 61 deletions lua/leap/main.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 74b2ed7

Please sign in to comment.