Skip to content

Commit 7eeeb3f

Browse files
committed
fix: use custom fn in place of strcharpart
This partially reverts 66f055a. The lack of `skipcc` makes the plugin practically unusable if composing characters are present in the text, and as this applies to the current latest stable Neovim release (0.9.1), the regression is unacceptable. Closes #175
1 parent 24c0f4d commit 7eeeb3f

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

fnl/leap/highlight.fnl

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(local {: inc
22
: dec
33
: get-cursor-pos
4-
: strcharpart}
4+
: get-char-from}
55
(require "leap.util"))
66

77
(local api vim.api)
@@ -61,8 +61,8 @@
6161
so we set a temporary highlight on it to see where we are."
6262
(let [[line col &as pos] (or ?pos (get-cursor-pos))
6363
line-str (vim.fn.getline line)
64-
start (vim.fn.charidx line-str (- col 1))
65-
ch-at-curpos (case (strcharpart line-str start 1)
64+
char-idx (vim.fn.charidx line-str (- col 1))
65+
ch-at-curpos (case (get-char-from line-str char-idx)
6666
"" " " ; on an emtpy line
6767
ch ch)
6868
id (api.nvim_buf_set_extmark 0 self.ns (dec line) (dec col)

fnl/leap/search.fnl

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
: dec
33
: get-cursor-pos
44
: ->representative-char
5-
: strcharpart}
5+
: get-char-from}
66
(require "leap.util"))
77

88
(local api vim.api)
@@ -117,11 +117,11 @@ Dynamic attributes
117117
(when (not= line prev-match.line)
118118
(set line-str (vim.fn.getline line)))
119119
(local start (vim.fn.charidx line-str (- col 1)))
120-
(case (strcharpart line-str start 1)
120+
(case (get-char-from line-str start)
121121
"" (when (= col 1) ; on an empty line
122122
(table.insert targets {: wininfo : pos :chars ["\n"]
123123
:empty-line? true}))
124-
ch1 (let [ch2 (case (strcharpart line-str (+ start 1) 1)
124+
ch1 (let [ch2 (case (get-char-from line-str (+ start 1))
125125
"" "\n" ; before EOL
126126
ch ch)
127127
xxx? (and

fnl/leap/util.fnl

+7-5
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@
5050
(if opts.case_sensitive ch* (vim.fn.tolower ch*)))
5151

5252

53-
(fn strcharpart [src start len]
54-
(if (= (vim.fn.has "nvim-0.10") 1)
55-
(vim.fn.strcharpart src start len 1)
56-
(vim.fn.strcharpart src start len)))
53+
; Note: on 0.10+ we could replace this with vim.fn.strcharpart (with
54+
; `skipcc`).
55+
(fn get-char-from [str idx] ; zero-based (<- vim.fn.charidx())
56+
(local nr (vim.fn.strgetchar str idx))
57+
(if (= nr -1) ""
58+
(vim.fn.nr2char nr)))
5759

5860

5961
; Input
@@ -116,6 +118,6 @@
116118
:get_enterable_windows get-enterable-windows
117119
: get-eq-class-of
118120
: ->representative-char
119-
: strcharpart
121+
: get-char-from
120122
: get-input
121123
: get-input-by-keymap}

lua/leap/highlight.lua

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lua/leap/search.lua

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lua/leap/util.lua

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)