Skip to content

Commit 436af74

Browse files
committed
compat: enable diff section syntax highlighting
by introducing high priority overlays
1 parent 7a292e4 commit 436af74

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

pr-review-render.el

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

123+
(defun pr-review--restore-diff-syntax-overlays ()
124+
"Restore diff syntax highlighting overlays with high priority.
125+
This ensures diff syntax highlighting overlays override section highlight overlays."
126+
(remove-overlays (point-min) (point-max) 'pr-review-diff-syntax t)
127+
(let ((pos (point-min)))
128+
(while (< pos (point-max))
129+
(when-let ((face (get-text-property pos 'pr-review-diff-syntax-face)))
130+
(let* ((end (or (next-single-property-change pos 'pr-review-diff-syntax-face nil (point-max))
131+
(point-max)))
132+
(ov (make-overlay pos end)))
133+
(overlay-put ov 'pr-review-diff-syntax t)
134+
(overlay-put ov 'font-lock-face face)
135+
(overlay-put ov 'priority 1) ; Higher than magit-section-highlight (priority 0)
136+
(overlay-put ov 'evaporate t)
137+
(setq pos end)))
138+
(setq pos (or (next-single-property-change pos 'pr-review-diff-syntax-face nil (point-max))
139+
(point-max))))))
140+
123141
(defun pr-review--insert-html (body &optional indent extra-face)
124142
"Insert html content BODY.
125143
INDENT is an optional number, if provided,
@@ -213,9 +231,14 @@ MARGIN count of spaces are added at the start of every line."
213231
(dolist (ol (overlays-in (point-min) (point-max)))
214232
(when (eq (overlay-get ol 'diff-mode) 'syntax)
215233
(when-let ((face (overlay-get ol 'face)))
216-
(add-face-text-property (overlay-start ol)
217-
(overlay-end ol)
218-
face))))
234+
;; Store syntax face info for later high-priority overlay recreation
235+
(put-text-property (overlay-start ol)
236+
(overlay-end ol)
237+
'pr-review-diff-syntax-face face)
238+
;; Also set font-lock-face for Magit v4.4.0+ compatibility
239+
(put-text-property (overlay-start ol)
240+
(overlay-end ol)
241+
'font-lock-face face))))
219242
(goto-char (point-min))
220243
(remove-overlays (point-min) (point-max) 'diff-mode 'syntax)))
221244

@@ -961,6 +984,10 @@ it can be displayed in a single line."
961984
(propertize (alist-get 'title pr)'font-lock-face 'pr-review-title-face)))
962985
(insert "\n")
963986
(pr-review--insert-pr-body pr diff))
987+
;; Create high-priority overlays for diff syntax highlighting
988+
(pr-review--restore-diff-syntax-overlays)
989+
;; Add hook to restore overlays after section highlighting
990+
(add-hook 'post-command-hook #'pr-review--restore-diff-syntax-overlays nil t)
964991
;; need to call after this inserting all sections
965992
(pr-review--hide-generated-files))
966993

0 commit comments

Comments
 (0)