improved the full diff view a bit more

This commit is contained in:
hyung-hwan 2015-01-28 02:52:29 +00:00
parent 5fc888924c
commit 58bb110c92
2 changed files with 71 additions and 27 deletions

View File

@ -131,6 +131,51 @@ $this->load->view (
<div id="code_diff_mainarea_result"> <div id="code_diff_mainarea_result">
<?php <?php
function format_diff ($a, $b, $css_class)
{
if ($b == '') return htmlspecialchars($a);
$cc = '';
$diffstart = -1;
$aalen = strlen($a);
$bblen = strlen($b);
for ($i = 0; $i < $aalen && $i < $bblen; $i++)
{
if ($a[$i] == $b[$i])
{
if ($diffstart >= 0)
{
$cc .= sprintf ('<span class="%s">', $css_class);
$cc .= htmlspecialchars(substr($a, $diffstart, $i - $diffstart));
$cc .= '</span>';
$diffstart = -1;
}
$cc .= htmlspecialchars($a[$i]);
}
else
{
if ($diffstart < 0) $diffstart = $i;
}
}
if ($diffstart >= 0)
{
$cc .= sprintf ('<span class="%s">', $css_class);
$cc .= htmlspecialchars(substr($a, $diffstart, $aalen - $diffstart));
$cc .= '</span>';
}
else
{
if ($aalen > $bblen)
{
$cc .= htmlspecialchars(substr ($a, $aalen, $aalen - $bblen));
}
}
return $cc;
}
if (!$fullview) if (!$fullview)
{ {
print '<table id="code_diff_mainarea_result_table">'; print '<table id="code_diff_mainarea_result_table">';
@ -289,20 +334,16 @@ else
print "<pre class='prettyprint lang-{$fileext}' style='width: 100%' id='code_diff_mainarea_result_fulldiffold'>"; print "<pre class='prettyprint lang-{$fileext}' style='width: 100%' id='code_diff_mainarea_result_fulldiffold'>";
foreach ($file['content'] as $x) foreach ($file['content'] as $x)
{
if (array_key_exists('rev1line', $x))
{ {
$diffclass = array_key_exists('rev1diffclass', $x)? $x['rev1diffclass']: 'diff'; $diffclass = array_key_exists('rev1diffclass', $x)? $x['rev1diffclass']: 'diff';
print "<span class='{$diffclass}'>"; print "<span class='{$diffclass}'>";
if ($x['rev1line'] == '') print '&nbsp;';
else print htmlspecialchars($x['rev1line']); if ($diffclass == 'diffchanged')
print "</span>"; print format_diff ($x['rev1line'], $x['rev2line'], 'diffchangedold');
}
else else
{ print htmlspecialchars($x['rev1line']);
print $x['rev1lineno'];
} print "</span>\n";
print "\n";
} }
printf ("</div>"); printf ("</div>");
print '</pre>'; print '</pre>';
@ -330,23 +371,17 @@ else
print "<pre class='prettyprint lang-{$fileext}' style='width: 100%' id='code_diff_mainarea_result_fulldiffnew'>"; print "<pre class='prettyprint lang-{$fileext}' style='width: 100%' id='code_diff_mainarea_result_fulldiffnew'>";
foreach ($file['content'] as $x) foreach ($file['content'] as $x)
{
if (array_key_exists('rev2line', $x))
{ {
$diffclass = array_key_exists('rev2diffclass', $x)? $x['rev2diffclass']: 'diff'; $diffclass = array_key_exists('rev2diffclass', $x)? $x['rev2diffclass']: 'diff';
print "<span class='{$diffclass}'>"; print "<span class='{$diffclass}'>";
if ($x['rev2line'] == '') print '&nbsp;'; if ($diffclass == 'diffchanged')
else print htmlspecialchars($x['rev2line']); print format_diff ($x['rev2line'], $x['rev1line'], 'diffchangednew');
print "</span>";
}
else else
{ print htmlspecialchars($x['rev2line']);
print $x['rev2lineno'];
} print "</span>\n";
print "\n";
} }
print '</pre>'; print '</pre>';

View File

@ -374,3 +374,12 @@
padding-left:15px; padding-left:15px;
margin: 0; margin: 0;
} }
#code_diff_mainarea_result_fullview .diffchangedold {
text-decoration: line-through;
}
#code_diff_mainarea_result_fullview .diffchangednew {
//background-color:#ffff00;
text-decoration: underline;
}