@@ -262,22 +262,30 @@ export def ConvertLinks()
262262enddef
263263
264264
265- export def RemoveLink (range_info: dict <list<list<number> >> = {})
265+ export def g: 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)
268269 if ! empty (link_info)
270+ # TODO : bug distance ahead from the cursor position
271+
269272 var symbol = utils.IsLess (searchpos (' [' , ' n' ), searchpos (' (' , ' n' ))
270273 ? ' ['
271274 : ' ('
272275 # 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
273281 search (symbol)
274- exe $ ' norm! "_da{symbol}'
282+ # exe $ ' norm! "_da{symbol}'
275283
276- # Remove text link
277- search (' ]' , ' bc' )
278- norm! " _x
279- search (' [' , ' bc' )
280- norm! " _x
284+ # # Remove text link
285+ # search (' ]' , ' bc' )
286+ # norm! " _x
287+ # search (' [' , ' bc' )
288+ # norm! " _x
281289 endif
282290enddef
283291
@@ -294,11 +302,13 @@ export def PopupFilter(id: number,
294302 key : string ,
295303 slave_id: number ,
296304 results: list <string> ,
305+ match_id: number ,
297306 ): bool
298307
299308 var maxheight = popup_getoptions (slave_id).maxheight
300309
301310 if key == " \<esc> "
311+ matchdelete (match_id)
302312 ClosePopups ()
303313 return true
304314 endif
@@ -419,7 +429,7 @@ export def PopupFilter(id: number,
419429 return true
420430enddef
421431
422- export def ShowPromptPopup (slave_id: number , links: list <string> , title : string )
432+ export def ShowPromptPopup (slave_id: number , links: list <string> , title : string , match_id: number )
423433 # This could be called by other scripts and its id may be undefined.
424434 InitScriptLocalVars ()
425435 # This is the UI thing
@@ -443,7 +453,7 @@ export def ShowPromptPopup(slave_id: number, links: list<string>, title: string)
443453 }
444454
445455 # Filter
446- opts.filter = (id, key ) = > PopupFilter (id, key , slave_id, links)
456+ opts.filter = (id, key ) = > PopupFilter (id, key , slave_id, links, match_id )
447457
448458 prompt_text = " "
449459 prompt_id = popup_create ([prompt_sign .. prompt_cursor], opts)
@@ -470,6 +480,10 @@ export def CreateLink(type: string = '')
470480 var lB = line (" ']" )
471481 var cB = type == ' line' ? len (getline (lB)) : col (" ']" )
472482
483+ if getregion (getpos (" '[" ), getpos (" ']" ))[0 ] = ~ ' ^\s*$'
484+ return
485+ endif
486+
473487 # The regex reads:
474488 # Take all characters, including newlines, from (l0,c0) to (l1,c1 + 1 )'
475489 const match_pattern = $ ' \%{lA}l\%{cA}c\_.*\%{lB}l\%{cB + 1}c'
@@ -486,7 +500,7 @@ export def CreateLink(type: string = '')
486500 main_id = popup_create (links, links_popup_opts)
487501
488502 # if len (links) > 1
489- ShowPromptPopup (main_id, links, " links: " )
503+ ShowPromptPopup (main_id, links, " links: " , match_id )
490504 # endif
491505enddef
492506
0 commit comments