1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 00:32:42 +01:00

Render inline comment suggestions as real diffs

Summary: Ref T13513. When rendering an inline suggestion for display, use highlighting and diffing.

Test Plan: {F7495053}

Maniphest Tasks: T13513

Differential Revision: https://secure.phabricator.com/D21277
This commit is contained in:
epriestley 2020-05-20 09:01:23 -07:00
parent 846562158a
commit 10f241352d
7 changed files with 98 additions and 18 deletions

View file

@ -12,7 +12,7 @@ return array(
'core.pkg.css' => 'ba768cdb', 'core.pkg.css' => 'ba768cdb',
'core.pkg.js' => '845355f4', 'core.pkg.js' => '845355f4',
'dark-console.pkg.js' => '187792c2', 'dark-console.pkg.js' => '187792c2',
'differential.pkg.css' => 'f924dbcf', 'differential.pkg.css' => '5c459f92',
'differential.pkg.js' => '256a327a', 'differential.pkg.js' => '256a327a',
'diffusion.pkg.css' => '42c75c37', 'diffusion.pkg.css' => '42c75c37',
'diffusion.pkg.js' => 'a98c0bf7', 'diffusion.pkg.js' => 'a98c0bf7',
@ -65,7 +65,7 @@ return array(
'rsrc/css/application/differential/add-comment.css' => '7e5900d9', 'rsrc/css/application/differential/add-comment.css' => '7e5900d9',
'rsrc/css/application/differential/changeset-view.css' => '60c3d405', 'rsrc/css/application/differential/changeset-view.css' => '60c3d405',
'rsrc/css/application/differential/core.css' => '7300a73e', 'rsrc/css/application/differential/core.css' => '7300a73e',
'rsrc/css/application/differential/phui-inline-comment.css' => '4107254a', 'rsrc/css/application/differential/phui-inline-comment.css' => '9863a85e',
'rsrc/css/application/differential/revision-comment.css' => '7dbc8d1d', 'rsrc/css/application/differential/revision-comment.css' => '7dbc8d1d',
'rsrc/css/application/differential/revision-history.css' => '8aa3eac5', 'rsrc/css/application/differential/revision-history.css' => '8aa3eac5',
'rsrc/css/application/differential/revision-list.css' => '93d2df7d', 'rsrc/css/application/differential/revision-list.css' => '93d2df7d',
@ -854,7 +854,7 @@ return array(
'phui-icon-view-css' => '4cbc684a', 'phui-icon-view-css' => '4cbc684a',
'phui-image-mask-css' => '62c7f4d2', 'phui-image-mask-css' => '62c7f4d2',
'phui-info-view-css' => 'a10a909b', 'phui-info-view-css' => 'a10a909b',
'phui-inline-comment-view-css' => '4107254a', 'phui-inline-comment-view-css' => '9863a85e',
'phui-invisible-character-view-css' => 'c694c4a4', 'phui-invisible-character-view-css' => 'c694c4a4',
'phui-left-right-css' => '68513c34', 'phui-left-right-css' => '68513c34',
'phui-lightbox-css' => '4ebf22da', 'phui-lightbox-css' => '4ebf22da',

View file

@ -834,7 +834,6 @@ final class DifferentialChangesetParser extends Phobject {
->setNewAttachesToNewFile($this->rightSideAttachesToNewFile) ->setNewAttachesToNewFile($this->rightSideAttachesToNewFile)
->setCodeCoverage($this->getCoverage()) ->setCodeCoverage($this->getCoverage())
->setRenderingReference($this->getRenderingReference()) ->setRenderingReference($this->getRenderingReference())
->setMarkupEngine($this->markupEngine)
->setHandles($this->handles) ->setHandles($this->handles)
->setOldLines($this->old) ->setOldLines($this->old)
->setNewLines($this->new) ->setNewLines($this->new)
@ -845,6 +844,10 @@ final class DifferentialChangesetParser extends Phobject {
->setHighlightingDisabled($this->highlightingDisabled) ->setHighlightingDisabled($this->highlightingDisabled)
->setDepthOnlyLines($this->getDepthOnlyLines()); ->setDepthOnlyLines($this->getDepthOnlyLines());
if ($this->markupEngine) {
$renderer->setMarkupEngine($this->markupEngine);
}
list($engine, $old_ref, $new_ref) = $this->newDocumentEngine(); list($engine, $old_ref, $new_ref) = $this->newDocumentEngine();
if ($engine) { if ($engine) {
$engine_blocks = $engine->newEngineBlocks( $engine_blocks = $engine->newEngineBlocks(

View file

@ -3,6 +3,17 @@
final class DifferentialChangesetOneUpRenderer final class DifferentialChangesetOneUpRenderer
extends DifferentialChangesetHTMLRenderer { extends DifferentialChangesetHTMLRenderer {
private $simpleMode;
public function setSimpleMode($simple_mode) {
$this->simpleMode = $simple_mode;
return $this;
}
public function getSimpleMode() {
return $this->simpleMode;
}
public function isOneUpRenderer() { public function isOneUpRenderer() {
return true; return true;
} }
@ -36,6 +47,8 @@ final class DifferentialChangesetOneUpRenderer
protected function renderPrimitives(array $primitives, $rows) { protected function renderPrimitives(array $primitives, $rows) {
list($left_prefix, $right_prefix) = $this->getLineIDPrefixes(); list($left_prefix, $right_prefix) = $this->getLineIDPrefixes();
$is_simple = $this->getSimpleMode();
$no_copy = phutil_tag('td', array('class' => 'copy')); $no_copy = phutil_tag('td', array('class' => 'copy'));
$no_coverage = null; $no_coverage = null;
@ -185,6 +198,12 @@ final class DifferentialChangesetOneUpRenderer
$cells[] = $no_coverage; $cells[] = $no_coverage;
} }
// In simple mode, only render the text. This is used to render
// "Edit Suggestions" in inline comments.
if ($is_simple) {
$cells = array($cells[3]);
}
$out[] = phutil_tag('tr', array(), $cells); $out[] = phutil_tag('tr', array(), $cells);
break; break;
@ -231,11 +250,17 @@ final class DifferentialChangesetOneUpRenderer
} }
} }
$result = null;
if ($out) { if ($out) {
return $this->wrapChangeInTable(phutil_implode_html('', $out)); if ($is_simple) {
$result = $this->newSimpleTable($out);
} else {
$result = $this->wrapChangeInTable(phutil_implode_html('', $out));
}
} }
return null; return $result;
} }
public function renderDocumentEngineBlocks( public function renderDocumentEngineBlocks(
@ -488,4 +513,14 @@ final class DifferentialChangesetOneUpRenderer
->addInlineView($view); ->addInlineView($view);
} }
private function newSimpleTable($content) {
return phutil_tag(
'table',
array(
'class' => 'diff-1up-simple-table',
),
$content);
}
} }

View file

@ -3,10 +3,20 @@
final class PhabricatorDiffInlineCommentContext final class PhabricatorDiffInlineCommentContext
extends PhabricatorInlineCommentContext { extends PhabricatorInlineCommentContext {
private $filename;
private $headLines; private $headLines;
private $bodyLines; private $bodyLines;
private $tailLines; private $tailLines;
public function setFilename($filename) {
$this->filename = $filename;
return $this;
}
public function getFilename() {
return $this->filename;
}
public function setHeadLines(array $head_lines) { public function setHeadLines(array $head_lines) {
$this->headLines = $head_lines; $this->headLines = $head_lines;
return $this; return $this;

View file

@ -289,8 +289,12 @@ abstract class PhabricatorDiffInlineCommentQuery
} }
if ($inline->getIsNewFile()) { if ($inline->getIsNewFile()) {
$vector = $changeset->getNewStatePathVector();
$filename = last($vector);
$corpus = $changeset->makeNewFile(); $corpus = $changeset->makeNewFile();
} else { } else {
$vector = $changeset->getOldStatePathVector();
$filename = last($vector);
$corpus = $changeset->makeOldFile(); $corpus = $changeset->makeOldFile();
} }
@ -321,6 +325,7 @@ abstract class PhabricatorDiffInlineCommentQuery
$tail = $this->simplifyContext($tail, false); $tail = $this->simplifyContext($tail, false);
$context = id(new PhabricatorDiffInlineCommentContext()) $context = id(new PhabricatorDiffInlineCommentContext())
->setFilename($filename)
->setHeadLines($head) ->setHeadLines($head)
->setBodyLines($body) ->setBodyLines($body)
->setTailLines($tail); ->setTailLines($tail);

View file

@ -540,20 +540,35 @@ final class PHUIDiffInlineCommentDetailView
return null; return null;
} }
$viewer = $this->getViewer();
$raw_diff = id(new PhabricatorDifferenceEngine()) $changeset = id(new PhabricatorDifferenceEngine())
->generateRawDiffFromFileContent($old_lines, $new_lines); ->generateChangesetFromFileContent($old_lines, $new_lines);
$raw_diff = phutil_split_lines($raw_diff); $changeset->setFilename($context->getFilename());
$raw_diff = array_slice($raw_diff, 3);
$raw_diff = implode('', $raw_diff); // TODO: This isn't cached!
$viewstate = new PhabricatorChangesetViewState();
$parser = id(new DifferentialChangesetParser())
->setViewer($viewer)
->setViewstate($viewstate)
->setChangeset($changeset);
$renderer = new DifferentialChangesetOneUpRenderer();
$renderer->setSimpleMode(true);
$parser->setRenderer($renderer);
$diff_view = $parser->render(0, 0xFFFF, array());
$view = phutil_tag( $view = phutil_tag(
'div', 'div',
array( array(
'class' => 'inline-suggestion-view PhabricatorMonospaced', 'class' => 'inline-suggestion-view PhabricatorMonospaced',
), ),
$raw_diff); $diff_view);
return $view; return $view;
} }

View file

@ -476,20 +476,32 @@ textarea.inline-suggestion-input {
border-right: 1px solid {$lightgreyborder}; border-right: 1px solid {$lightgreyborder};
} }
.inline-suggestion-input-cell { .inline-suggestion-table td.inline-suggestion-input-cell {
padding: 8px; padding: 8px 4px;
} }
.inline-suggestion-text-cell { .inline-suggestion-table td.inline-suggestion-text-cell {
padding: 0 8px; /* This is attempting to align the text in the textarea with the text on
the surrounding context lines. */
padding: 0 8px 0 11px;
} }
.inline-suggestion-view { .inline-suggestion-view {
padding: 8px 12px; padding: 4px 0;
white-space: pre-wrap; white-space: pre-wrap;
background: {$greybackground}; background: {$lightgreybackground};
margin: 0 -12px 8px; margin: 0 -12px 8px;
border-width: 1px 0; border-width: 1px 0;
border-style: solid; border-style: solid;
border-color: {$lightgreyborder}; border-color: {$lightgreyborder};
} }
.diff-1up-simple-table {
width: 100%;
table-layout: fixed;
}
.diff-1up-simple-table > tbody > tr > td {
padding-left: 12px;
padding-right: 12px;
}