From 9581dd0f52726b10c923038c28d5fe2170f0d1b6 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 15 Feb 2019 09:53:23 -0800 Subject: [PATCH] Add Arcanist support for highlighting indent change intraline diffs Summary: Ref T13161. See D20181. This allows the intraline highlighter to accept new ">" and "<" spans and apply a different style for them. The input pattern is `list`. Each segment is `pair`, i.e. wrap the next `byte_length` bytes in a span of kind `kind`. Before this change, the possible kinds of segements are `0` (no intraline diff, do not highlight) or `1` (intraline diff, highlight in bright color). D20181 adds `<` (depth decreased) and `>` (depth increased). These are like `1`, but add a different class so the UI can handle them differently. Test Plan: See D20181. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13161 Differential Revision: https://secure.phabricator.com/D20182 --- src/difference/ArcanistDiffUtils.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/difference/ArcanistDiffUtils.php b/src/difference/ArcanistDiffUtils.php index a68a0532..0f798c9e 100644 --- a/src/difference/ArcanistDiffUtils.php +++ b/src/difference/ArcanistDiffUtils.php @@ -89,6 +89,9 @@ final class ArcanistDiffUtils extends Phobject { $highlight_o = ''; $highlight_c = ''; + $depth_in = ''; + $depth_out = ''; + $is_html = false; if ($str instanceof PhutilSafeHTML) { $is_html = true; @@ -107,11 +110,23 @@ final class ArcanistDiffUtils extends Phobject { $stack = array_shift($intra_stack); $s = $e; $e += $stack[1]; - } while ($stack[0] == 0); + } while ($stack[0] === 0); + + switch ($stack[0]) { + case '>': + $open_tag = $depth_in; + break; + case '<': + $open_tag = $depth_out; + break; + default: + $open_tag = $highlight_o; + break; + } } if (!$highlight && !$tag && !$ent && $p == $s) { - $buf .= $highlight_o; + $buf .= $open_tag; $highlight = true; } @@ -139,7 +154,7 @@ final class ArcanistDiffUtils extends Phobject { if ($tag && $str[$i] == '>') { $tag = false; if ($highlight) { - $buf .= $highlight_o; + $buf .= $open_tag; } }