mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Add keyboard navigation in Query tool module via Tab/Shift-Tab key. Fixes #2896
Note: 1) Once the keyboard shortcut infrastructure is ready we will add generic shortcut to focus out from CodeMirror editor and set foucs to next element, Right now there is no way of doing this, For testing purpose you can manually focus out from CodeMirror and click on data output panel to continue navigate using Tab key. 2) As of now inner panel's are not getting focused on Tab/Shift-Tab keys but once RM#2895 patch gets committed it will start working automatically as it's inherited code which will add tabindex tag automatically on each newly created wcDocker panel.
This commit is contained in:
committed by
Dave Page
parent
5cea5f8485
commit
97760d65c2
@@ -1,81 +0,0 @@
|
||||
const F5_KEY = 116,
|
||||
F7_KEY = 118,
|
||||
F8_KEY = 119,
|
||||
PERIOD_KEY = 190,
|
||||
FWD_SLASH_KEY = 191;
|
||||
|
||||
function keyboardShortcuts(sqlEditorController, queryToolActions, event) {
|
||||
if (sqlEditorController.isQueryRunning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let keyCode = event.which || event.keyCode;
|
||||
|
||||
if (keyCode === F5_KEY) {
|
||||
event.preventDefault();
|
||||
queryToolActions.executeQuery(sqlEditorController);
|
||||
} else if (event.shiftKey && keyCode === F7_KEY) {
|
||||
_stopEventPropagation();
|
||||
queryToolActions.explainAnalyze(sqlEditorController);
|
||||
} else if (keyCode === F7_KEY) {
|
||||
_stopEventPropagation();
|
||||
queryToolActions.explain(sqlEditorController);
|
||||
} else if (keyCode === F8_KEY) {
|
||||
event.preventDefault();
|
||||
queryToolActions.download(sqlEditorController);
|
||||
} else if ((
|
||||
(this.isMac() && event.metaKey) ||
|
||||
(!this.isMac() && event.ctrlKey)
|
||||
) && !event.altKey && event.shiftKey && keyCode === FWD_SLASH_KEY) {
|
||||
_stopEventPropagation();
|
||||
queryToolActions.commentBlockCode(sqlEditorController);
|
||||
} else if ((
|
||||
(this.isMac() && !this.isKeyCtrlAltShift(event) && event.metaKey) ||
|
||||
(!this.isMac() && !this.isKeyAltShift(event) && event.ctrlKey)
|
||||
) && keyCode === FWD_SLASH_KEY) {
|
||||
_stopEventPropagation();
|
||||
queryToolActions.commentLineCode(sqlEditorController);
|
||||
} else if ((
|
||||
(this.isMac() && !this.isKeyCtrlAltShift(event) && event.metaKey) ||
|
||||
(!this.isMac() && !this.isKeyAltShift(event) && event.ctrlKey)
|
||||
) && keyCode === PERIOD_KEY) {
|
||||
_stopEventPropagation();
|
||||
queryToolActions.uncommentLineCode(sqlEditorController);
|
||||
}
|
||||
|
||||
function _stopEventPropagation() {
|
||||
event.cancelBubble = true;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
}
|
||||
|
||||
function isMac() {
|
||||
return window.navigator.platform.search('Mac') != -1;
|
||||
}
|
||||
|
||||
function isKeyCtrlAlt(event) {
|
||||
return event.ctrlKey || event.altKey;
|
||||
}
|
||||
|
||||
function isKeyAltShift(event) {
|
||||
return event.altKey || event.shiftKey;
|
||||
}
|
||||
|
||||
function isKeyCtrlShift(event) {
|
||||
return event.ctrlKey || event.shiftKey;
|
||||
}
|
||||
|
||||
function isKeyCtrlAltShift(event) {
|
||||
return event.ctrlKey || event.altKey || event.shiftKey;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
processEvent: keyboardShortcuts,
|
||||
isMac: isMac,
|
||||
isKeyCtrlAlt: isKeyCtrlAlt,
|
||||
isKeyAltShift: isKeyAltShift,
|
||||
isKeyCtrlShift: isKeyCtrlShift,
|
||||
isKeyCtrlAltShift: isKeyCtrlAltShift,
|
||||
};
|
||||
Reference in New Issue
Block a user