1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-25 06:50:55 +01:00

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
This commit is contained in:
Lauri-Henrik Jalonen 2013-03-14 10:51:34 -07:00 committed by epriestley
parent dcdf207266
commit 1e8d20d9fc
4 changed files with 20 additions and 9 deletions

View file

@ -32,9 +32,9 @@ final class PhabricatorPasteRemarkupRule
foreach ($opts as $key => $value) { foreach ($opts as $key => $value) {
if ($key == 'lines') { if ($key == 'lines') {
// placeholder for now $embed_paste->setLines(preg_replace('/[^0-9]/', '', $value));
} else if ($key == 'highlight') { } else if ($key == 'highlight') {
$highlights = explode('&', preg_replace('/\s+/', '', $value)); $highlights = preg_split('/,|&/', preg_replace('/\s+/', '', $value));
$to_highlight = array(); $to_highlight = array();
foreach ($highlights as $highlight) { foreach ($highlights as $highlight) {

View file

@ -5,6 +5,7 @@ final class PasteEmbedView extends AphrontView {
private $paste; private $paste;
private $handle; private $handle;
private $highlights = array(); private $highlights = array();
private $lines = 30;
public function setPaste(PhabricatorPaste $paste) { public function setPaste(PhabricatorPaste $paste) {
$this->paste = $paste; $this->paste = $paste;
@ -21,6 +22,10 @@ final class PasteEmbedView extends AphrontView {
return $this; return $this;
} }
public function setLines($lines) {
$this->lines = $lines;
}
public function render() { public function render() {
if (!$this->paste) { if (!$this->paste) {
throw new Exception("Call setPaste() before render()!"); throw new Exception("Call setPaste() before render()!");
@ -43,18 +48,21 @@ final class PasteEmbedView extends AphrontView {
), ),
$link); $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( $body = phutil_tag(
'div', 'div',
array(), $body_attributes,
id(new PhabricatorSourceCodeView()) id(new PhabricatorSourceCodeView())
->setLines($lines) ->setLines($lines)
->setHighlights($this->highlights)); ->setHighlights($this->highlights));
return phutil_tag( return phutil_tag(
'div', 'div',
array( array('class' => 'paste-embed'),
'class' => 'paste-embed'
),
array($head, $body)); array($head, $body));
} }

View file

@ -17,7 +17,7 @@ final class PhabricatorSourceCodeView extends AphrontView {
} }
public function setHighlights(array $highlights) { public function setHighlights(array $highlights) {
$this->highlights = $highlights; $this->highlights = array_fuse($highlights);
return $this; return $this;
} }
@ -31,7 +31,6 @@ final class PhabricatorSourceCodeView extends AphrontView {
$rows = array(); $rows = array();
foreach ($this->lines as $line) { foreach ($this->lines as $line) {
$hit_limit = $this->limit && $hit_limit = $this->limit &&
($line_number == $this->limit) && ($line_number == $this->limit) &&
(count($this->lines) != $this->limit); (count($this->lines) != $this->limit);
@ -50,7 +49,7 @@ final class PhabricatorSourceCodeView extends AphrontView {
} }
$row_attributes = array(); $row_attributes = array();
if (in_array($line_number, $this->highlights)) { if (isset($this->highlights[$line_number])) {
$row_attributes['class'] = 'phabricator-source-highlight'; $row_attributes['class'] = 'phabricator-source-highlight';
} }

View file

@ -17,3 +17,7 @@
color: #282828; color: #282828;
font-weight: bold; font-weight: bold;
} }
.paste-embed-body {
overflow-y: auto;
}