1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Prevent copying Harbormaster build log line numbers with CSS psuedocontent instead of ZWS

Summary:
Depends on D19165. Ref T13088. Currently, in other applications, we use Zero Width Spaces and Javascript "copy" listeners to prevent line numbers from being copied. This isn't terribly elegant.

Modern browsers support a second approach: using psuedo-elements with `content`. Try this in Harbormaster since it's conceptually cleaner, at least. One immediate drawback is that Command-F can't find this text either.

Test Plan: In Safari, Chrome and Firefox, highlighted ranges of lines and copy/pasted text. Got just text (no line numbers) in all cases.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13088

Differential Revision: https://secure.phabricator.com/D19166
This commit is contained in:
epriestley 2018-03-01 08:14:17 -08:00
parent 73619c4643
commit 4e91ad276d
4 changed files with 28 additions and 11 deletions

View file

@ -78,7 +78,7 @@ return array(
'rsrc/css/application/feed/feed.css' => 'ecd4ec57', 'rsrc/css/application/feed/feed.css' => 'ecd4ec57',
'rsrc/css/application/files/global-drag-and-drop.css' => 'b556a948', 'rsrc/css/application/files/global-drag-and-drop.css' => 'b556a948',
'rsrc/css/application/flag/flag.css' => 'bba8f811', 'rsrc/css/application/flag/flag.css' => 'bba8f811',
'rsrc/css/application/harbormaster/harbormaster.css' => '2999ccaa', 'rsrc/css/application/harbormaster/harbormaster.css' => 'cd73d427',
'rsrc/css/application/herald/herald-test.css' => 'a52e323e', 'rsrc/css/application/herald/herald-test.css' => 'a52e323e',
'rsrc/css/application/herald/herald.css' => 'cd8d0134', 'rsrc/css/application/herald/herald.css' => 'cd8d0134',
'rsrc/css/application/maniphest/report.css' => '9b9580b7', 'rsrc/css/application/maniphest/report.css' => '9b9580b7',
@ -495,7 +495,7 @@ return array(
'rsrc/js/core/behavior-keyboard-pager.js' => 'a8da01f0', 'rsrc/js/core/behavior-keyboard-pager.js' => 'a8da01f0',
'rsrc/js/core/behavior-keyboard-shortcuts.js' => '01fca1f0', 'rsrc/js/core/behavior-keyboard-shortcuts.js' => '01fca1f0',
'rsrc/js/core/behavior-lightbox-attachments.js' => 'e31fad01', 'rsrc/js/core/behavior-lightbox-attachments.js' => 'e31fad01',
'rsrc/js/core/behavior-line-linker.js' => 'c479ac01', 'rsrc/js/core/behavior-line-linker.js' => 'a9b946f8',
'rsrc/js/core/behavior-more.js' => 'a80d0378', 'rsrc/js/core/behavior-more.js' => 'a80d0378',
'rsrc/js/core/behavior-object-selector.js' => '77c1f0b0', 'rsrc/js/core/behavior-object-selector.js' => '77c1f0b0',
'rsrc/js/core/behavior-oncopy.js' => '2926fff2', 'rsrc/js/core/behavior-oncopy.js' => '2926fff2',
@ -579,7 +579,7 @@ return array(
'font-fontawesome' => 'e838e088', 'font-fontawesome' => 'e838e088',
'font-lato' => 'c7ccd872', 'font-lato' => 'c7ccd872',
'global-drag-and-drop-css' => 'b556a948', 'global-drag-and-drop-css' => 'b556a948',
'harbormaster-css' => '2999ccaa', 'harbormaster-css' => 'cd73d427',
'herald-css' => 'cd8d0134', 'herald-css' => 'cd8d0134',
'herald-rule-editor' => 'dca75c0e', 'herald-rule-editor' => 'dca75c0e',
'herald-test-css' => 'a52e323e', 'herald-test-css' => 'a52e323e',
@ -658,7 +658,7 @@ return array(
'javelin-behavior-phabricator-gesture-example' => '558829c2', 'javelin-behavior-phabricator-gesture-example' => '558829c2',
'javelin-behavior-phabricator-keyboard-pager' => 'a8da01f0', 'javelin-behavior-phabricator-keyboard-pager' => 'a8da01f0',
'javelin-behavior-phabricator-keyboard-shortcuts' => '01fca1f0', 'javelin-behavior-phabricator-keyboard-shortcuts' => '01fca1f0',
'javelin-behavior-phabricator-line-linker' => 'c479ac01', 'javelin-behavior-phabricator-line-linker' => 'a9b946f8',
'javelin-behavior-phabricator-nav' => '836f966d', 'javelin-behavior-phabricator-nav' => '836f966d',
'javelin-behavior-phabricator-notification-example' => '8ce821c5', 'javelin-behavior-phabricator-notification-example' => '8ce821c5',
'javelin-behavior-phabricator-object-selector' => '77c1f0b0', 'javelin-behavior-phabricator-object-selector' => '77c1f0b0',
@ -1743,6 +1743,12 @@ return array(
'javelin-uri', 'javelin-uri',
'phabricator-keyboard-shortcut', 'phabricator-keyboard-shortcut',
), ),
'a9b946f8' => array(
'javelin-behavior',
'javelin-stratcom',
'javelin-dom',
'javelin-history',
),
'a9f88de2' => array( 'a9f88de2' => array(
'javelin-behavior', 'javelin-behavior',
'javelin-dom', 'javelin-dom',
@ -1931,12 +1937,6 @@ return array(
'javelin-stratcom', 'javelin-stratcom',
'phabricator-tooltip', 'phabricator-tooltip',
), ),
'c479ac01' => array(
'javelin-behavior',
'javelin-stratcom',
'javelin-dom',
'javelin-history',
),
'c587b80f' => array( 'c587b80f' => array(
'javelin-install', 'javelin-install',
), ),

View file

@ -369,8 +369,9 @@ final class HarbormasterBuildLogRenderController
'a', 'a',
array( array(
'href' => $uri.'$'.$display_line, 'href' => $uri.'$'.$display_line,
'data-n' => $display_line,
), ),
$display_line); '');
$line_cell = phutil_tag('th', array(), $display_line); $line_cell = phutil_tag('th', array(), $display_line);
$text_cell = phutil_tag('td', array(), $display_text); $text_cell = phutil_tag('td', array(), $display_text);

View file

@ -48,6 +48,12 @@
user-select: none; user-select: none;
} }
.harbormaster-log-table > tbody > tr > th a::before {
/* Render the line numbers into the document using a pseudo-element so that
the text is not copied. */
content: attr(data-n);
}
.harbormaster-log-table > tbody > tr > th a { .harbormaster-log-table > tbody > tr > th a {
display: block; display: block;
color: {$darkbluetext}; color: {$darkbluetext};

View file

@ -21,6 +21,16 @@ JX.behavior('phabricator-line-linker', function() {
function getRowNumber(tr) { function getRowNumber(tr) {
var th = tr.firstChild; var th = tr.firstChild;
// If the "<th />" tag contains an "<a />" with "data-n" that we're using
// to prevent copy/paste of line numbers, use that.
if (th.firstChild) {
var line = th.firstChild.getAttribute('data-n');
if (line) {
return line;
}
}
return +(th.textContent || th.innerText); return +(th.textContent || th.innerText);
} }