Skip to content

Commit e6f9218

Browse files
committed
fix font rendering for magit v4.4.0+
1 parent 469e2e1 commit e6f9218

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

pr-review-render.el

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@
120120
(t
121121
(shr-generic td)))))))))
122122

123+
(defun pr-review--copy-face-to-font-lock-face (start end)
124+
"Copy 'face text properties to 'font-lock-face between START and END.
125+
This ensures compatibility with Magit v4.4.0+ which uses font-lock-face
126+
instead of face for rendering in magit-section-mode buffers."
127+
(let ((pos start))
128+
(while (< pos end)
129+
(let* ((next-change (or (next-single-property-change pos 'face nil end) end))
130+
(face-value (get-text-property pos 'face)))
131+
(when face-value
132+
(put-text-property pos next-change 'font-lock-face face-value))
133+
(setq pos next-change)))))
134+
123135
(defun pr-review--insert-html (body &optional indent extra-face)
124136
"Insert html content BODY.
125137
INDENT is an optional number, if provided,
@@ -157,7 +169,9 @@ in addition to other faces."
157169
(forward-line))))
158170
;; additional face for the inserted region
159171
(when extra-face
160-
(add-face-text-property start end extra-face))))
172+
(add-face-text-property start end extra-face))
173+
;; Convert face properties to font-lock-face for Magit v4.4.0+
174+
(pr-review--copy-face-to-font-lock-face start end)))
161175

162176
(defun pr-review--maybe-insert-reactions (reaction-group &optional indent)
163177
"Insert REACTION-GROUP if not nil.
@@ -196,6 +210,9 @@ MARGIN count of spaces are added at the start of every line."
196210
(insert "\n"))
197211
(unless (eq major-mode lang-mode)
198212
(funcall lang-mode))
213+
;; Explicitly enable font-lock-mode for Magit v4.4.0+
214+
(unless font-lock-mode
215+
(font-lock-mode 1))
199216
(condition-case-unless-debug nil
200217
(font-lock-ensure)
201218
(error nil)))
@@ -212,14 +229,33 @@ MARGIN count of spaces are added at the start of every line."
212229
(save-excursion
213230
(dolist (ol (overlays-in (point-min) (point-max)))
214231
(when (eq (overlay-get ol 'diff-mode) 'syntax)
215-
(when-let ((face (overlay-get ol 'face)))
216-
(add-face-text-property (overlay-start ol)
217-
(overlay-end ol)
218-
face))))
232+
;; Magit v4.4.0+ uses font-lock-face instead of face
233+
;; Check both properties for backwards compatibility
234+
(let ((face (or (overlay-get ol 'font-lock-face)
235+
(overlay-get ol 'face))))
236+
(when face
237+
;; Add to both face and font-lock-face for compatibility
238+
(add-face-text-property (overlay-start ol)
239+
(overlay-end ol)
240+
face)
241+
;; Also explicitly set font-lock-face
242+
(put-text-property (overlay-start ol)
243+
(overlay-end ol)
244+
'font-lock-face face)))))
219245
(goto-char (point-min))
220246
(remove-overlays (point-min) (point-max) 'diff-mode 'syntax)))
221247

222248
(let ((res (buffer-substring 2 (point-max)))) ;; start at 2: skip first newline
249+
;; Magit v4.4.0+ uses font-lock-face; ensure face property is also set
250+
(when (eq lang-mode 'diff-mode)
251+
(let ((start 0))
252+
(while (< start (length res))
253+
(let* ((next-change (or (next-single-property-change start 'font-lock-face res)
254+
(length res)))
255+
(font-lock-face (get-text-property start 'font-lock-face res)))
256+
(when font-lock-face
257+
(put-text-property start next-change 'face font-lock-face res))
258+
(setq start next-change)))))
223259
(when margin
224260
(setq res (replace-regexp-in-string (rx bol) (make-string margin ?\s) res)))
225261
res)))
@@ -231,7 +267,9 @@ MARGIN count of spaces are added at the start of every line."
231267
(insert (pr-review--fontify body lang-mode margin))
232268
(setq end (point))
233269
(when extra-face
234-
(add-face-text-property start end extra-face))))
270+
(add-face-text-property start end extra-face))
271+
;; Convert face properties to font-lock-face for Magit v4.4.0+
272+
(pr-review--copy-face-to-font-lock-face start end)))
235273

236274
(defun pr-review--insert-diff (diff)
237275
"Insert pull request diff DIFF, wash it using magit."
@@ -950,6 +988,12 @@ it can be displayed in a single line."
950988
(mapc 'pr-review--insert-in-diff-checkrun-annotation
951989
(let-alist context .annotations.nodes))))))
952990

991+
(defun pr-review--convert-face-to-font-lock-face ()
992+
"Convert all 'face text properties to 'font-lock-face for Magit v4.4.0+.
993+
This ensures all UI elements (titles, usernames, timestamps, buttons, etc.)
994+
are properly displayed in magit-section-mode buffers."
995+
(pr-review--copy-face-to-font-lock-face (point-min) (point-max)))
996+
953997
(defun pr-review--insert-pr (pr diff)
954998
"Insert pr buffer with PR and DIFF."
955999
(setq pr-review--char-pixel-width (shr-string-pixel-width "-"))
@@ -961,6 +1005,8 @@ it can be displayed in a single line."
9611005
(propertize (alist-get 'title pr)'face 'pr-review-title-face)))
9621006
(insert "\n")
9631007
(pr-review--insert-pr-body pr diff))
1008+
;; Convert all face properties to font-lock-face for Magit v4.4.0+
1009+
(pr-review--convert-face-to-font-lock-face)
9641010
;; need to call after this inserting all sections
9651011
(pr-review--hide-generated-files))
9661012

pr-review.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ Which means that all sections are collapsed."
130130
(setq-local magit-hunk-section-map nil
131131
magit-file-section-map nil
132132
magit-diff-highlight-hunk-body nil)
133+
;; Enable font-lock-mode for Magit v4.4.0+ which uses font-lock-face
134+
(font-lock-mode 1)
133135
(setq-local imenu-create-index-function #'magit--imenu-create-index
134136
imenu-default-goto-function #'magit--imenu-goto-function
135137
magit--imenu-item-types '(pr-review--review-section

0 commit comments

Comments
 (0)