mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-17 09:18:44 +01:00
Allow disabling line highlighting on click in PhabricatorSourceCodeView
Summary: There may be times when we don't want lines in some embeded source code to be highlighted on click, this adds that functionality. Also use the functionalty in `PasteEmbedView` Test Plan: - View paste, make sure everything works. - Embed paste in comment, make sure everything works apart from click hl Reviewers: epriestley Reviewed By: epriestley CC: Korvin, aran Maniphest Tasks: T3881 Differential Revision: https://secure.phabricator.com/D7111
This commit is contained in:
parent
c373baa766
commit
487152e67f
2 changed files with 26 additions and 10 deletions
|
@ -58,7 +58,8 @@ final class PasteEmbedView extends AphrontView {
|
|||
$body_attributes,
|
||||
id(new PhabricatorSourceCodeView())
|
||||
->setLines($lines)
|
||||
->setHighlights($this->highlights));
|
||||
->setHighlights($this->highlights)
|
||||
->disableHighlightOnClick());
|
||||
|
||||
return phutil_tag(
|
||||
'div',
|
||||
|
|
|
@ -6,6 +6,7 @@ final class PhabricatorSourceCodeView extends AphrontView {
|
|||
private $limit;
|
||||
private $uri;
|
||||
private $highlights = array();
|
||||
private $canClickHighlight = true;
|
||||
|
||||
public function setLimit($limit) {
|
||||
$this->limit = $limit;
|
||||
|
@ -27,12 +28,19 @@ final class PhabricatorSourceCodeView extends AphrontView {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function disableHighlightOnClick() {
|
||||
$this->canClickHighlight = false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
require_celerity_resource('phabricator-source-code-view-css');
|
||||
require_celerity_resource('syntax-highlighting-css');
|
||||
|
||||
Javelin::initBehavior('phabricator-oncopy', array());
|
||||
Javelin::initBehavior('phabricator-line-linker');
|
||||
if ($this->canClickHighlight) {
|
||||
Javelin::initBehavior('phabricator-line-linker');
|
||||
}
|
||||
|
||||
$line_number = 1;
|
||||
|
||||
|
@ -61,15 +69,22 @@ final class PhabricatorSourceCodeView extends AphrontView {
|
|||
$row_attributes['class'] = 'phabricator-source-highlight';
|
||||
}
|
||||
|
||||
$line_uri = $this->uri . "$" . $line_number;
|
||||
$line_href = (string) new PhutilURI($line_uri);
|
||||
if ($this->canClickHighlight) {
|
||||
$line_uri = $this->uri . "$" . $line_number;
|
||||
$line_href = (string) new PhutilURI($line_uri);
|
||||
|
||||
$tag_number = javelin_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $line_href
|
||||
),
|
||||
$line_number);
|
||||
$tag_number = javelin_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $line_href
|
||||
),
|
||||
$line_number);
|
||||
} else {
|
||||
$tag_number = javelin_tag(
|
||||
'span',
|
||||
array(),
|
||||
$line_number);
|
||||
}
|
||||
|
||||
$rows[] = phutil_tag(
|
||||
'tr',
|
||||
|
|
Loading…
Add table
Reference in a new issue