Skip to content

Commit 6303b82

Browse files
committed
genericize set-beacon-for-labeled
1 parent 1340684 commit 6303b82

File tree

2 files changed

+263
-251
lines changed

2 files changed

+263
-251
lines changed

fnl/leap/main.fnl

+28-19
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,17 @@ char separately.
196196
(+ (ch1:len) (ch2:len)))))
197197

198198

199-
(fn set-beacon-for-labeled [target {: user-given-targets? : aot?}]
200-
(let [offset (if aot? (get-label-offset target) 0) ; user-given-targets implies (not aot)
201-
pad (if (or user-given-targets? aot?) "" " ")
199+
(fn set-beacon-for-labeled [target]
200+
(let [offset (or target.beacon-offset 0)
201+
pad (or target.pad "")
202202
label (or (. opts.substitute_chars target.label) target.label)
203-
text (.. label pad)
203+
text (or target.text (.. label pad))
204204
virttext (case target.label-state
205205
:selected [[text hl.group.label-selected]]
206206
:active-primary [[text hl.group.label-primary]]
207207
:active-secondary [[text hl.group.label-secondary]]
208-
:inactive (if (and aot? (not opts.highlight_unlabeled_phase_one_targets))
209-
; In this case, "no highlight" should
210-
; unambiguously signal "no further keystrokes
211-
; needed", so it is mandatory to show all labeled
212-
; positions in some way.
213-
[[(.. " " pad) hl.group.label-secondary]]
214-
:else nil))]
208+
; only show text on inactive targets if explicitly set
209+
:inactive (if target.text [[target.text hl.group.label-secondary]] :else nil))]
215210
(set target.beacon (when virttext [offset virttext]))))
216211

217212

@@ -344,13 +339,13 @@ is either labeled (C) or not (B).
344339
other (set-beacon-to-match-hl target)))))))))
345340

346341

347-
(fn set-beacons [targets {: no-labels? : user-given-targets? : aot?}]
342+
(fn set-beacons [targets {: no-labels? : aot?}]
348343
(if (and no-labels? (. targets 1 :chars)) ; user-given targets might not have :chars
349344
(each [_ target (ipairs targets)]
350345
(set-beacon-to-match-hl target))
351346
(do (each [_ target (ipairs targets)]
352347
(if target.label
353-
(set-beacon-for-labeled target {: user-given-targets? : aot?})
348+
(set-beacon-for-labeled target)
354349

355350
(and aot? opts.highlight_unlabeled_phase_one_targets)
356351
(set-beacon-to-match-hl target)))
@@ -725,7 +720,7 @@ is either labeled (C) or not (B).
725720
; setting the initial label states if using `spec-keys.repeat_search`.
726721
(when targets.label-set
727722
(set-label-states targets {: group-offset}))
728-
(set-beacons targets {:aot? vars.aot? : no-labels? : user-given-targets?})
723+
(set-beacons targets {:aot? vars.aot? : no-labels?})
729724
(local (start end) (get-highlighted-idx-range targets no-labels?))
730725
(with-highlight-chores (fn [] (light-up-beacons targets {: start : end}))))
731726
; ---
@@ -790,7 +785,7 @@ is either labeled (C) or not (B).
790785
(doto (. targets i) (tset :label nil) (tset :beacon nil))))))
791786
; ---
792787
(fn display []
793-
(set-beacons targets {: no-labels? :aot? vars.aot? : user-given-targets?})
788+
(set-beacons targets {: no-labels? :aot? vars.aot?})
794789
(local (start end) (get-highlighted-idx-range targets no-labels?))
795790
(with-highlight-chores (fn [] (light-up-beacons targets {: start : end}))))
796791
; ---
@@ -864,13 +859,27 @@ is either labeled (C) or not (B).
864859
(prepare-targets targets))
865860
(do
866861
(when (> (length targets) max-phase-one-targets)
867-
(set vars.aot? false))
862+
(do
863+
(set vars.aot? false)
864+
(each [_ target (ipairs targets)]
865+
(set target.beacon-offset 0))))
868866
(populate-sublists targets)
869867
(each [_ sublist (pairs targets.sublists)]
870868
(prepare-targets sublist))
871-
(doto targets
872-
(set-initial-label-states)
873-
(set-beacons {:aot? vars.aot?}))))
869+
(set-initial-label-states targets)
870+
(each [_ target (ipairs targets)]
871+
(if vars.aot?
872+
(do
873+
(set target.beacon-offset (get-label-offset target))
874+
(when (and (not opts.highlight_unlabeled_phase_one_targets) (= target.label-state :inactive))
875+
; In this case, "no highlight" should
876+
; unambiguously signal "no further keystrokes
877+
; needed", so it is mandatory to show all labeled
878+
; positions in some way.
879+
(set target.text " ")
880+
))
881+
(when (not user-given-targets?) (set target.pad " "))))
882+
(set-beacons targets {:aot? vars.aot?})))
874883
(local in2 (or ?in2 (get-second-pattern-input targets))) ; REDRAW
875884
(when-not in2
876885
(exit-early))

0 commit comments

Comments
 (0)