From 1e8d20d9fc50cba3fc260a483e4da30481541d3f Mon Sep 17 00:00:00 2001 From: Lauri-Henrik Jalonen Date: Thu, 14 Mar 2013 10:51:34 -0700 Subject: [PATCH] Line count can be set for paste Summary: Probably not the ideal way to deal showing only certain amount of lines. Size vary by browsers, zooming will mess it up albeit only a little and will definitely not work with IE. Test Plan: {F35989} Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1770 Differential Revision: https://secure.phabricator.com/D5347 --- .../remarkup/PhabricatorPasteRemarkupRule.php | 4 ++-- src/applications/paste/view/PasteEmbedView.php | 16 ++++++++++++---- src/view/layout/PhabricatorSourceCodeView.php | 5 ++--- webroot/rsrc/css/application/paste/paste.css | 4 ++++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php b/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php index 93b987e570..1115bac6c4 100644 --- a/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php +++ b/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php @@ -32,9 +32,9 @@ final class PhabricatorPasteRemarkupRule foreach ($opts as $key => $value) { if ($key == 'lines') { - // placeholder for now + $embed_paste->setLines(preg_replace('/[^0-9]/', '', $value)); } else if ($key == 'highlight') { - $highlights = explode('&', preg_replace('/\s+/', '', $value)); + $highlights = preg_split('/,|&/', preg_replace('/\s+/', '', $value)); $to_highlight = array(); foreach ($highlights as $highlight) { diff --git a/src/applications/paste/view/PasteEmbedView.php b/src/applications/paste/view/PasteEmbedView.php index 315404cf49..62014ad919 100644 --- a/src/applications/paste/view/PasteEmbedView.php +++ b/src/applications/paste/view/PasteEmbedView.php @@ -5,6 +5,7 @@ final class PasteEmbedView extends AphrontView { private $paste; private $handle; private $highlights = array(); + private $lines = 30; public function setPaste(PhabricatorPaste $paste) { $this->paste = $paste; @@ -21,6 +22,10 @@ final class PasteEmbedView extends AphrontView { return $this; } + public function setLines($lines) { + $this->lines = $lines; + } + public function render() { if (!$this->paste) { throw new Exception("Call setPaste() before render()!"); @@ -43,18 +48,21 @@ final class PasteEmbedView extends AphrontView { ), $link); + $body_attributes = array('class' => 'paste-embed-body'); + if ($this->lines != null) { + $body_attributes['style'] = 'max-height: '.$this->lines * (1.15).'em;'; + } + $body = phutil_tag( 'div', - array(), + $body_attributes, id(new PhabricatorSourceCodeView()) ->setLines($lines) ->setHighlights($this->highlights)); return phutil_tag( 'div', - array( - 'class' => 'paste-embed' - ), + array('class' => 'paste-embed'), array($head, $body)); } diff --git a/src/view/layout/PhabricatorSourceCodeView.php b/src/view/layout/PhabricatorSourceCodeView.php index 70956a4be8..12d051771c 100644 --- a/src/view/layout/PhabricatorSourceCodeView.php +++ b/src/view/layout/PhabricatorSourceCodeView.php @@ -17,7 +17,7 @@ final class PhabricatorSourceCodeView extends AphrontView { } public function setHighlights(array $highlights) { - $this->highlights = $highlights; + $this->highlights = array_fuse($highlights); return $this; } @@ -31,7 +31,6 @@ final class PhabricatorSourceCodeView extends AphrontView { $rows = array(); foreach ($this->lines as $line) { - $hit_limit = $this->limit && ($line_number == $this->limit) && (count($this->lines) != $this->limit); @@ -50,7 +49,7 @@ final class PhabricatorSourceCodeView extends AphrontView { } $row_attributes = array(); - if (in_array($line_number, $this->highlights)) { + if (isset($this->highlights[$line_number])) { $row_attributes['class'] = 'phabricator-source-highlight'; } diff --git a/webroot/rsrc/css/application/paste/paste.css b/webroot/rsrc/css/application/paste/paste.css index 9050efe54f..9f0caf08f4 100644 --- a/webroot/rsrc/css/application/paste/paste.css +++ b/webroot/rsrc/css/application/paste/paste.css @@ -17,3 +17,7 @@ color: #282828; font-weight: bold; } + +.paste-embed-body { + overflow-y: auto; +}