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:
parent
dcdf207266
commit
1e8d20d9fc
4 changed files with 20 additions and 9 deletions
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
||||
|
|
|
@ -17,3 +17,7 @@
|
|||
color: #282828;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.paste-embed-body {
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue