From 487152e67f7fe480f6d10f080c9077701e636068 Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Wed, 25 Sep 2013 05:57:03 -0700 Subject: [PATCH] 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 --- .../paste/view/PasteEmbedView.php | 3 +- src/view/layout/PhabricatorSourceCodeView.php | 33 ++++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/applications/paste/view/PasteEmbedView.php b/src/applications/paste/view/PasteEmbedView.php index 62014ad919..fa3295e2cb 100644 --- a/src/applications/paste/view/PasteEmbedView.php +++ b/src/applications/paste/view/PasteEmbedView.php @@ -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', diff --git a/src/view/layout/PhabricatorSourceCodeView.php b/src/view/layout/PhabricatorSourceCodeView.php index 717de7f60c..b8396b78b2 100644 --- a/src/view/layout/PhabricatorSourceCodeView.php +++ b/src/view/layout/PhabricatorSourceCodeView.php @@ -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',