Save comments on Ctrl+Enter and Meta+Enter

Feature: Issue 4997
Change-Id: Ia1887b3ee558b96182e3ea987370c9f555c90502
This commit is contained in:
Viktar Donich 2017-02-24 16:26:32 -08:00
parent 08f265c97f
commit a2cfc65301
3 changed files with 71 additions and 14 deletions
polygerrit-ui/app/elements
core/gr-keyboard-shortcuts-dialog
diff/gr-diff-comment

@ -378,7 +378,11 @@ limitations under the License.
<tr>
<td>
<span class="key modifier">Ctrl</span>
<span class="key">s</span>
<span class="key">s</span><br/>
<span class="key modifier">Ctrl</span>
<span class="key">Enter</span><br/>
<span class="key modifier">Meta</span>
<span class="key">Enter</span>
</td>
<td>Save comment</td>
</tr>

@ -243,13 +243,18 @@
_handleTextareaKeydown: function(e) {
switch (e.keyCode) {
case 13: // 'enter'
if (this._messageText.length !== 0 && (e.metaKey || e.ctrlKey)) {
this._handleSave(e);
}
break;
case 27: // 'esc'
if (this._messageText.length === 0) {
this._handleCancel(e);
}
break;
case 83: // 's'
if (e.ctrlKey) {
if (this._messageText.length !== 0 && e.ctrlKey) {
this._handleSave(e);
}
break;

@ -175,19 +175,67 @@ limitations under the License.
'header middle content is is not visible');
});
test('esc does not close comment unless text is empty', function(done) {
element.editing = true;
element._messageText = 'test';
var textarea = element.$.editTextarea;
var closeSpy = sandbox.spy(element, '_handleCancel');
suite('while editing', function() {
setup(function() {
element.editing = true;
element._messageText = 'test';
sandbox.stub(element, '_handleCancel');
sandbox.stub(element, '_handleSave');
flushAsynchronousOperations();
});
flush(function() {
MockInteractions.pressAndReleaseKeyOn(textarea, 27); // esc
assert.isFalse(closeSpy.called);
element._messageText = '';
MockInteractions.pressAndReleaseKeyOn(textarea, 27); // esc
assert.isTrue(closeSpy.called);
done();
suite('when text is empty', function() {
setup(function() {
element._messageText = '';
});
test('esc closes comment when text is empty', function() {
MockInteractions.pressAndReleaseKeyOn(
element.$.editTextarea, 27); // esc
assert.isTrue(element._handleCancel.called);
});
test('ctrl+enter does not save', function() {
MockInteractions.pressAndReleaseKeyOn(
element.$.editTextarea, 13, 'ctrl'); // ctrl + enter
assert.isFalse(element._handleSave.called);
});
test('meta+enter does not save', function() {
MockInteractions.pressAndReleaseKeyOn(
element.$.editTextarea, 13, 'meta'); // meta + enter
assert.isFalse(element._handleSave.called);
});
test('ctrl+s does not save', function() {
MockInteractions.pressAndReleaseKeyOn(
element.$.editTextarea, 83, 'ctrl'); // ctrl + s
assert.isFalse(element._handleSave.called);
});
});
test('esc does not close comment that has content', function() {
MockInteractions.pressAndReleaseKeyOn(
element.$.editTextarea, 27); // esc
assert.isFalse(element._handleCancel.called);
});
test('ctrl+enter saves', function() {
MockInteractions.pressAndReleaseKeyOn(
element.$.editTextarea, 13, 'ctrl'); // ctrl + enter
assert.isTrue(element._handleSave.called);
});
test('meta+enter saves', function() {
MockInteractions.pressAndReleaseKeyOn(
element.$.editTextarea, 13, 'meta'); // meta + enter
assert.isTrue(element._handleSave.called);
});
test('ctrl+s saves', function() {
MockInteractions.pressAndReleaseKeyOn(
element.$.editTextarea, 83, 'ctrl'); // ctrl + s
assert.isTrue(element._handleSave.called);
});
});
});