diff --git a/web/pgadmin/static/js/keyboard_shortcuts.js b/web/pgadmin/static/js/keyboard_shortcuts.js
index 91e45cd..b61365a 100644
--- a/web/pgadmin/static/js/keyboard_shortcuts.js
+++ b/web/pgadmin/static/js/keyboard_shortcuts.js
@@ -1,3 +1,12 @@
+//////////////////////////////////////////////////////////////////////////
+//
+// pgAdmin 4 - PostgreSQL Tools
+//
+// Copyright (C) 2013 - 2018, The pgAdmin Development Team
+// This software is released under the PostgreSQL Licence
+//
+//////////////////////////////////////////////////////////////////////////
+
import $ from 'jquery';
const PERIOD_KEY = 190,
diff --git a/web/pgadmin/tools/debugger/static/js/debugger_utils.js b/web/pgadmin/tools/debugger/static/js/debugger_utils.js
new file mode 100644
index 0000000..63d0232
--- /dev/null
+++ b/web/pgadmin/tools/debugger/static/js/debugger_utils.js
@@ -0,0 +1,23 @@
+//////////////////////////////////////////////////////////////////////////
+//
+// pgAdmin 4 - PostgreSQL Tools
+//
+// Copyright (C) 2013 - 2018, The pgAdmin Development Team
+// This software is released under the PostgreSQL Licence
+//
+//////////////////////////////////////////////////////////////////////////
+
+function setFocusToDebuggerEditor(editor, command) {
+ const TAB = 9;
+ if (!command)
+ return;
+ let key = command.which || command.keyCode;
+ // Keys other than Tab key
+ if (key !== TAB) {
+ editor.focus();
+ }
+}
+
+module.exports = {
+ setFocusToDebuggerEditor: setFocusToDebuggerEditor,
+};
diff --git a/web/pgadmin/tools/debugger/static/js/direct.js b/web/pgadmin/tools/debugger/static/js/direct.js
index 62cc0ba..52c9e66 100644
--- a/web/pgadmin/tools/debugger/static/js/direct.js
+++ b/web/pgadmin/tools/debugger/static/js/direct.js
@@ -2,10 +2,11 @@ define([
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
'pgadmin.alertifyjs', 'sources/pgadmin', 'pgadmin.browser', 'backbone',
'pgadmin.backgrid', 'pgadmin.backform', 'sources/../bundle/codemirror',
- 'pgadmin.tools.debugger.ui', 'sources/keyboard_shortcuts', 'wcdocker',
+ 'pgadmin.tools.debugger.ui', 'sources/keyboard_shortcuts',
+ 'pgadmin.tools.debugger.utils', 'wcdocker',
], function(
gettext, url_for, $, _, Alertify, pgAdmin, pgBrowser, Backbone, Backgrid,
- Backform, codemirror, debug_function_again, keyboardShortcuts
+ Backform, codemirror, debug_function_again, keyboardShortcuts, debuggerUtils
) {
var CodeMirror = codemirror.default,
@@ -185,7 +186,6 @@ define([
'CodeMirror-activeline-background'
);
}
-
// Call function to create and update local variables ....
self.GetStackInformation(trans_id);
if (pgTools.DirectDebug.debug_type) {
@@ -345,7 +345,6 @@ define([
'wrap', 'CodeMirror-activeline-background'
);
self.active_line_no = (res.data.result[0].linenumber - 2);
-
// Update the stack, local variables and parameters information
self.GetStackInformation(trans_id);
@@ -1211,8 +1210,10 @@ define([
});
variable_grid.collection.on(
- 'backgrid:edited', () => {
- pgTools.DirectDebug.editor.focus();
+ 'backgrid:edited', (ch1, ch2, command) => {
+ debuggerUtils.setFocusToDebuggerEditor(
+ pgTools.DirectDebug.editor, command
+ );
}
);
@@ -1294,8 +1295,10 @@ define([
});
param_grid.collection.on(
- 'backgrid:edited', () => {
- pgTools.DirectDebug.editor.focus();
+ 'backgrid:edited', (ch1, ch2, command) => {
+ debuggerUtils.setFocusToDebuggerEditor(
+ pgTools.DirectDebug.editor, command
+ );
}
);
@@ -1371,7 +1374,6 @@ define([
(res.data.result[0].linenumber - 2), 'wrap',
'CodeMirror-activeline-background'
);
-
// Call function to create and update local variables ....
self.GetLocalVariables(pgTools.DirectDebug.trans_id);
}
diff --git a/web/pgadmin/tools/debugger/templates/debugger/direct.html b/web/pgadmin/tools/debugger/templates/debugger/direct.html
index 2f748d9..58d97a0 100644
--- a/web/pgadmin/tools/debugger/templates/debugger/direct.html
+++ b/web/pgadmin/tools/debugger/templates/debugger/direct.html
@@ -52,8 +52,8 @@ try {
diff --git a/web/regression/javascript/debugger_utils_spec.js b/web/regression/javascript/debugger_utils_spec.js
new file mode 100644
index 0000000..3e6be97
--- /dev/null
+++ b/web/regression/javascript/debugger_utils_spec.js
@@ -0,0 +1,44 @@
+//////////////////////////////////////////////////////////////////////////
+//
+// pgAdmin 4 - PostgreSQL Tools
+//
+// Copyright (C) 2013 - 2018, The pgAdmin Development Team
+// This software is released under the PostgreSQL Licence
+//
+//////////////////////////////////////////////////////////////////////////
+
+import { setFocusToDebuggerEditor } from '../../pgadmin/tools/debugger/static/js/debugger_utils';
+
+describe('debuggerUtils', function () {
+ let editor;
+ editor = jasmine.createSpyObj('editor', ['focus']);
+
+ let tab_key = {
+ which: 9,
+ keyCode: 9,
+ }
+
+ let enter_key = {
+ which: 13,
+ keyCode: 13,
+ }
+
+ describe('debuggerUtils', function () {
+ it('returns undefined if no command is passed', function () {
+ expect(setFocusToDebuggerEditor(editor, null)).toEqual(undefined);
+ });
+ });
+
+ describe('debuggerUtils', function () {
+ it('should call focus on editor', function () {
+ setFocusToDebuggerEditor(editor, enter_key)
+ expect(editor.focus).toHaveBeenCalled();
+ });
+ });
+
+ describe('debuggerUtils', function () {
+ it('should not call focus on editor and returns undefined', function () {
+ expect(setFocusToDebuggerEditor(editor, tab_key)).toEqual(undefined);
+ });
+ });
+});
diff --git a/web/webpack.shim.js b/web/webpack.shim.js
index d36fe61..58b2604 100644
--- a/web/webpack.shim.js
+++ b/web/webpack.shim.js
@@ -230,6 +230,7 @@ var webpackShimConfig = {
'pgadmin.tools.import_export': path.join(__dirname, './pgadmin/tools/import_export/static/js/import_export'),
'pgadmin.node.view': path.join(__dirname, './pgadmin/browser/server_groups/servers/databases/schemas/views/static/js/view'),
'pgadmin.tools.debugger.ui': path.join(__dirname, './pgadmin/tools/debugger/static/js/debugger_ui'),
+ 'pgadmin.tools.debugger.utils': path.join(__dirname, './pgadmin/tools/debugger/static/js/debugger_utils'),
'pgadmin.node.pga_schedule': path.join(__dirname, './pgadmin/browser/server_groups/servers/pgagent/schedules/static/js/pga_schedule'),
'pgadmin.node.catalog_object_column': path.join(__dirname, './pgadmin/browser/server_groups/servers/databases/schemas/catalog_objects/columns/static/js/catalog_object_column'),
'pgadmin.browser.collection': path.join(__dirname, './pgadmin/browser/static/js/collection'),