[PATCH] Allow C&P from file revision in hgweb without also copying line numbers
Laurens Holst
laurens.nospam at grauw.nl
Tue Oct 11 17:45:20 CDT 2011
Hey Jordi,
Let me make sure if I understand correctly, you’re trying to change the
behaviour of *triple-clicking* on the line? Because that’s rather
obscure, you can already just select it by dragging, and it is not
exactly such a super-frequent operation that it becomes a hassle to do.
Now if you were trying to fix selecting multiple lines… :)
Tables have complicated size calculations and do incremental loading
reflows, which can get really slow and ugly for large pages. Matt
already pointed out some performance problems with this for the annotate
page. I’m not sure spewing out a separate table for every line will
improve the situation, it certainly has the smell of ‘dirty hack’ all
over it. Did you test it with exceptionally large changesets?
Anyway, in Firefox and Internet Explorer (not Chrome, didn’t test
Safari) I can also get the desired triple-clicking behaviour when I wrap
the line number and line contents in separate spans, and give the first
an inline-block style.
<style>
.a { display: inline-block; }
</style>
<pre><span class="a"><a class="linenr" href="#l1.1" id="l1.1">
1.1</a></span><span style="color:#cc0000;"> --- a/NOTICE Sat Oct 08
22:16:13 2011 +0200
</span><span class="a"><a class="linenr" href="#l1.2" id="l1.2">
1.2</a></span><span style="color:#008800;"> +++ b/NOTICE Sat Oct 08
22:17:25 2011 +0200
</span></pre>
Is that good enough? I think it is acceptable (if at all necessary).
Otherwise, maybe try to find a solution along those lines that also
works in Chrome (actually, float: left; works in Chrome but not Firefox
;p). I would *really* avoid tables as much as possible, it’s like
getting a wire through a needle with a sledgehammer.
Re. the annotate view, probably the reason to use a table there is the
variable width of the first column because it includes a user name.
Otherwise, for performance reasons I would say divs + spans are way
preferable.
~Laurens
Op 11-10-2011 18:15, Jordi Gutiérrez Hermoso schreef:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso<jordigh at octave.org>
> # Date 1318312976 18000
> # Node ID df28d9372ba72bc84a5f78c4e993127a5234284b
> # Parent c133296b0a3a7d6372457fdd37c6b60c2b7c3bca
> Allow C&P from file revision in hgweb without also copying line numbers
>
> It's useful from the web interface to be able to highlight code in
> order to copy and paste it elsewhere. Unfortunately with the current
> web interface, this has the annoying result of also including the line
> numbers, so the pasted code will have them too and requires further
> surgery to work.
>
> This patch puts the line numbers for file revisions in a separate<td>
> inside a table, and the actual code in another<td>, so there are only
> two<td>s in the table. This is also done by passing the line numbers
> to the template in a separate generator object than the actual line
> contents themselves.
>
> diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
> --- a/mercurial/hgweb/webcommands.py
> +++ b/mercurial/hgweb/webcommands.py
> @@ -67,22 +67,30 @@
> f = fctx.path()
> text = fctx.data()
> parity = paritygen(web.stripecount)
> + parity_nums = paritygen(web.stripecount)
>
> if binary(text):
> mt = mimetypes.guess_type(f)[0] or 'application/octet-stream'
> text = '(binary:%s)' % mt
>
> + all_lines = text.splitlines(True)
> +
> def lines():
> - for lineno, t in enumerate(text.splitlines(True)):
> + for t in all_lines:
> yield {"line": t,
> - "lineid": "l%d" % (lineno + 1),
> + "parity": parity.next()}
> +
> + def linenums():
> + for lineno in range(0, len(all_lines)):
> + yield {"lineid": "l%d" % (lineno + 1),
> "linenumber": "% 6d" % (lineno + 1),
> - "parity": parity.next()}
> + "parity": parity_nums.next()}
>
> return tmpl("filerevision",
> file=f,
> path=webutil.up(f),
> text=lines(),
> + textnums=linenums(),
> rev=fctx.rev(),
> node=fctx.hex(),
> author=fctx.user(),
> diff --git a/mercurial/templates/coal/map b/mercurial/templates/coal/map
> --- a/mercurial/templates/coal/map
> +++ b/mercurial/templates/coal/map
> @@ -65,7 +65,9 @@
> filediff = ../paper/filediff.tmpl
> filelog = ../paper/filelog.tmpl
> fileline = '
> -<div class="parity{parity} source"><a href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}</div>'
> +<div class="parity{parity} source"> {line|escape}</div>'
> +filelinenums ='
> +<div class="parity{parity} source"> <a href="#{lineid}" id="{lineid}">{linenumber}</a></div>'
> filelogentry = ../paper/filelogentry.tmpl
>
> annotateline = '
> diff --git a/mercurial/templates/gitweb/filerevision.tmpl b/mercurial/templates/gitweb/filerevision.tmpl
> --- a/mercurial/templates/gitweb/filerevision.tmpl
> +++ b/mercurial/templates/gitweb/filerevision.tmpl
> @@ -58,7 +58,16 @@
> </div>
>
> <div class="page_body">
> -{text%fileline}
> +<table cellspacing="0" cellpadding="0">
> +<tr>
> +<td>
> + {textnums%filelinenums}
> +</td>
> +<td>
> + {text%fileline}
> +</td>
> +</tr>
> +</table>
> </div>
>
> {footer}
> diff --git a/mercurial/templates/gitweb/map b/mercurial/templates/gitweb/map
> --- a/mercurial/templates/gitweb/map
> +++ b/mercurial/templates/gitweb/map
> @@ -83,9 +83,9 @@
> filediff = filediff.tmpl
> filelog = filelog.tmpl
> fileline = '
> -<div style="font-family:monospace" class="parity{parity}">
> -<pre><a class="linenr" href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}</pre>
> -</div>'
> +<div style="font-family:monospace" class="parity{parity}"><pre>{line|escape}</pre></div>'
> +filelinenums ='
> +<div style="font-family:monospace" class="parity{parity}"><pre><a class="linenr" href="#{lineid}" id="{lineid}">{linenumber}</a></pre></div>'
> annotateline = '
> <tr style="font-family:monospace" class="parity{parity}">
> <td class="linenr" style="text-align: right;">
> diff --git a/mercurial/templates/monoblue/filerevision.tmpl b/mercurial/templates/monoblue/filerevision.tmpl
> --- a/mercurial/templates/monoblue/filerevision.tmpl
> +++ b/mercurial/templates/monoblue/filerevision.tmpl
> @@ -59,7 +59,16 @@
> <p class="description">{desc|strip|escape|addbreaks|nonempty}</p>
>
> <div class="source">
> - {text%fileline}
> +<table cellspacing="0" cellpadding="0">
> +<tr>
> +<td>
> + {textnums%filelinenums}
> +</td>
> +<td>
> + {text%fileline}
> +</td>
> +</tr>
> +</table>
> </div>
>
> {footer}
> diff --git a/mercurial/templates/monoblue/map b/mercurial/templates/monoblue/map
> --- a/mercurial/templates/monoblue/map
> +++ b/mercurial/templates/monoblue/map
> @@ -77,7 +77,11 @@
> filelog = filelog.tmpl
> fileline = '
> <div style="font-family:monospace" class="parity{parity}">
> -<pre><a class="linenr" href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}</pre>
> +<pre>{line|escape}</pre>
> +</div>'
> +filelinenums = '
> +<div style="font-family:monospace" class="parity{parity}">
> +<pre><a class="linenr" href="#{lineid}" id="{lineid}">{linenumber}</a></pre>
> </div>'
> annotateline = '
> <tr class="parity{parity}">
> diff --git a/mercurial/templates/paper/filerevision.tmpl b/mercurial/templates/paper/filerevision.tmpl
> --- a/mercurial/templates/paper/filerevision.tmpl
> +++ b/mercurial/templates/paper/filerevision.tmpl
> @@ -67,7 +67,16 @@
>
> <div class="overflow">
> <div class="sourcefirst"> line source</div>
> +<table cellspacing="0" cellpadding="0">
> +<tr>
> +<td>
> +{textnums%filelinenums}
> +</td>
> +<td>
> {text%fileline}
> +</td>
> +</tr>
> +</table>
> <div class="sourcelast"></div>
> </div>
> </div>
> diff --git a/mercurial/templates/paper/map b/mercurial/templates/paper/map
> --- a/mercurial/templates/paper/map
> +++ b/mercurial/templates/paper/map
> @@ -64,7 +64,9 @@
> filediff = filediff.tmpl
> filelog = filelog.tmpl
> fileline = '
> -<div class="parity{parity} source"><a href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}</div>'
> +<div class="parity{parity} source"> {line|escape}</div>'
> +filelinenums ='
> +<div class="parity{parity} source"> <a href="#{lineid}" id="{lineid}">{linenumber}</a></div>'
> filelogentry = filelogentry.tmpl
>
> annotateline = '
> diff --git a/mercurial/templates/spartan/filerevision.tmpl b/mercurial/templates/spartan/filerevision.tmpl
> --- a/mercurial/templates/spartan/filerevision.tmpl
> +++ b/mercurial/templates/spartan/filerevision.tmpl
> @@ -40,8 +40,19 @@
> </tr>
> </table>
>
> -<pre>
> -{text%fileline}
> -</pre>
> +<table cellspacing="0" cellpadding="0">
> +<tr>
> +<td>
> +<pre style="line-height: 16px">
> + {textnums%filelinenums}
> +</pre>
> +</td>
> +<td>
> +<pre style="line-height: 16px">
> + {text%fileline}
> +</pre>
> +</td>
> +</tr>
> +</table>
>
> {footer}
> diff --git a/mercurial/templates/spartan/map b/mercurial/templates/spartan/map
> --- a/mercurial/templates/spartan/map
> +++ b/mercurial/templates/spartan/map
> @@ -47,7 +47,8 @@
> fileannotate = fileannotate.tmpl
> filediff = filediff.tmpl
> filelog = filelog.tmpl
> -fileline = '<div class="parity{parity}"><a class="lineno" href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}</div>'
> +fileline = '<div class="parity{parity}"> {line|escape}</div>'
> +filelinenums = '<div class="parity{parity}"><a class="lineno" href="#{lineid}" id="{lineid}">{linenumber}</a></div>'
> filelogentry = filelogentry.tmpl
>
> # The ensures that all table cells have content (even if there
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
--
~~ Ushiko-san! Kimi wa doushite, Ushiko-san nan da!! ~~
Laurens Holst, developer, Utrecht, the Netherlands
Website: www.grauw.nl. Working @ www.roughcookie.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4332 bytes
Desc: S/MIME cryptografische ondertekening
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20111012/0e1d00d6/attachment.bin>
More information about the Mercurial-devel
mailing list