Make newly added blocks align correctly in side-by-side view
Make newly added blocks align correctly in side-by-side view

Added blocks of code (so all '+' lines) are aligning incorrectly - they
appear one line higher than where they actually are, which is confusing
because it generally makes the code look like it's syntactially invalid.

This change does fix it, but I'm really don't think that it's the right
solution. Labeling it as a HACK for now to revisit later.

--- a/include/git/FileDiff.class.php
+++ b/include/git/FileDiff.class.php
@@ -643,8 +643,11 @@
 				continue;
 			switch($d[0]) {
 				case '@':
-					if($currentDiff)
+					if($currentDiff) {
+						if (count($currentDiff['left']) == 0 && count($currentDiff['right']) > 0)
+							$currentDiff['line']++; 	// HACK to make added blocks align correctly
 						$diffs[] = $currentDiff;
+					}
 					$comma = strpos($d, ",");
 					$line = -intval(substr($d, 2, $comma-2));
 					$currentDiff = array("line" => $line,
@@ -667,8 +670,11 @@
 					break;
 			}
 		}
-		if($currentDiff)
+		if($currentDiff) {
+			if (count($currentDiff['left']) == 0 && count($currentDiff['right']) > 0)
+				$currentDiff['line']++;		// HACK to make added blocks align correctly
 			$diffs[] = $currentDiff;
+		}
 
 		//
 		// iterate over diffs

comments