From ca1775b4687c2ad22e588d04435911f4b0faf0b3 Mon Sep 17 00:00:00 2001 From: vrana Date: Wed, 22 Aug 2012 23:26:03 -0700 Subject: [PATCH] Display context in changeset gaps Summary: I quite often wonder what's inside these gaps displayed in changeset. In which method I am? Is it a while loop or a foreach? Maybe I'm in a class but the project doesn't have a sctrict policy of one class per file so what's the name of the class? I've experimented with bunch of rules: - Always display 0 indentation: useless for one class per file. - Always display 1 indentation: weird inside global functions. - Display closest lower indentation: works best. I'm not sure about highlighting the context. I like highlighting but maybe in this case subtler monochrome text will work better. Test Plan: Browsed bunch of diffs, loved it. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3371 --- .../parser/DifferentialChangesetParser.php | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/applications/differential/parser/DifferentialChangesetParser.php b/src/applications/differential/parser/DifferentialChangesetParser.php index 4b4046b306..78ed2f2d40 100644 --- a/src/applications/differential/parser/DifferentialChangesetParser.php +++ b/src/applications/differential/parser/DifferentialChangesetParser.php @@ -1363,6 +1363,28 @@ final class DifferentialChangesetParser { $highlight_new = array_flip($highlight_new); } + // We need to go backwards to properly indent whitespace in this code: + // + // 0: class C { + // 1: + // 1: function f() { + // 2: + // 2: return; + // + $depths = array(); + $last_depth = 0; + for ($ii = $range_start + $range_len - 1; $ii >= $range_start; $ii--) { + // We need to expand tabs to process mixed indenting and to round + // correctly later. + $line = str_replace("\t", " ", $this->new[$ii]['text']); + $trimmed = ltrim($line); + if ($trimmed != '') { + // We round down to flatten "/**" and " *". + $last_depth = floor((strlen($line) - strlen($trimmed)) / 2); + } + $depths[$ii] = $last_depth; + } + for ($ii = $range_start; $ii < $range_start + $range_len; $ii++) { if (empty($mask[$ii])) { // If we aren't going to show this line, we've just entered a gap. @@ -1414,12 +1436,12 @@ final class DifferentialChangesetParser { ), 'Show All '.$len.' Lines'); - if ($len > 40) { - $is_last_block = false; - if ($ii + $len >= $rows) { - $is_last_block = true; - } + $is_last_block = false; + if ($ii + $len >= $rows) { + $is_last_block = true; + } + if ($len > 40) { $contents[] = javelin_render_tag( 'a', array( @@ -1436,6 +1458,17 @@ final class DifferentialChangesetParser { : "\xE2\x96\xBC Show 20 Lines"); } + if (!$is_last_block && $depths[$ii + $len]) { + for ($l = $ii + $len - 1; $l >= $ii; $l--) { + $line = $this->new[$l]['text']; + if ($depths[$l] < $depths[$ii + $len] && trim($line) != '') { + $contents[] = ''.$this->newRender[$l].''; + break; + } + } + + } + $container = javelin_render_tag( 'tr', array(