Stricter refinement threshold and logic

This commit is contained in:
Timothy 2024-09-15 01:49:35 +08:00
parent c042ae2e33
commit 15c71d1189
Signed by: tec
SSH key fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A

View file

@ -52,8 +52,11 @@ If nil, the additions will be displayed via empty overlays."
"Whether to refine diffs with finer changes."
:type 'boolean)
(defcustom inline-diff-refine-similarity 0.5
"The similarity threshold for refining diffs."
(defcustom inline-diff-refine-similarity 0.7
"The similarity threshold for refining diffs, between 0.0 and 1.0.
This is the proportion of characters that must remain in common between
the old and new versions in order for refinement highlighting to be shown."
:type 'number)
;;;; Faces
@ -509,8 +512,9 @@ SO-FAR is a list of overlays already seen."
(mapconcat #'cdr (cdar last-op-ov) nil))))
(new-chars (vconcat (inline-diff--char-positions
(mapconcat #'cdr (cdar op-ov) nil))))
(max-length (max (length old-chars) (length new-chars)))
(char-diff (inline-diff--myers-diff old-chars new-chars :test #'eql :key #'cdr))
deletions insertions del-ins-unique-points)
deletions insertions)
(dolist (op char-diff)
(pcase (car op)
('delete
@ -518,13 +522,15 @@ SO-FAR is a list of overlays already seen."
('insert
(setq insertions (nconc insertions (cdr op))))))
(when (and deletions
(<= (length deletions) (* inline-diff-refine-similarity (length old-chars))))
(<= (length deletions) (* (- 1 inline-diff-refine-similarity) (length old-chars)))
(<= (* inline-diff-refine-similarity max-length) (length old-chars)))
(inline-diff--show-refinement
(cdr last-op-ov)
(inline-diff--seq-ranges deletions #'car)
'inline-diff-refine-removed))
(when (and insertions
(<= (length insertions) (* inline-diff-refine-similarity (length new-chars))))
(<= (length insertions) (* (- 1 inline-diff-refine-similarity) (length new-chars)))
(<= (* inline-diff-refine-similarity max-length) (length new-chars)))
(inline-diff--show-refinement
(cdr op-ov)
(inline-diff--seq-ranges insertions #'car)