@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make Paste source code line highlighting behavior more generic

Summary: Depends on D19163. Ref T13088. Increase the generality of this code so it can be shared with Harbormaster.

Test Plan: Clicked individual lines, clicked-and-dragged, etc., in Paste. Got sensible URI and highlight behaviors.

Maniphest Tasks: T13088

Differential Revision: https://secure.phabricator.com/D19164

+117 -50
+10 -10
resources/celerity/map.php
··· 122 122 'rsrc/css/font/font-lato.css' => 'c7ccd872', 123 123 'rsrc/css/font/phui-font-icon-base.css' => '870a7360', 124 124 'rsrc/css/layout/phabricator-filetree-view.css' => 'b912ad97', 125 - 'rsrc/css/layout/phabricator-source-code-view.css' => 'aea41829', 125 + 'rsrc/css/layout/phabricator-source-code-view.css' => '926ced2d', 126 126 'rsrc/css/phui/button/phui-button-bar.css' => 'f1ff5494', 127 127 'rsrc/css/phui/button/phui-button-simple.css' => '8e1baf68', 128 128 'rsrc/css/phui/button/phui-button.css' => '1863cc6e', ··· 495 495 'rsrc/js/core/behavior-keyboard-pager.js' => 'a8da01f0', 496 496 'rsrc/js/core/behavior-keyboard-shortcuts.js' => '01fca1f0', 497 497 'rsrc/js/core/behavior-lightbox-attachments.js' => 'e31fad01', 498 - 'rsrc/js/core/behavior-line-linker.js' => '1499a8cb', 498 + 'rsrc/js/core/behavior-line-linker.js' => 'c479ac01', 499 499 'rsrc/js/core/behavior-more.js' => 'a80d0378', 500 500 'rsrc/js/core/behavior-object-selector.js' => '77c1f0b0', 501 501 'rsrc/js/core/behavior-oncopy.js' => '2926fff2', ··· 658 658 'javelin-behavior-phabricator-gesture-example' => '558829c2', 659 659 'javelin-behavior-phabricator-keyboard-pager' => 'a8da01f0', 660 660 'javelin-behavior-phabricator-keyboard-shortcuts' => '01fca1f0', 661 - 'javelin-behavior-phabricator-line-linker' => '1499a8cb', 661 + 'javelin-behavior-phabricator-line-linker' => 'c479ac01', 662 662 'javelin-behavior-phabricator-nav' => '836f966d', 663 663 'javelin-behavior-phabricator-notification-example' => '8ce821c5', 664 664 'javelin-behavior-phabricator-object-selector' => '77c1f0b0', ··· 802 802 'phabricator-search-results-css' => '505dd8cf', 803 803 'phabricator-shaped-request' => '7cbe244b', 804 804 'phabricator-slowvote-css' => 'a94b7230', 805 - 'phabricator-source-code-view-css' => 'aea41829', 805 + 'phabricator-source-code-view-css' => '926ced2d', 806 806 'phabricator-standard-page-view' => '34ee718b', 807 807 'phabricator-textareautils' => '320810c8', 808 808 'phabricator-title' => '485aaa6c', ··· 997 997 'javelin-util', 998 998 'javelin-dom', 999 999 'javelin-typeahead-normalizer', 1000 - ), 1001 - '1499a8cb' => array( 1002 - 'javelin-behavior', 1003 - 'javelin-stratcom', 1004 - 'javelin-dom', 1005 - 'javelin-history', 1006 1000 ), 1007 1001 '15d5ff71' => array( 1008 1002 'aphront-typeahead-control-css', ··· 1936 1930 'javelin-behavior-device', 1937 1931 'javelin-stratcom', 1938 1932 'phabricator-tooltip', 1933 + ), 1934 + 'c479ac01' => array( 1935 + 'javelin-behavior', 1936 + 'javelin-stratcom', 1937 + 'javelin-dom', 1938 + 'javelin-history', 1939 1939 ), 1940 1940 'c587b80f' => array( 1941 1941 'javelin-install',
+8 -6
src/view/layout/PhabricatorSourceCodeView.php
··· 73 73 pht('...'))); 74 74 } 75 75 76 + $base_uri = (string)$this->uri; 76 77 foreach ($lines as $line) { 77 78 78 79 // NOTE: See phabricator-oncopy behavior. ··· 84 85 } 85 86 86 87 if ($this->canClickHighlight) { 87 - $line_uri = $this->uri.'$'.$line_number; 88 - $line_href = (string)new PhutilURI($line_uri); 88 + $line_href = $base_uri.'$'.$line_number; 89 89 90 - $tag_number = javelin_tag( 90 + $tag_number = phutil_tag( 91 91 'a', 92 92 array( 93 93 'href' => $line_href, 94 94 ), 95 95 $line_number); 96 96 } else { 97 - $tag_number = javelin_tag( 97 + $tag_number = phutil_tag( 98 98 'span', 99 99 array(), 100 100 $line_number); ··· 104 104 'tr', 105 105 $row_attributes, 106 106 array( 107 - javelin_tag( 107 + phutil_tag( 108 108 'th', 109 109 array( 110 110 'class' => 'phabricator-source-line', 111 - 'sigil' => 'phabricator-source-line', 112 111 ), 113 112 $tag_number), 114 113 phutil_tag( ··· 134 133 array( 135 134 'class' => implode(' ', $classes), 136 135 'sigil' => 'phabricator-source', 136 + 'meta' => array( 137 + 'uri' => (string)$this->uri, 138 + ), 137 139 ), 138 140 phutil_implode_html('', $rows))); 139 141 }
+8 -3
webroot/rsrc/css/layout/phabricator-source-code-view.css
··· 31 31 .phabricator-source-line { 32 32 background-color: {$paste.highlight}; 33 33 text-align: right; 34 - padding: 2px 6px 1px 12px; 35 34 border-right: 1px solid {$paste.border}; 36 35 color: {$sh-yellowtext}; 37 36 ··· 48 47 49 48 th.phabricator-source-line a { 50 49 color: {$darkbluetext}; 50 + display: block; 51 + padding: 2px 6px 1px 12px; 51 52 } 52 53 53 - th.phabricator-source-line:hover { 54 + th.phabricator-source-line a:hover { 54 55 background: {$paste.border}; 55 - cursor: pointer; 56 + text-decoration: none; 56 57 } 57 58 58 59 .phabricator-source-highlight { 59 60 background: {$paste.highlight}; 61 + } 62 + 63 + .phabricator-source-highlight th.phabricator-source-line { 64 + background: {$paste.border}; 60 65 } 61 66 62 67 .phabricator-source-code-summary {
+91 -31
webroot/rsrc/js/core/behavior-line-linker.js
··· 10 10 var origin = null; 11 11 var target = null; 12 12 var root = null; 13 + var highlighted = null; 13 14 14 15 var editor_link = null; 15 16 try { ··· 19 20 } 20 21 21 22 function getRowNumber(tr) { 22 - var th = JX.DOM.find(tr, 'th', 'phabricator-source-line'); 23 + var th = tr.firstChild; 23 24 return +(th.textContent || th.innerText); 24 25 } 25 26 26 27 JX.Stratcom.listen( 27 - 'mousedown', 28 - 'phabricator-source-line', 28 + ['click', 'mousedown'], 29 + ['phabricator-source', 'tag:tr', 'tag:th', 'tag:a'], 29 30 function(e) { 30 31 if (!e.isNormalMouseEvent()) { 31 32 return; 32 33 } 33 - origin = e.getNode('tag:tr'); 34 + 35 + // Make sure the link we clicked is actually a line number in a source 36 + // table, not some kind of link in some element embedded inside the 37 + // table. The row's immediate ancestor table needs to be the table with 38 + // the "phabricator-source" sigil. 39 + 40 + var row = e.getNode('tag:tr'); 41 + var table = e.getNode('phabricator-source'); 42 + if (JX.DOM.findAbove(row, 'table') !== table) { 43 + return; 44 + } 45 + 46 + var number = getRowNumber(row); 47 + if (!number) { 48 + return; 49 + } 50 + 51 + e.kill(); 52 + 53 + // If this is a click event, kill it. We handle mousedown and mouseup 54 + // instead. 55 + if (e.getType() === 'click') { 56 + return; 57 + } 58 + 59 + origin = row; 34 60 target = origin; 35 - root = e.getNode('phabricator-source'); 36 - e.kill(); 37 - }); 38 61 39 - JX.Stratcom.listen( 40 - 'click', 41 - 'phabricator-source-line', 42 - function(e) { 43 - e.kill(); 62 + root = table; 44 63 }); 45 64 46 65 var highlight = function(e) { 47 - if (!origin || e.getNode('phabricator-source') !== root) { 66 + if (!origin) { 67 + return; 68 + } 69 + 70 + if (e.getNode('phabricator-source') !== root) { 48 71 return; 49 72 } 50 73 target = e.getNode('tag:tr'); 51 74 52 - var highlighting = false; 53 - var source = null; 54 - var trs = JX.DOM.scry(root, 'tr'); 55 - for (var i = 0; i < trs.length; i++) { 56 - if (!highlighting && (trs[i] === origin || trs[i] === target)) { 57 - highlighting = true; 58 - source = trs[i]; 75 + var min; 76 + var max; 77 + 78 + // NOTE: We're using position to figure out which order these rows are in, 79 + // not row numbers. We do this because Harbormaster build logs may have 80 + // multiple rows with the same row number. 81 + 82 + if (JX.$V(origin).y <= JX.$V(target).y) { 83 + min = origin; 84 + max = target; 85 + } else { 86 + min = target; 87 + max = origin; 88 + } 89 + 90 + // If we haven't changed highlighting, we don't have a list of highlighted 91 + // nodes yet. Assume every row is highlighted. 92 + var ii; 93 + if (highlighted === null) { 94 + highlighted = []; 95 + var rows = JX.DOM.scry(root, 'tr'); 96 + for (ii = 0; ii < rows.length; ii++) { 97 + highlighted.push(rows[ii]); 59 98 } 60 - JX.DOM.alterClass(trs[i], 'phabricator-source-highlight', highlighting); 61 - if (trs[i] === (source === origin ? target : origin)) { 62 - highlighting = false; 99 + } 100 + 101 + // Unhighlight any existing highlighted rows. 102 + for (ii = 0; ii < highlighted.length; ii++) { 103 + JX.DOM.alterClass(highlighted[ii], 'phabricator-source-highlight', false); 104 + } 105 + highlighted = []; 106 + 107 + // Highlight the newly selected rows. 108 + var cursor = min; 109 + while (true) { 110 + JX.DOM.alterClass(cursor, 'phabricator-source-highlight', true); 111 + highlighted.push(cursor); 112 + 113 + if (cursor === max) { 114 + break; 63 115 } 116 + 117 + cursor = cursor.nextSibling; 64 118 } 65 119 }; 66 120 ··· 75 129 } 76 130 77 131 highlight(e); 132 + e.kill(); 78 133 79 134 var o = getRowNumber(origin); 80 135 var t = getRowNumber(target); 81 - var lines = (o == t ? o : Math.min(o, t) + '-' + Math.max(o, t)); 82 - var th = JX.DOM.find(origin, 'th', 'phabricator-source-line'); 83 - var uri = JX.DOM.find(th, 'a').href; 84 - uri = uri.replace(/(.*\$)\d+/, '$1' + lines); 136 + var uri = JX.Stratcom.getData(root).uri; 137 + 85 138 origin = null; 86 139 target = null; 87 - e.kill(); 140 + root = null; 141 + 142 + var lines = (o == t ? o : Math.min(o, t) + '-' + Math.max(o, t)); 143 + uri = uri + '$' + lines; 144 + 88 145 JX.History.replace(uri); 89 - if (editor_link.href) { 90 - var editdata = JX.Stratcom.getData(editor_link); 91 - editor_link.href = editdata.link_template.replace('%25l', o); 146 + 147 + if (editor_link) { 148 + if (editor_link.href) { 149 + var editdata = JX.Stratcom.getData(editor_link); 150 + editor_link.href = editdata.link_template.replace('%25l', o); 151 + } 92 152 } 93 153 }); 94 154