Skip to content

Commit 662a200

Browse files
committed
Fixed bug in RemoveLink()
1 parent 78b0644 commit 662a200

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

lib/links.vim

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -265,27 +265,27 @@ enddef
265265
export def RemoveLink(range_info: dict<list<list<number>>> = {})
266266
const link_info = empty(range_info) ? IsLink() : range_info
267267
# TODO: it may not be the best but it works so far
268-
echom "link_info: " .. string(link_info)
269268
if !empty(link_info)
270-
# TODO: bug distance ahead from the cursor position
271-
272-
var symbol = utils.IsLess(searchpos('[', 'n'), searchpos('(', 'n'))
273-
? '['
274-
: '('
269+
# Find the closest between [ and (
270+
var symbol = ''
271+
if searchpos('[', 'nW') == [0, 0]
272+
symbol = '('
273+
elseif searchpos('(', 'nW') == [0, 0]
274+
symbol = '['
275+
else
276+
symbol = utils.IsLess(searchpos('[', 'nW'), searchpos('(', 'nW'))
277+
? '['
278+
: '('
279+
endif
275280
# Remove actual link
276-
#
277-
echom "pos [: " .. string(searchpos('[', 'n'))
278-
echom "pos (: " .. string(searchpos('(', 'n'))
279-
echom utils.IsLess(searchpos('[', 'n'), searchpos('(', 'n'))
280-
echom "symbol: " .. symbol
281281
search(symbol)
282-
# exe $'norm! "_da{symbol}'
282+
exe $'norm! "_da{symbol}'
283283

284-
# # Remove text link
285-
# search(']', 'bc')
286-
# norm! "_x
287-
# search('[', 'bc')
288-
# norm! "_x
284+
# Remove text link
285+
search(']', 'bc')
286+
norm! "_x
287+
search('[', 'bc')
288+
norm! "_x
289289
endif
290290
enddef
291291

0 commit comments

Comments
 (0)