# HG changeset patch # User domruf # Date 2017-12-16 22:10:45 # Node ID 422671dd32df4868c49d45e3a3b8e884def57bf4 # Parent f0c4fcdd1035cbc2b4459de8d91e804b4b27f239 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
 is hardcoded to
be rendered when pasting to text.)

diff --git a/kallithea/lib/diffs.py b/kallithea/lib/diffs.py
--- a/kallithea/lib/diffs.py
+++ b/kallithea/lib/diffs.py
@@ -75,7 +75,7 @@ def as_html(table_class='code-difftable'
         """
 
         if condition:
-            return '''%(label)s''' % {
+            return '''''' % {
                 'url': url,
                 'label': label
             }
diff --git a/kallithea/public/less/kallithea-diff.less b/kallithea/public/less/kallithea-diff.less
--- a/kallithea/public/less/kallithea-diff.less
+++ b/kallithea/public/less/kallithea-diff.less
@@ -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;
diff --git a/kallithea/public/less/style.less b/kallithea/public/less/style.less
--- a/kallithea/public/less/style.less
+++ b/kallithea/public/less/style.less
@@ -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;