@@ -355,9 +355,17 @@ is either labeled (C) or not (B).
355
355
(when aot ?
356
356
(resolve - conflicts targets )))))
357
357
358
-
359
- (fn light - up - beacons [targets ?start ?end ]
360
- (for [i (or ?start 1 ) (or ?end (length targets ))]
358
+ (fn with - highlight - chores [opts ... ]
359
+ (do (local opts (or opts {}))
360
+ (hl:cleanup opts.hl - affected - windows )
361
+ (hl:apply - backdrop (or opts.backdrop - ranges []))
362
+ (do ,... )
363
+ (hl:highlight - cursor )
364
+ (vim.cmd :redraw)))
365
+
366
+ (fn light - up - beacons [targets opts ]
367
+ (local opts (or opts {}))
368
+ (for [i (or opts.start 1 ) (or opts.end (length targets ))]
361
369
(local target (. targets i ))
362
370
(case target.beacon
363
371
[offset virttext ]
@@ -485,13 +493,29 @@ is either labeled (C) or not (B).
485
493
(when vars.errmsg (echo vars.errmsg ))
486
494
(exit )))
487
495
488
- (macro with - highlight - chores [... ]
489
- `(do (hl:cleanup hl - affected - windows )
490
- (when-not count
491
- (hl:apply - backdrop backward ? ?target - windows ))
492
- (do ,... )
493
- (hl:highlight - cursor )
494
- (vim.cmd :redraw)))
496
+ (local backdrop - ranges [])
497
+ (when (and (pcall api.nvim_get_hl_by_name hl.group.backdrop false ) (not count ))
498
+ (if ?target - windows
499
+ (each [_ winid (ipairs ?target - windows )]
500
+ (local wininfo (. (vim.fn.getwininfo winid ) 1 ))
501
+ (local range {:bufnr wininfo.bufnr
502
+ :startrow (dec wininfo.topline )
503
+ :startcol 0
504
+ :endrow (dec wininfo.botline )
505
+ :endcol -1 })
506
+ (table . insert backdrop - ranges range ))
507
+ (let [[curline curcol ] (map dec [(vim.fn.line "." ) (vim.fn.col "." )])
508
+ [win - top win - bot ] [(dec (vim.fn.line "w0" )) (dec (vim.fn.line "w$" ))]
509
+ [startrow startcol endrow endcol ] (if backward ?
510
+ [win - top 0 curline curcol ]
511
+ [curline (inc curcol ) win - bot -1 ])]
512
+ (local wininfo (. (vim.fn.getwininfo 0 ) 1 ))
513
+ (local range {:bufnr wininfo.bufnr
514
+ :startrow startrow
515
+ :startcol startcol
516
+ :endrow endrow
517
+ :endcol endcol })
518
+ (table . insert backdrop - ranges range ))))
495
519
496
520
; Helper functions ///
497
521
@@ -643,7 +667,7 @@ is either labeled (C) or not (B).
643
667
(values start end ))))
644
668
645
669
(fn get - first - pattern - input []
646
- (with - highlight - chores (echo "" )) ; clean up the command line
670
+ (with - highlight - chores { : backdrop - ranges : hl - affected - windows } (echo "" )) ; clean up the command line
647
671
(case (get - input - by - keymap prompt )
648
672
; Here we can handle any other modifier key as "zeroth" input,
649
673
; if the need arises.
@@ -657,7 +681,7 @@ is either labeled (C) or not (B).
657
681
658
682
(fn get - second - pattern - input [targets ]
659
683
(when (<= (length targets ) max - phase - one - targets )
660
- (with - highlight - chores (light - up - beacons targets )))
684
+ (with - highlight - chores { : backdrop - ranges : hl - affected - windows } (light - up - beacons targets )))
661
685
(get - input - by - keymap prompt ))
662
686
663
687
(fn get - full - pattern - input []
@@ -679,9 +703,8 @@ is either labeled (C) or not (B).
679
703
(when targets.label -set
680
704
(set- label - states targets {: group - offset }))
681
705
(set- beacons targets {:aot? vars.aot ? : no - labels ? : user - given - targets ?})
682
- (with - highlight - chores
683
- (local (start end ) (get - highlighted - idx - range targets no - labels ?))
684
- (light - up - beacons targets start end )))
706
+ (local (start end ) (get - highlighted - idx - range targets no - labels ?))
707
+ (with - highlight - chores {: backdrop - ranges : hl - affected - windows } (light - up - beacons targets {: start : end })))
685
708
; ---
686
709
(fn loop [group - offset first - invoc ?]
687
710
(display group - offset )
@@ -745,9 +768,8 @@ is either labeled (C) or not (B).
745
768
; ---
746
769
(fn display []
747
770
(set- beacons targets {: no - labels ? :aot? vars.aot ? : user - given - targets ?})
748
- (with - highlight - chores
749
- (local (start end ) (get - highlighted - idx - range targets no - labels ?))
750
- (light - up - beacons targets start end )))
771
+ (local (start end ) (get - highlighted - idx - range targets no - labels ?))
772
+ (with - highlight - chores {: backdrop - ranges : hl - affected - windows } (light - up - beacons targets {: start : end })))
751
773
; ---
752
774
(fn get - new - idx [idx in ]
753
775
(if (contains ? spec - keys.next_target in ) (min (inc idx ) (length targets ))
@@ -854,7 +876,7 @@ is either labeled (C) or not (B).
854
876
targets **
855
877
; The action callback should expect a list in this case.
856
878
; It might also get user input, so keep the beacons highlighted.
857
- (do (with - highlight - chores (light - up - beacons targets ** ))
879
+ (do (with - highlight - chores { : backdrop - ranges : hl - affected - windows } (light - up - beacons targets ** ))
858
880
(do- action targets ** )))
859
881
(exit ))
860
882
0 commit comments