Patchwork [2,of,6] hgweb: add line wrapping switch to file source view

login
register
mail settings
Submitter Alexander Plavin
Date July 12, 2013, 9:07 p.m.
Message ID <506b516ecf16d9e97fda.1373663259@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/1847/
State Superseded, archived
Headers show

Comments

Alexander Plavin - July 12, 2013, 9:07 p.m.
# HG changeset patch
# User Alexander Plavin <me@aplavin.ru>
# Date 1373630293 -14400
#      Fri Jul 12 15:58:13 2013 +0400
# Node ID 506b516ecf16d9e97fdaa92dfa9193f5da358d2f
# Parent  f639ae607bd76f71e3ae2e481edd09623324adc9
hgweb: add line wrapping switch to file source view

Patch

diff -r f639ae607bd7 -r 506b516ecf16 mercurial/templates/paper/filerevision.tmpl
--- a/mercurial/templates/paper/filerevision.tmpl	Fri Jul 12 16:01:11 2013 +0400
+++ b/mercurial/templates/paper/filerevision.tmpl	Fri Jul 12 15:58:13 2013 +0400
@@ -67,8 +67,9 @@ 
 </table>
 
 <div class="overflow">
+<div class="sourcefirst linewraptoggle">line wrap: <a class="linewraplink" href="javascript:toggleLinewrap()">on</a></div>
 <div class="sourcefirst"> line source</div>
-<pre class="sourcelines">{text%fileline}</pre>
+<pre class="sourcelines wrap">{text%fileline}</pre>
 <div class="sourcelast"></div>
 </div>
 </div>
diff -r f639ae607bd7 -r 506b516ecf16 mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js	Fri Jul 12 16:01:11 2013 +0400
+++ b/mercurial/templates/static/mercurial.js	Fri Jul 12 15:58:13 2013 +0400
@@ -269,3 +269,21 @@ 
 	document.getElementById('diffstatdetails').style.display = flag ? 'inline' : 'none';
 	document.getElementById('diffstatexpand').style.display = flag ? 'none' : 'inline';
 }
+
+function toggleLinewrap() {
+    var new_flag;
+    var nodes = document.querySelectorAll('.sourcelines');
+    for (var i = 0; i < nodes.length; i++) {
+        new_flag = !nodes[i].classList.contains('wrap');
+        if (new_flag) {
+            nodes[i].classList.add('wrap');
+        } else {
+            nodes[i].classList.remove('wrap');
+        }
+    }
+
+    var links = document.getElementsByClassName('linewraplink');
+    for (var i = 0; i < links.length; i++) {
+        links[i].innerHTML = new_flag ? 'on' : 'off';
+    }
+}
diff -r f639ae607bd7 -r 506b516ecf16 mercurial/templates/static/style-paper.css
--- a/mercurial/templates/static/style-paper.css	Fri Jul 12 16:01:11 2013 +0400
+++ b/mercurial/templates/static/style-paper.css	Fri Jul 12 15:58:13 2013 +0400
@@ -214,11 +214,18 @@ 
   position: relative;
 }
 
+.wrap > span {
+    white-space: pre-wrap;
+}
+
+.linewraptoggle {
+    float: right;
+}
+
 .sourcelines > span {
   display: inline-block;
   width: 100%;
   padding: 1px 0px;
-  white-space: pre-wrap;
   counter-increment: lineno;
 }
 
diff -r f639ae607bd7 -r 506b516ecf16 tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t	Fri Jul 12 16:01:11 2013 +0400
+++ b/tests/test-hgweb-commands.t	Fri Jul 12 15:58:13 2013 +0400
@@ -667,8 +667,9 @@ 
   </table>
   
   <div class="overflow">
+  <div class="sourcefirst linewraptoggle">line wrap: <a class="linewraplink" href="javascript:toggleLinewrap()">on</a></div>
   <div class="sourcefirst"> line source</div>
-  <pre class="sourcelines">
+  <pre class="sourcelines wrap">
   <span id="l1">foo</span><a href="#l1"></a></pre>
   <div class="sourcelast"></div>
   </div>
diff -r f639ae607bd7 -r 506b516ecf16 tests/test-highlight.t
--- a/tests/test-highlight.t	Fri Jul 12 16:01:11 2013 +0400
+++ b/tests/test-highlight.t	Fri Jul 12 15:58:13 2013 +0400
@@ -136,8 +136,9 @@ 
   </table>
   
   <div class="overflow">
+  <div class="sourcefirst linewraptoggle">line wrap: <a class="linewraplink" href="javascript:toggleLinewrap()">on</a></div>
   <div class="sourcefirst"> line source</div>
-  <pre class="sourcelines">
+  <pre class="sourcelines wrap">
   <span id="l1"><span class="c">#!/usr/bin/env python</span></span><a href="#l1"></a>
   <span id="l2"></span><a href="#l2"></a>
   <span id="l3"><span class="sd">&quot;&quot;&quot;Fun with generators. Corresponding Haskell implementation:</span></span><a href="#l3"></a>