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

View File

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

View File

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

View File

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

View File

@@ -97,7 +97,12 @@
// Dont preventDefault in this case because it will render the event // Dont preventDefault in this case because it will render the event
// useless for other handlers (other gr-diff-comment-thread elements). // 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) { _expandCollapseComments: function(actionIsCollapse) {

View File

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

View File

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