mirror of
https://github.com/org-roam/org-roam
synced 2025-09-22 16:20:54 -05:00
(fix)completions: fix highlighting of formatted/truncated strings (#1895)
* (fix)org-roam-unlinked-references-section: Use truncate-string-ellipsis The variable can be set to a unicode ellipsis. * (fix)org-roam-node-read--format-entry: Fix highlighting for truncation Fix #1801. The truncated part of the string is made invisible. Matching on the whole string remains possible. * (fix)org-roam-format-template: Preserve string properties like format If the variable value carries properties itself, these properties take precedence. Display templates can be properties with this change. (setq org-roam-node-display-template (concat (propertize "${title:*}" 'face 'font-lock-keyword-face) " " (propertize "${tags:10}" 'face 'font-lock-constant-face)))
This commit is contained in:
@@ -536,12 +536,20 @@ Uses `org-roam-node-display-template' to format the entry."
|
||||
;; empty string results in an empty string and misalignment for candidates that
|
||||
;; don't have some field. This uses the actual display string, made of spaces
|
||||
;; when the field-value is "" so that we actually take up space.
|
||||
(if (or (not field-width) (equal field-value ""))
|
||||
field-value
|
||||
;; Remove properties from the full candidate string, otherwise the display
|
||||
;; formatting with pre-propertized field-values gets messed up.
|
||||
(let ((display-string (truncate-string-to-width field-value field-width 0 ?\s)))
|
||||
(propertize (substring-no-properties field-value) 'display display-string))))))))
|
||||
(unless (or (not field-width) (equal field-value ""))
|
||||
(let* ((truncated (truncate-string-to-width field-value field-width 0 ?\s))
|
||||
(tlen (length truncated))
|
||||
(len (length field-value)))
|
||||
(if (< tlen len)
|
||||
;; Make the truncated part of the string invisible. If strings
|
||||
;; are pre-propertized with display or invisible properties, the
|
||||
;; formatting may get messed up. Ideally, truncated strings are
|
||||
;; not preformatted with these properties. Face properties are
|
||||
;; allowed without restriction.
|
||||
(put-text-property tlen len 'invisible t field-value)
|
||||
;; If the string wasn't truncated, but padded, use this string instead.
|
||||
(setq field-value truncated))))
|
||||
field-value)))))
|
||||
|
||||
(defun org-roam-node-read--process-display-format (format)
|
||||
"Pre-calculate minimal widths needed by the FORMAT string."
|
||||
|
Reference in New Issue
Block a user