Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create user option to highlight full candidate line. #208

Merged
merged 9 commits into from
Oct 14, 2020
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ The format is based on [Keep a Changelog].
(`mouse-1`) selects the candidate, and right click (`mouse-3`)
inserts the candidate, just like `RET` and `TAB`, respectively. See
[#113] and [#118].
* The user option `selectrum-extend-current-candidate-highlight`
determines whether to extend the highlighting of the current
candidate until the margin (the default is nil). See [#208].

### Enhancements
* `selectrum-insert-current-candidate` no longer adds inserted
Expand Down Expand Up @@ -189,6 +192,7 @@ The format is based on [Keep a Changelog].
[#193]: https://github.com/raxod502/selectrum/pull/193
[#197]: https://github.com/raxod502/selectrum/pull/197
[#198]: https://github.com/raxod502/selectrum/pull/198
[#208]: https://github.com/raxod502/selectrum/pull/208
[#212]: https://github.com/raxod502/selectrum/issues/212
[#213]: https://github.com/raxod502/selectrum/pull/213

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ matching and case-insensitive matching.
* The currently selected candidate is highlighted with the face
`selectrum-current-candidate`. If you don't like the color, you can
adjust it to taste.
* By default, only the displayed text is highlighted. If you wish to
extend the highlight until the margin, you can set
`selectrum-extend-current-candidate-highlight` to `t`.
* By default, the part of each candidate that matches your input is
highlighted with the face `selectrum-primary-highlight`. There is
also `selectrum-secondary-highlight`, which is not used by default
Expand Down
32 changes: 24 additions & 8 deletions selectrum.el
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ setting."
(string :tag "Indicator string")
(face :tag "Indicator face"))))

(defcustom selectrum-extend-current-candidate-highlight nil
"Whether to extend highlighting of the current candidate until the margin.

Nil (the default) means to only highlight the displayed text."
:type 'boolean)

;;;; Utility functions

;;;###autoload
Expand Down Expand Up @@ -989,7 +995,9 @@ candidate."
candidate)))
(right-margin (get-text-property
0 'selectrum-candidate-display-right-margin
candidate)))
candidate))
(formatting-current-candidate
(equal index highlighted-index)))
;; Add the ability to interact with candidates via the mouse.
(add-text-properties
0 (length displayed-candidate)
Expand All @@ -1009,7 +1017,7 @@ candidate."
(selectrum-insert-current-candidate ,(1+ index))))
keymap))
displayed-candidate)
(when (equal index highlighted-index)
(when formatting-current-candidate
(setq displayed-candidate
(copy-sequence displayed-candidate))
;; Avoid trampling highlighting done by
Expand Down Expand Up @@ -1046,24 +1054,32 @@ candidate."
(insert
(propertize curr-index 'face 'minibuffer-prompt))))
(insert displayed-candidate)
(when right-margin
(cond
(right-margin
(insert
(concat
(propertize
" "
'face
(when (and right-margin
(equal index highlighted-index))
(when formatting-current-candidate
'selectrum-current-candidate)
'display
`(space :align-to (- right-fringe
,(string-width right-margin)
selectrum-right-margin-padding)))
(propertize right-margin
'face
(when (and right-margin
(equal index highlighted-index))
'selectrum-current-candidate))))))
(when formatting-current-candidate
'selectrum-current-candidate)))))
((and selectrum-extend-current-candidate-highlight
formatting-current-candidate)
(insert
(propertize
" "
'face 'selectrum-current-candidate
'display
`(space :align-to (- right-fringe
selectrum-right-margin-padding)))))))
(cl-incf index))
(buffer-string))))

Expand Down