Changeset - 422671dd32df
[Not reviewed]
default
0 3 0
domruf - 8 years ago 2017-12-16 22:10:45
dominikruf@gmail.com
css: use pseudo-content trick to prevent diff line numbers from being pasted to text

When copy-pasting a diff from Chrome to a text editor, line numbers (on
separate lines) would be pasted as well. Even though 'user-select: none'
prevents text from being visually selected, in Chrome, the text still gets
copied to the clipboard when the user for example presses ctrl-c. (It worked in
Firefox.)

Instead, don't put the line numbers directly in the DOM, but put them in a data
attribute and render them as :before. That will give the same rendering as
before but prevent it from being copied.

(Firefox will however still add empty lines - that is how <pre> is hardcoded to
be rendered when pasting to text.)
3 files changed with 6 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/diffs.py
Show inline comments
 
@@ -75,7 +75,7 @@ def as_html(table_class='code-difftable'
 
        """
 

	
 
        if condition:
 
            return '''<a href="%(url)s">%(label)s</a>''' % {
 
            return '''<a href="%(url)s" data-pseudo-content="%(label)s"></a>''' % {
 
                'url': url,
 
                'label': label
 
            }
kallithea/public/less/kallithea-diff.less
Show inline comments
 
@@ -119,8 +119,6 @@ BIN_FILENODE = 6
 
    padding-left: 2px;
 
    padding-right: 2px !important;
 
    width: 30px;
 
    -moz-user-select: none;
 
    -webkit-user-select: none;
 
    border-right: 1px solid #CCC !important;
 
    border-left: 0px solid #CCC !important;
 
    border-top: 0px solid #CCC !important;
kallithea/public/less/style.less
Show inline comments
 
@@ -2,6 +2,11 @@ body {
 
  background: url("../images/background.png") repeat scroll 0 0 #B0B0B0;
 
}
 

	
 
/* pseude content that should not be selected or copied by the user */
 
[data-pseudo-content]:before {
 
  content: attr(data-pseudo-content);
 
}
 

	
 
/* class for texts where newlines should be preserved, for very light-weight ascii art markup (like pull request descriptions) */
 
.formatted-fixed {
 
  white-space: pre-wrap;
0 comments (0 inline, 0 general)