@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PHUIDiffInlineCommentEditView
4 extends PHUIDiffInlineCommentView {
5
6 private $title;
7
8 public function setTitle($title) {
9 $this->title = $title;
10 return $this;
11 }
12
13 public function render() {
14 $viewer = $this->getViewer();
15 $inline = $this->getInlineComment();
16
17 $content = phabricator_form(
18 $viewer,
19 array(
20 'action' => $inline->getControllerURI(),
21 'method' => 'POST',
22 'sigil' => 'inline-edit-form',
23 ),
24 array(
25 $this->renderBody(),
26 ));
27
28 return $content;
29 }
30
31 private function renderBody() {
32 $buttons = array();
33
34 $buttons[] = id(new PHUIButtonView())
35 ->setText(pht('Save Draft'));
36
37 $buttons[] = id(new PHUIButtonView())
38 ->setText(pht('Cancel'))
39 ->setColor(PHUIButtonView::GREY)
40 ->addSigil('inline-edit-cancel');
41
42 $title = phutil_tag(
43 'div',
44 array(
45 'class' => 'differential-inline-comment-edit-title',
46 ),
47 $this->title);
48
49 $corpus_view = $this->newCorpusView();
50
51 $body = phutil_tag(
52 'div',
53 array(
54 'class' => 'differential-inline-comment-edit-body',
55 ),
56 array(
57 $corpus_view,
58 $this->newTextarea(),
59 ));
60
61 $edit = javelin_tag(
62 'div',
63 array(
64 'class' => 'differential-inline-comment-edit-buttons grouped',
65 'sigil' => 'inline-edit-buttons',
66 ),
67 array(
68 $buttons,
69 ));
70
71 $inline = $this->getInlineComment();
72
73 return javelin_tag(
74 'div',
75 array(
76 'class' => 'differential-inline-comment-edit',
77 'sigil' => 'differential-inline-comment',
78 'meta' => $this->getInlineCommentMetadata(),
79 ),
80 array(
81 $title,
82 $body,
83 $edit,
84 ));
85 }
86
87 private function newTextarea() {
88 $viewer = $this->getViewer();
89 $inline = $this->getInlineComment();
90
91 $state = $inline->getContentStateForEdit($viewer);
92
93 return id(new PhabricatorRemarkupControl())
94 ->setViewer($viewer)
95 ->setSigil('inline-content-text')
96 ->setValue($state->getContentText())
97 ->setDisableFullScreen(true);
98 }
99
100 private function newCorpusView() {
101 $viewer = $this->getViewer();
102 $inline = $this->getInlineComment();
103
104 $context = $inline->getInlineContext();
105 if ($context === null) {
106 return null;
107 }
108
109 $head = $context->getHeadLines();
110 $head = $this->newContextView($head);
111
112 $state = $inline->getContentStateForEdit($viewer);
113
114 $main = $state->getContentSuggestionText();
115 $main_count = count(phutil_split_lines($main));
116
117 // Browsers ignore one leading newline in text areas. Add one so that
118 // any actual leading newlines in the content are preserved.
119 $main = "\n".$main;
120
121 $textarea = javelin_tag(
122 'textarea',
123 array(
124 'class' => 'inline-suggestion-input PhabricatorMonospaced',
125 'rows' => max(3, $main_count + 1),
126 'sigil' => 'inline-content-suggestion',
127 ),
128 $main);
129
130 $main = phutil_tag(
131 'tr',
132 array(
133 'class' => 'inline-suggestion-input-row',
134 ),
135 array(
136 phutil_tag(
137 'td',
138 array(
139 'class' => 'inline-suggestion-line-cell',
140 ),
141 null),
142 phutil_tag(
143 'td',
144 array(
145 'class' => 'inline-suggestion-input-cell',
146 ),
147 $textarea),
148 ));
149
150 $tail = $context->getTailLines();
151 $tail = $this->newContextView($tail);
152
153 $body = phutil_tag(
154 'tbody',
155 array(),
156 array(
157 $head,
158 $main,
159 $tail,
160 ));
161
162 $table = phutil_tag(
163 'table',
164 array(
165 'class' => 'inline-suggestion-table',
166 ),
167 $body);
168
169 $container = phutil_tag(
170 'div',
171 array(
172 'class' => 'inline-suggestion',
173 ),
174 $table);
175
176 return $container;
177 }
178
179 private function newContextView(array $lines) {
180 if (!$lines) {
181 return array();
182 }
183
184 $rows = array();
185 foreach ($lines as $index => $line) {
186 $line_cell = phutil_tag(
187 'td',
188 array(
189 'class' => 'inline-suggestion-line-cell PhabricatorMonospaced',
190 ),
191 $index + 1);
192
193 $text_cell = phutil_tag(
194 'td',
195 array(
196 'class' => 'inline-suggestion-text-cell PhabricatorMonospaced',
197 ),
198 $line);
199
200 $cells = array(
201 $line_cell,
202 $text_cell,
203 );
204
205 $rows[] = phutil_tag('tr', array(), $cells);
206 }
207
208 return $rows;
209 }
210
211}