Migrate gr-diff-comment to iron-a11y-keys

Bug: Issue 4198
Change-Id: I68ca64a9b0ef5cc9e83f19521529971d260fda55
This commit is contained in:
Kasper Nilsson
2017-06-19 11:27:22 -07:00
parent 23da39d7c0
commit 9fee82ef7d
3 changed files with 26 additions and 19 deletions

View File

@@ -56,6 +56,10 @@ limitations under the License.
getKeyboardEvent(e) {
return getKeyboardEvent(e);
},
getRootTarget(e) {
return Polymer.dom(getKeyboardEvent(e)).rootTarget;
},
};
window.Gerrit = window.Gerrit || {};

View File

@@ -15,6 +15,7 @@ limitations under the License.
-->
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
<link rel="import" href="../../../bower_components/iron-autogrow-textarea/iron-autogrow-textarea.html">
<link rel="import" href="../../shared/gr-textarea/gr-textarea.html">
<link rel="import" href="../../shared/gr-button/gr-button.html">
@@ -241,8 +242,7 @@ limitations under the License.
monospace
disabled="{{disabled}}"
rows="4"
text="{{_messageText}}"
on-keydown="_handleTextareaKeydown"></gr-textarea>
text="{{_messageText}}"></gr-textarea>
<gr-formatted-text class="message"
content="[[comment.message]]"
no-trailing-margin="[[!comment.__draft]]"

View File

@@ -116,6 +116,15 @@
'_calculateActionstoShow(showActions, isRobotComment)',
],
behaviors: [
Gerrit.KeyboardShortcutBehavior,
],
keyBindings: {
'ctrl+enter meta+enter ctrl+s meta+s': '_handleSaveKey',
'esc': '_handleEsc',
},
attached() {
if (this.editing) {
this.collapsed = false;
@@ -256,23 +265,17 @@
return draft == null || draft.trim() == '';
},
_handleTextareaKeydown(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 (this._messageText.length !== 0 && e.ctrlKey) {
this._handleSave(e);
}
break;
_handleSaveKey(e) {
if (this._messageText.length) {
e.preventDefault();
this._handleSave(e);
}
},
_handleEsc(e) {
if (!this._messageText.length) {
e.preventDefault();
this._handleCancel(e);
}
},