Merge lp:~blr/launchpad/diff-code-select-bug-1483925 into lp:launchpad

Proposed by Kit Randel on 2015-08-13
Status: Merged
Merged at revision: 17706
Proposed branch: lp:~blr/launchpad/diff-code-select-bug-1483925
Merge into: lp:launchpad
Diff against target: 116 lines (+22/-14)
3 files modified
lib/canonical/launchpad/icing/style.css (+6/-0)
lib/lp/app/browser/stringformatter.py (+7/-6)
lib/lp/app/browser/tests/test_stringformatter.py (+9/-8)
To merge this branch: bzr merge lp:~blr/launchpad/diff-code-select-bug-1483925
Reviewer Review Type Date Requested Status
Colin Watson 2015-08-13 Approve on 2015-08-17
Review via email: mp+268017@code.launchpad.net

Commit Message

Add unselectable css class and apply to line-no and line-no-ss in preview diffs.

Description of the Change

This branch provides a simple .unselectable class, and applies it to both line-no and line-no-ss on preview diffs - a small usability improvement to facilitate copy/pasting diffs.

To post a comment you must log in.
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/icing/style.css'
2--- lib/canonical/launchpad/icing/style.css 2015-06-29 23:04:36 +0000
3+++ lib/canonical/launchpad/icing/style.css 2015-08-13 23:15:46 +0000
4@@ -35,6 +35,12 @@
5 top: 0;
6 }
7
8+.unselectable {
9+ -moz-user-select: none;
10+ -webkit-user-select: none;
11+ -ms-user-select: none;
12+}
13+
14 /* === Fonts and colors === */
15
16 .unavailable {
17
18=== modified file 'lib/lp/app/browser/stringformatter.py'
19--- lib/lp/app/browser/stringformatter.py 2015-07-21 09:04:01 +0000
20+++ lib/lp/app/browser/stringformatter.py 2015-08-13 23:15:46 +0000
21@@ -938,7 +938,7 @@
22
23 for css_class, row, _, _, line in parse_diff(text):
24 result.append('<tr id="diff-line-%s">' % row)
25- result.append('<td class="line-no">%s</td>' % row)
26+ result.append('<td class="line-no unselectable">%s</td>' % row)
27 result.append(
28 structured(
29 '<td class="%s">%s</td>', css_class, line).escapedtext)
30@@ -953,7 +953,8 @@
31 # work, but displaying it would be confusing since there are also
32 # per-file line numbers.
33 result.append(
34- '<td class="line-no" style="display: none">%s</td>' % row)
35+ '<td class="line-no unselectable" '
36+ 'style="display: none">%s</td>' % row)
37 result.extend(cells)
38 result.append('</tr>')
39
40@@ -968,11 +969,11 @@
41 else:
42 added_diff_row, added_row, added_line = 0, '', ''
43 cells = (
44- '<td class="ss-line-no">%s</td>' % removed_row,
45+ '<td class="ss-line-no unselectable">%s</td>' % removed_row,
46 structured(
47 '<td class="diff-removed text">%s</td>',
48 removed_line).escapedtext,
49- '<td class="ss-line-no">%s</td>' % added_row,
50+ '<td class="ss-line-no unselectable">%s</td>' % added_row,
51 structured(
52 '<td class="diff-added text">%s</td>',
53 added_line).escapedtext,
54@@ -1022,10 +1023,10 @@
55 if line.startswith(' '):
56 line = line[1:]
57 cells = [
58- '<td class="ss-line-no">%s</td>' % orig_row,
59+ '<td class="ss-line-no unselectable">%s</td>' % orig_row,
60 structured(
61 '<td class="text">%s</td>', line).escapedtext,
62- '<td class="ss-line-no">%s</td>' % mod_row,
63+ '<td class="ss-line-no unselectable">%s</td>' % mod_row,
64 structured(
65 '<td class="text">%s</td>', line).escapedtext,
66 ]
67
68=== modified file 'lib/lp/app/browser/tests/test_stringformatter.py'
69--- lib/lp/app/browser/tests/test_stringformatter.py 2015-06-25 11:16:06 +0000
70+++ lib/lp/app/browser/tests/test_stringformatter.py 2015-08-13 23:15:46 +0000
71@@ -483,14 +483,15 @@
72 # White space doesn't count as empty, and is formatted.
73 self.assertEqual(
74 '<table class="diff unidiff"><tr id="diff-line-1">'
75- '<td class="line-no">1</td><td class="text"> </td></tr></table>',
76+ '<td class="line-no unselectable">1</td><td class="text"> '
77+ '</td></tr></table>',
78 FormattersAPI(' ').format_diff())
79
80 def test_format_unicode(self):
81 # Sometimes the strings contain unicode, those should work too.
82 self.assertEqual(
83 u'<table class="diff unidiff"><tr id="diff-line-1">'
84- u'<td class="line-no">1</td><td class="text">'
85+ u'<td class="line-no unselectable">1</td><td class="text">'
86 u'Unicode \u1010</td></tr></table>',
87 FormattersAPI(u'Unicode \u1010').format_diff())
88
89@@ -576,10 +577,10 @@
90 # White space doesn't count as empty, and is formatted.
91 self.assertEqual(
92 '<table class="diff ssdiff"><tr id="diff-line-1">'
93- '<td class="line-no" style="display: none">1</td>'
94- '<td class="ss-line-no">0</td>'
95+ '<td class="line-no unselectable" style="display: none">1</td>'
96+ '<td class="ss-line-no unselectable">0</td>'
97 '<td class="text"></td>'
98- '<td class="ss-line-no">0</td>'
99+ '<td class="ss-line-no unselectable">0</td>'
100 '<td class="text"></td>'
101 '</tr></table>',
102 FormattersAPI(' ').format_ssdiff())
103@@ -588,10 +589,10 @@
104 # Sometimes the strings contain unicode, those should work too.
105 self.assertEqual(
106 u'<table class="diff ssdiff"><tr id="diff-line-1">'
107- u'<td class="line-no" style="display: none">1</td>'
108- u'<td class="ss-line-no">0</td>'
109+ u'<td class="line-no unselectable" style="display: none">1</td>'
110+ u'<td class="ss-line-no unselectable">0</td>'
111 u'<td class="text">Unicode \u1010</td>'
112- u'<td class="ss-line-no">0</td>'
113+ u'<td class="ss-line-no unselectable">0</td>'
114 u'<td class="text">Unicode \u1010</td>'
115 u'</tr></table>',
116 FormattersAPI(u'Unicode \u1010').format_ssdiff())