changeset 7091:422671dd32df

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.)
author domruf <dominikruf@gmail.com>
date Sat, 16 Dec 2017 22:10:45 +0100
parents f0c4fcdd1035
children aa25ef34ebab
files kallithea/lib/diffs.py kallithea/public/less/kallithea-diff.less kallithea/public/less/style.less
diffstat 3 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/diffs.py	Sun Jan 21 01:28:42 2018 +0100
+++ b/kallithea/lib/diffs.py	Sat Dec 16 22:10:45 2017 +0100
@@ -75,7 +75,7 @@
         """
 
         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
             }
--- a/kallithea/public/less/kallithea-diff.less	Sun Jan 21 01:28:42 2018 +0100
+++ b/kallithea/public/less/kallithea-diff.less	Sat Dec 16 22:10:45 2017 +0100
@@ -119,8 +119,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;
--- a/kallithea/public/less/style.less	Sun Jan 21 01:28:42 2018 +0100
+++ b/kallithea/public/less/style.less	Sat Dec 16 22:10:45 2017 +0100
@@ -2,6 +2,11 @@
   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;