Skip to content

Commit 5efe985

Browse files
committed
refactor(utils/get-char-from): always use strcharpart; use pcall
IDK what I was thinking in 7eeeb3f, `strgetchar` is exactly as broken as `strcharpart` without `skipcc`. `pcall` to make it work with all 0.10 versions, without needing an extra-precise `has` check.
1 parent 4f1696a commit 5efe985

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

fnl/leap/util.fnl

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

5252

53+
; Issue A: failing to calculate the start index properly when composite
54+
; characters precede the match
55+
; Issue B: failing to extract a composite character from the match
56+
; (n̂ becomes n)
57+
58+
; charidx w/countcc charidx
59+
; -----------------------------------------------------------
60+
; strgetchar B AB
61+
; strcharpart (stable) B AB
62+
; strcharpart w/skipcc (0.10+) A OK
63+
64+
; It is not worth the fuss (i.e., branching when calling `charidx`) to
65+
; make this half-broken on stable.
66+
5367
(fn get-char-from [str idx] ; zero-based (<- vim.fn.charidx())
54-
(if (= (vim.fn.has "nvim-0.10") 1)
55-
; `skipcc` parameter (essential) is only available from 0.10.
56-
(vim.fn.strcharpart str idx 1 1)
57-
; `strgetchar` has a bug with composite unicode chars (#108).
58-
(let [nr (vim.fn.strgetchar str idx)]
59-
(if (= nr -1) ""
60-
(vim.fn.nr2char nr)))))
68+
; `skipcc` is only available from 0.10.<something>.
69+
(local (ok? res) (pcall vim.fn.strcharpart str idx 1 1))
70+
(if ok? res (vim.fn.strcharpart str idx 1)))
6171

6272

6373
; Input

lua/leap/util.lua

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

0 commit comments

Comments
 (0)