hgweb: file diff and changesets views behave like file source view
This gives all the benefits introduced before for file source view, namely
code selection without line numbers and correct indents, highlighting line
which is linked to, long lines wrapping.
Implementation strategy is also the same as for file source view: all the
lines are put in a sigle pre tag with span's for each line. Correct line
numbering (same as before this patch) is achieved with nested CSS counters.
--- a/mercurial/templates/paper/changeset.tmpl Fri Jul 12 23:47:56 2013 +0400
+++ b/mercurial/templates/paper/changeset.tmpl Sat Jul 13 00:57:10 2013 +0400
@@ -77,10 +77,11 @@
</table>
<div class="overflow">
-<div class="sourcefirst"> line diff</div>
-
+<div class="sourcefirst"> line diff</div>
+<div class="stripes2 diffblocks">
{diff}
</div>
+</div>
</div>
</div>
--- a/mercurial/templates/paper/filediff.tmpl Fri Jul 12 23:47:56 2013 +0400
+++ b/mercurial/templates/paper/filediff.tmpl Sat Jul 13 00:57:10 2013 +0400
@@ -68,11 +68,12 @@
</table>
<div class="overflow">
-<div class="sourcefirst"> line diff</div>
-
+<div class="sourcefirst"> line diff</div>
+<div class="stripes2 diffblocks">
{diff}
</div>
</div>
</div>
+</div>
{footer}
--- a/mercurial/templates/paper/map Fri Jul 12 23:47:56 2013 +0400
+++ b/mercurial/templates/paper/map Sat Jul 13 00:57:10 2013 +0400
@@ -84,11 +84,15 @@
<td class="source"><a href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}</td>
</tr>'
-diffblock = '<div class="source bottomline parity{parity}"><pre>{lines}</pre></div>'
-difflineplus = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> <span class="plusline">{line|escape}</span>'
-difflineminus = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> <span class="minusline">{line|escape}</span>'
-difflineat = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> <span class="atline">{line|escape}</span>'
-diffline = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}'
+diffblock = '<div class="bottomline inc-lineno"><pre class="sourcelines wrap">{lines}</pre></div>'
+difflineplus = '
+ <span id="{lineid}" class="plusline">{strip(line|escape, '\r\n')}</span><a href="#{lineid}"></a>'
+difflineminus = '
+ <span id="{lineid}" class="minusline">{strip(line|escape, '\r\n')}</span><a href="#{lineid}"></a>'
+difflineat = '
+ <span id="{lineid}" class="atline">{strip(line|escape, '\r\n')}</span><a href="#{lineid}"></a>'
+diffline = '
+ <span id="{lineid}">{strip(line|escape, '\r\n')}</span><a href="#{lineid}"></a>'
comparisonblock ='
<tbody class="block">
--- a/mercurial/templates/static/style-paper.css Fri Jul 12 23:47:56 2013 +0400
+++ b/mercurial/templates/static/style-paper.css Sat Jul 13 00:57:10 2013 +0400
@@ -216,6 +216,7 @@
.sourcelines {
font-size: 90%;
position: relative;
+ counter-reset: lineno;
}
.wrap > span {
@@ -226,6 +227,9 @@
float: right;
}
+.diffblocks { counter-reset: lineno; }
+.diffblocks > div { counter-increment: lineno; }
+
.sourcelines > span {
display: inline-block;
width: 100%;
@@ -245,7 +249,7 @@
font-size: smaller;
color: #999;
text-align: right;
- content: counter(lineno);
+ content: counters(lineno, ".");
}
.sourcelines > span:target {
--- a/tests/test-hgweb-commands.t Fri Jul 12 23:47:56 2013 +0400
+++ b/tests/test-hgweb-commands.t Sat Jul 13 00:57:10 2013 +0400
@@ -450,17 +450,18 @@
</table>
<div class="overflow">
- <div class="sourcefirst"> line diff</div>
-
- <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1"> 1.1</a> <span class="minusline">--- /dev/null Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l1.2" id="l1.2"> 1.2</a> <span class="plusline">+++ b/da/foo Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l1.3" id="l1.3"> 1.3</a> <span class="atline">@@ -0,0 +1,1 @@
- </span><a href="#l1.4" id="l1.4"> 1.4</a> <span class="plusline">+foo
- </span></pre></div><div class="source bottomline parity1"><pre><a href="#l2.1" id="l2.1"> 2.1</a> <span class="minusline">--- /dev/null Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l2.2" id="l2.2"> 2.2</a> <span class="plusline">+++ b/foo Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l2.3" id="l2.3"> 2.3</a> <span class="atline">@@ -0,0 +1,1 @@
- </span><a href="#l2.4" id="l2.4"> 2.4</a> <span class="plusline">+foo
- </span></pre></div>
+ <div class="sourcefirst"> line diff</div>
+ <div class="stripes2 diffblocks">
+ <div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+ <span id="l1.1" class="minusline">--- /dev/null Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
+ <span id="l1.2" class="plusline">+++ b/da/foo Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
+ <span id="l1.3" class="atline">@@ -0,0 +1,1 @@</span><a href="#l1.3"></a>
+ <span id="l1.4" class="plusline">+foo</span><a href="#l1.4"></a></pre></div><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+ <span id="l2.1" class="minusline">--- /dev/null Thu Jan 01 00:00:00 1970 +0000</span><a href="#l2.1"></a>
+ <span id="l2.2" class="plusline">+++ b/foo Thu Jan 01 00:00:00 1970 +0000</span><a href="#l2.2"></a>
+ <span id="l2.3" class="atline">@@ -0,0 +1,1 @@</span><a href="#l2.3"></a>
+ <span id="l2.4" class="plusline">+foo</span><a href="#l2.4"></a></pre></div>
+ </div>
</div>
</div>
--- a/tests/test-hgweb-diffs.t Fri Jul 12 23:47:56 2013 +0400
+++ b/tests/test-hgweb-diffs.t Sat Jul 13 00:57:10 2013 +0400
@@ -142,17 +142,18 @@
</table>
<div class="overflow">
- <div class="sourcefirst"> line diff</div>
-
- <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1"> 1.1</a> <span class="minusline">--- /dev/null Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l1.2" id="l1.2"> 1.2</a> <span class="plusline">+++ b/a Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l1.3" id="l1.3"> 1.3</a> <span class="atline">@@ -0,0 +1,1 @@
- </span><a href="#l1.4" id="l1.4"> 1.4</a> <span class="plusline">+a
- </span></pre></div><div class="source bottomline parity1"><pre><a href="#l2.1" id="l2.1"> 2.1</a> <span class="minusline">--- /dev/null Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l2.2" id="l2.2"> 2.2</a> <span class="plusline">+++ b/b Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l2.3" id="l2.3"> 2.3</a> <span class="atline">@@ -0,0 +1,1 @@
- </span><a href="#l2.4" id="l2.4"> 2.4</a> <span class="plusline">+b
- </span></pre></div>
+ <div class="sourcefirst"> line diff</div>
+ <div class="stripes2 diffblocks">
+ <div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+ <span id="l1.1" class="minusline">--- /dev/null Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
+ <span id="l1.2" class="plusline">+++ b/a Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
+ <span id="l1.3" class="atline">@@ -0,0 +1,1 @@</span><a href="#l1.3"></a>
+ <span id="l1.4" class="plusline">+a</span><a href="#l1.4"></a></pre></div><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+ <span id="l2.1" class="minusline">--- /dev/null Thu Jan 01 00:00:00 1970 +0000</span><a href="#l2.1"></a>
+ <span id="l2.2" class="plusline">+++ b/b Thu Jan 01 00:00:00 1970 +0000</span><a href="#l2.2"></a>
+ <span id="l2.3" class="atline">@@ -0,0 +1,1 @@</span><a href="#l2.3"></a>
+ <span id="l2.4" class="plusline">+b</span><a href="#l2.4"></a></pre></div>
+ </div>
</div>
</div>
@@ -271,13 +272,14 @@
</table>
<div class="overflow">
- <div class="sourcefirst"> line diff</div>
-
- <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1"> 1.1</a> <span class="minusline">--- a/b Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l1.2" id="l1.2"> 1.2</a> <span class="plusline">+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l1.3" id="l1.3"> 1.3</a> <span class="atline">@@ -1,1 +0,0 @@
- </span><a href="#l1.4" id="l1.4"> 1.4</a> <span class="minusline">-b
- </span></pre></div>
+ <div class="sourcefirst"> line diff</div>
+ <div class="stripes2 diffblocks">
+ <div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+ <span id="l1.1" class="minusline">--- a/b Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
+ <span id="l1.2" class="plusline">+++ /dev/null Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
+ <span id="l1.3" class="atline">@@ -1,1 +0,0 @@</span><a href="#l1.3"></a>
+ <span id="l1.4" class="minusline">-b</span><a href="#l1.4"></a></pre></div>
+ </div>
</div>
</div>
</div>
@@ -403,19 +405,20 @@
</table>
<div class="overflow">
- <div class="sourcefirst"> line diff</div>
-
- <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1"> 1.1</a> new file mode 100644
- <a href="#l1.2" id="l1.2"> 1.2</a> <span class="minusline">--- /dev/null
- </span><a href="#l1.3" id="l1.3"> 1.3</a> <span class="plusline">+++ b/a
- </span><a href="#l1.4" id="l1.4"> 1.4</a> <span class="atline">@@ -0,0 +1,1 @@
- </span><a href="#l1.5" id="l1.5"> 1.5</a> <span class="plusline">+a
- </span></pre></div><div class="source bottomline parity1"><pre><a href="#l2.1" id="l2.1"> 2.1</a> new file mode 100644
- <a href="#l2.2" id="l2.2"> 2.2</a> <span class="minusline">--- /dev/null
- </span><a href="#l2.3" id="l2.3"> 2.3</a> <span class="plusline">+++ b/b
- </span><a href="#l2.4" id="l2.4"> 2.4</a> <span class="atline">@@ -0,0 +1,1 @@
- </span><a href="#l2.5" id="l2.5"> 2.5</a> <span class="plusline">+b
- </span></pre></div>
+ <div class="sourcefirst"> line diff</div>
+ <div class="stripes2 diffblocks">
+ <div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+ <span id="l1.1">new file mode 100644</span><a href="#l1.1"></a>
+ <span id="l1.2" class="minusline">--- /dev/null</span><a href="#l1.2"></a>
+ <span id="l1.3" class="plusline">+++ b/a</span><a href="#l1.3"></a>
+ <span id="l1.4" class="atline">@@ -0,0 +1,1 @@</span><a href="#l1.4"></a>
+ <span id="l1.5" class="plusline">+a</span><a href="#l1.5"></a></pre></div><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+ <span id="l2.1">new file mode 100644</span><a href="#l2.1"></a>
+ <span id="l2.2" class="minusline">--- /dev/null</span><a href="#l2.2"></a>
+ <span id="l2.3" class="plusline">+++ b/b</span><a href="#l2.3"></a>
+ <span id="l2.4" class="atline">@@ -0,0 +1,1 @@</span><a href="#l2.4"></a>
+ <span id="l2.5" class="plusline">+b</span><a href="#l2.5"></a></pre></div>
+ </div>
</div>
</div>
@@ -536,11 +539,12 @@
</table>
<div class="overflow">
- <div class="sourcefirst"> line diff</div>
-
- <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1"> 1.1</a> old mode 100644
- <a href="#l1.2" id="l1.2"> 1.2</a> new mode 100755
- </pre></div>
+ <div class="sourcefirst"> line diff</div>
+ <div class="stripes2 diffblocks">
+ <div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+ <span id="l1.1">old mode 100644</span><a href="#l1.1"></a>
+ <span id="l1.2">new mode 100755</span><a href="#l1.2"></a></pre></div>
+ </div>
</div>
</div>
</div>
--- a/tests/test-hgweb-removed.t Fri Jul 12 23:47:56 2013 +0400
+++ b/tests/test-hgweb-removed.t Sat Jul 13 00:57:10 2013 +0400
@@ -115,13 +115,14 @@
</table>
<div class="overflow">
- <div class="sourcefirst"> line diff</div>
-
- <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1"> 1.1</a> <span class="minusline">--- a/a Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l1.2" id="l1.2"> 1.2</a> <span class="plusline">+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l1.3" id="l1.3"> 1.3</a> <span class="atline">@@ -1,1 +0,0 @@
- </span><a href="#l1.4" id="l1.4"> 1.4</a> <span class="minusline">-a
- </span></pre></div>
+ <div class="sourcefirst"> line diff</div>
+ <div class="stripes2 diffblocks">
+ <div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+ <span id="l1.1" class="minusline">--- a/a Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
+ <span id="l1.2" class="plusline">+++ /dev/null Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
+ <span id="l1.3" class="atline">@@ -1,1 +0,0 @@</span><a href="#l1.3"></a>
+ <span id="l1.4" class="minusline">-a</span><a href="#l1.4"></a></pre></div>
+ </div>
</div>
</div>
@@ -215,13 +216,14 @@
</table>
<div class="overflow">
- <div class="sourcefirst"> line diff</div>
-
- <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1"> 1.1</a> <span class="minusline">--- a/a Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l1.2" id="l1.2"> 1.2</a> <span class="plusline">+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
- </span><a href="#l1.3" id="l1.3"> 1.3</a> <span class="atline">@@ -1,1 +0,0 @@
- </span><a href="#l1.4" id="l1.4"> 1.4</a> <span class="minusline">-a
- </span></pre></div>
+ <div class="sourcefirst"> line diff</div>
+ <div class="stripes2 diffblocks">
+ <div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+ <span id="l1.1" class="minusline">--- a/a Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
+ <span id="l1.2" class="plusline">+++ /dev/null Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
+ <span id="l1.3" class="atline">@@ -1,1 +0,0 @@</span><a href="#l1.3"></a>
+ <span id="l1.4" class="minusline">-a</span><a href="#l1.4"></a></pre></div>
+ </div>
</div>
</div>
</div>