Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 63bfad0

Browse files
author
epriestley
committed
Refine unusual inline comment client interactions
Summary: Ref T13513. Refine some inline behaviors, see test plan. Test Plan: - Edit a comment ("A"), type text ("AB"), cancel, edit. - Old behavior: edit and undo states (wrong, and undo does not function). - New behavior: edit state only. - Edit a comment ("A"), type text ("AB"), cancel. Undo ("AB"), cancel. Edit. - Old behavior: "AB" (wrong: you never submitted this text). - New behavior: "A". - Create a comment, type text, cancel. - Old behavior: counter appears in filetree (wrong, comment is undo-able but should not be counted). - New behavior: no counter. - Cancel editing an empty comment with no text. - Old behavior: Something buggy -- undo, I think? - New behavior: it just vanishes (correct behavior). Maniphest Tasks: T13513 Differential Revision: https://secure.phabricator.com/D21212
1 parent f5ef341 commit 63bfad0

File tree

4 files changed

+82
-24
lines changed

4 files changed

+82
-24
lines changed

resources/celerity/map.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'core.pkg.js' => '632fb8f5',
1414
'dark-console.pkg.js' => '187792c2',
1515
'differential.pkg.css' => '2d70b7b9',
16-
'differential.pkg.js' => 'b35de23a',
16+
'differential.pkg.js' => '4287e51f',
1717
'diffusion.pkg.css' => '42c75c37',
1818
'diffusion.pkg.js' => 'a98c0bf7',
1919
'maniphest.pkg.css' => '35995d6d',
@@ -379,9 +379,9 @@
379379
'rsrc/js/application/dashboard/behavior-dashboard-move-panels.js' => 'a2ab19be',
380380
'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '1e413dc9',
381381
'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => '0116d3e8',
382-
'rsrc/js/application/diff/DiffChangeset.js' => '9a713ba5',
382+
'rsrc/js/application/diff/DiffChangeset.js' => 'a49dc31e',
383383
'rsrc/js/application/diff/DiffChangesetList.js' => '10726e6a',
384-
'rsrc/js/application/diff/DiffInline.js' => '02791ed9',
384+
'rsrc/js/application/diff/DiffInline.js' => '7f804f2b',
385385
'rsrc/js/application/diff/DiffPathView.js' => '8207abf9',
386386
'rsrc/js/application/diff/DiffTreeView.js' => '5d83623b',
387387
'rsrc/js/application/diff/behavior-preview-link.js' => 'f51e9c17',
@@ -776,9 +776,9 @@
776776
'phabricator-darklog' => '3b869402',
777777
'phabricator-darkmessage' => '26cd4b73',
778778
'phabricator-dashboard-css' => '5a205b9d',
779-
'phabricator-diff-changeset' => '9a713ba5',
779+
'phabricator-diff-changeset' => 'a49dc31e',
780780
'phabricator-diff-changeset-list' => '10726e6a',
781-
'phabricator-diff-inline' => '02791ed9',
781+
'phabricator-diff-inline' => '7f804f2b',
782782
'phabricator-diff-path-view' => '8207abf9',
783783
'phabricator-diff-tree-view' => '5d83623b',
784784
'phabricator-drag-and-drop-file-upload' => '4370900d',
@@ -944,9 +944,6 @@
944944
'javelin-leader',
945945
'javelin-json',
946946
),
947-
'02791ed9' => array(
948-
'javelin-dom',
949-
),
950947
'02cb4398' => array(
951948
'javelin-behavior',
952949
'javelin-dom',
@@ -1629,6 +1626,9 @@
16291626
'javelin-install',
16301627
'javelin-dom',
16311628
),
1629+
'7f804f2b' => array(
1630+
'javelin-dom',
1631+
),
16321632
'80bff3af' => array(
16331633
'javelin-install',
16341634
'javelin-typeahead-source',
@@ -1797,19 +1797,6 @@
17971797
'javelin-request',
17981798
'javelin-util',
17991799
),
1800-
'9a713ba5' => array(
1801-
'javelin-dom',
1802-
'javelin-util',
1803-
'javelin-stratcom',
1804-
'javelin-install',
1805-
'javelin-workflow',
1806-
'javelin-router',
1807-
'javelin-behavior-device',
1808-
'javelin-vector',
1809-
'phabricator-diff-inline',
1810-
'phabricator-diff-path-view',
1811-
'phuix-button-view',
1812-
),
18131800
'9aae2b66' => array(
18141801
'javelin-install',
18151802
'javelin-util',
@@ -1863,6 +1850,19 @@
18631850
'javelin-stratcom',
18641851
'javelin-vector',
18651852
),
1853+
'a49dc31e' => array(
1854+
'javelin-dom',
1855+
'javelin-util',
1856+
'javelin-stratcom',
1857+
'javelin-install',
1858+
'javelin-workflow',
1859+
'javelin-router',
1860+
'javelin-behavior-device',
1861+
'javelin-vector',
1862+
'phabricator-diff-inline',
1863+
'phabricator-diff-path-view',
1864+
'phuix-button-view',
1865+
),
18661866
'a4aa75c4' => array(
18671867
'phui-button-css',
18681868
'phui-button-simple-css',

src/infrastructure/diff/PhabricatorInlineCommentController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ public function processRequest() {
220220

221221
$inline->setIsEditing(false);
222222

223+
// If the user uses "Undo" to get into an edited state ("AB"), then
224+
// clicks cancel to return to the previous state ("A"), we also want
225+
// to set the stored state back to "A".
226+
$text = $this->getCommentText();
227+
if (strlen($text)) {
228+
$inline->setContent($text);
229+
}
230+
223231
$content = $inline->getContent();
224232
if (!strlen($content)) {
225233
$this->deleteComment($inline);

webroot/rsrc/js/application/diff/DiffChangeset.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,10 @@ JX.install('DiffChangeset', {
829829
continue;
830830
}
831831

832+
if (inline.isUndo()) {
833+
continue;
834+
}
835+
832836
if (inline.isSynthetic()) {
833837
continue;
834838
}

webroot/rsrc/js/application/diff/DiffInline.js

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ JX.install('DiffInline', {
6565

6666
this._number = parseInt(data.number, 10);
6767
this._length = parseInt(data.length, 10);
68-
this._originalText = data.original;
68+
69+
var original = '' + data.original;
70+
if (original.length) {
71+
this._originalText = original;
72+
} else {
73+
this._originalText = null;
74+
}
6975
this._isNewFile = data.isNewFile;
7076

7177
this._replyToCommentPHID = data.replyToCommentPHID;
@@ -103,6 +109,10 @@ JX.install('DiffInline', {
103109
return this._isEditing;
104110
},
105111

112+
isUndo: function() {
113+
return !!this._undoRow;
114+
},
115+
106116
isDeleted: function() {
107117
return this._isDeleted;
108118
},
@@ -370,8 +380,21 @@ JX.install('DiffInline', {
370380
},
371381

372382
edit: function(text) {
383+
// If you edit an inline ("A"), modify the text ("AB"), cancel, and then
384+
// edit it again: discard the undo state ("AB"). Otherwise we end up
385+
// with an open editor and an active "Undo" link, which is weird.
386+
387+
if (this._undoRow) {
388+
JX.DOM.remove(this._undoRow);
389+
this._undoRow = null;
390+
391+
this._undoType = null;
392+
this._undoText = null;
393+
}
394+
373395
var uri = this._getInlineURI();
374396
var handler = JX.bind(this, this._oneditresponse);
397+
375398
var data = this._newRequestData('edit', text || null);
376399

377400
this.setLoading(true);
@@ -647,10 +670,21 @@ JX.install('DiffInline', {
647670
}
648671

649672
this.setEditing(false);
650-
this.setInvisible(false);
673+
674+
// If this was an empty box and we typed some text and then hit cancel,
675+
// don't show the empty concrete inline.
676+
if (!this._originalText) {
677+
this.setInvisible(true);
678+
} else {
679+
this.setInvisible(false);
680+
}
681+
682+
// If you "undo" to restore text ("AB") and then "Cancel", we put you
683+
// back in the original text state ("A"). We also send the original
684+
// text ("A") to the server as the current persistent state.
651685

652686
var uri = this._getInlineURI();
653-
var data = this._newRequestData('cancel');
687+
var data = this._newRequestData('cancel', this._originalText);
654688
var handler = JX.bind(this, this._onCancelResponse);
655689

656690
this.setLoading(true);
@@ -664,6 +698,18 @@ JX.install('DiffInline', {
664698

665699
_onCancelResponse: function(response) {
666700
this.setLoading(false);
701+
702+
// If the comment was empty when we started editing it (there's no
703+
// original text) and empty when we finished editing it (there's no
704+
// undo row), just delete the comment.
705+
if (!this._originalText && !this.isUndo()) {
706+
this.setDeleted(true);
707+
708+
JX.DOM.remove(this._row);
709+
this._row = null;
710+
711+
this._didUpdate();
712+
}
667713
},
668714

669715
_readText: function(row) {

0 commit comments

Comments
 (0)