Merge "Add check for modifiers in keyboard shortcut handlers"

This commit is contained in:
Andrew Bonventre
2016-12-09 16:51:49 +00:00
committed by Gerrit Code Review
7 changed files with 58 additions and 25 deletions

View File

@@ -165,7 +165,8 @@
},
_handleJKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
var len = this._getAggregateGroupsLen(this.groups);
@@ -174,7 +175,8 @@
},
_handleKKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
if (this.selectedIndex === 0) { return; }
@@ -182,7 +184,8 @@
},
_handleEnterKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
page.show(this._changeURLForIndex(this.selectedIndex));

View File

@@ -607,26 +607,32 @@
},
_handleAKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (!this._loggedIn || e.detail.keyboardEvent.shiftKey) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e) ||
!this._loggedIn) { return; }
e.preventDefault();
this._openReplyDialog();
},
_handleDKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this.$.downloadOverlay.open();
},
_handleCapitalRKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
e.preventDefault();
this._switchToMostRecentPatchNum();
},
_handleUKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
e.preventDefault();
this._determinePageBack();
},

View File

@@ -340,8 +340,9 @@
},
_handleIKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.$.fileCursor.index === -1) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e) ||
this.$.fileCursor.index === -1) { return; }
e.preventDefault();
var expanded = this._files[this.$.fileCursor.index].__expanded;
@@ -381,7 +382,8 @@
},
_handleCKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
var isRangeSelected = this.diffs.some(function(diff) {
return diff.isRangeSelected();
@@ -393,21 +395,24 @@
},
_handleLeftBracketKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this._openSelectedFile(this._files.length - 1);
},
_handleRightBracketKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this._openSelectedFile(0);
},
_handleEnterKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
if (this._showInlineDiffs) {
@@ -418,7 +423,8 @@
},
_handleNKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
if (!this._showInlineDiffs) { return; }
e.preventDefault();
@@ -430,7 +436,8 @@
},
_handlePKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
if (!this._showInlineDiffs) { return; }
e.preventDefault();

View File

@@ -297,7 +297,8 @@
},
_handleForwardSlashKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this.$.searchInput.focus();

View File

@@ -97,7 +97,12 @@
// Dont preventDefault in this case because it will render the event
// useless for other handlers (other gr-diff-comment-thread elements).
this._expandCollapseComments(e.detail.keyboardEvent.shiftKey);
if (e.detail.keyboardEvent.shiftKey) {
this._expandCollapseComments(true);
} else {
if (this.modifierPressed(e)) { return; }
this._expandCollapseComments(false);
}
},
_expandCollapseComments: function(actionIsCollapse) {

View File

@@ -202,7 +202,8 @@
},
_handleEscKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this.$.diff.displayLine = false;
@@ -223,7 +224,8 @@
},
_handleUpKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this.$.diff.displayLine = true;
@@ -231,7 +233,8 @@
},
_handleDownKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this.$.diff.displayLine = true;
@@ -251,14 +254,16 @@
},
_handleLeftBracketKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this._navToFile(this._path, this._fileList, -1);
},
_handleRightBracketKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this._navToFile(this._path, this._fileList, 1);
@@ -271,6 +276,7 @@
if (e.detail.keyboardEvent.shiftKey) {
this.$.cursor.moveToNextCommentThread();
} else {
if (this.modifierPressed(e)) { return; }
this.$.cursor.moveToNextChunk();
}
},
@@ -282,6 +288,7 @@
if (e.detail.keyboardEvent.shiftKey) {
this.$.cursor.moveToPreviousCommentThread();
} else {
if (this.modifierPressed(e)) { return; }
this.$.cursor.moveToPreviousChunk();
}
},
@@ -295,6 +302,8 @@
return;
}
if (this.modifierPressed(e)) { return; }
if (!this._loggedIn) { return; }
this.set('changeViewState.showReplyDialog', true);
@@ -303,14 +312,16 @@
},
_handleUKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this._navToChangeView();
},
_handleCommaKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this._openPrefs();

View File

@@ -79,8 +79,8 @@
},
_handleCKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
if (this.modifierPressed(e)) { return; }
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this._fireCreateComment();