Skip to content

Commit

Permalink
fix: truncate should be handle before alignment (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 authored Nov 17, 2024
1 parent 476804d commit 56d4a85
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions sideline.el
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,20 @@ FACE, NAME, ON-LEFT, and ORDER for details."
(data (sideline--find-line len-title on-left order))
(pos-start (nth 0 data)) (pos-end (nth 1 data)) (occ-pt (nth 2 data))
(offset (- 0 (sideline--render-data :hscroll)))
;; Truncate
(title (and sideline-truncate
(let* ((win-width (sideline--render-data :win-width))
(used-space (- pos-start occ-pt))
(available-space (- win-width used-space))
(suffix nil))
(when (and sideline-truncate-suffix
(> available-space (sideline--render-data :suffix-width)))
(setq suffix (copy-sequence sideline-truncate-suffix))
(set-text-properties 0 (length suffix)
(text-properties-at (1- (length title)) title)
suffix))
(truncate-string-to-width title available-space 0 nil suffix))))
;; Align left/right
(str (concat
(unless on-left
(propertize " "
Expand All @@ -604,20 +618,6 @@ FACE, NAME, ON-LEFT, and ORDER for details."
`cursor t))
title)))

;; Truncate
(when sideline-truncate
(let* ((win-width (sideline--render-data :win-width))
(used-space (- pos-start occ-pt))
(available-space (1+ (- win-width used-space)))
(suffix nil))
(when (and sideline-truncate-suffix
(> available-space (sideline--render-data :suffix-width)))
(setq suffix (copy-sequence sideline-truncate-suffix))
(set-text-properties 0 (length suffix)
(text-properties-at (1- (length str)) str)
suffix))
(setq str (truncate-string-to-width str available-space 0 nil suffix))))

;; Create overlay
(let* ((len-str (length str))
(empty-ln (= pos-start pos-end))
Expand Down

0 comments on commit 56d4a85

Please sign in to comment.