Add preferences to enable brace matching and brace closing in the SQL editors. Fixes #2513

This commit is contained in:
Murtuza Zabuawala
2017-06-27 09:57:38 -04:00
committed by Dave Page
parent a87ee6d059
commit 1b49bb8b22
8 changed files with 62 additions and 18 deletions

View File

@@ -1,6 +1,8 @@
define([
'sources/gettext', 'sources/url_for', 'jquery','alertify', 'pgadmin','codemirror',
'sources/sqleditor_utils', 'pgadmin.browser', 'wcdocker'
'sources/sqleditor_utils', 'pgadmin.browser', 'wcdocker',
'codemirror/addon/edit/matchbrackets', 'codemirror/addon/edit/closebrackets'
], function(gettext, url_for, $, alertify, pgAdmin, codemirror, sqlEditorUtils) {
// Some scripts do export their object in the window only.
// Generally the one, which do no have AMD support.
@@ -263,13 +265,13 @@ define([
// Apply CodeMirror to filter text area.
this.filter_obj = CodeMirror.fromTextArea($sql_filter.get(0), {
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
indentUnit: 4,
mode: "text/x-pgsql",
extraKeys: pgBrowser.editor_shortcut_keys,
tabSize: pgBrowser.editor_options.tabSize,
lineWrapping: pgAdmin.Browser.editor_options.wrapCode
lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
autoCloseBrackets: pgAdmin.Browser.editor_options.insert_pair_brackets,
matchBrackets: pgAdmin.Browser.editor_options.brace_matching
});
},

View File

@@ -4,7 +4,9 @@ define([
'pgadmin.tools.debugger.ui', 'wcdocker', 'pgadmin.backform',
'pgadmin.backgrid', 'codemirror/addon/selection/active-line',
'codemirror/addon/fold/foldgutter', 'codemirror/addon/fold/foldcode',
'pgadmin-sqlfoldcode'
'pgadmin-sqlfoldcode', 'codemirror/addon/edit/matchbrackets',
'codemirror/addon/edit/closebrackets',
], function(
gettext, $, _, S, Alertify, pgAdmin, pgBrowser, Backbone, Backgrid,
CodeMirror, Backform, debug_function_again
@@ -1605,7 +1607,9 @@ define([
readOnly: true,
extraKeys: pgAdmin.Browser.editor_shortcut_keys,
tabSize: pgAdmin.Browser.editor_options.tabSize,
lineWrapping: pgAdmin.Browser.editor_options.wrapCode
lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
autoCloseBrackets: pgAdmin.Browser.editor_options.insert_pair_brackets,
matchBrackets: pgAdmin.Browser.editor_options.brace_matching
});
// On loading the docker, register the callbacks

View File

@@ -190,9 +190,24 @@ class SqlEditorModule(PgAdminModule):
'Options', 'wrap_code',
gettext("Line wrapping?"), 'boolean', False,
category_label=gettext('Options'),
help_str=gettext('Specifies whether or not to wrap SQL code in editor.')
help_str=gettext('Specifies whether or not to wrap SQL code in the editor.')
)
self.insert_pair_brackets = self.preference.register(
'Options', 'insert_pair_brackets',
gettext("Insert bracket pairs?"), 'boolean', True,
category_label=gettext('Options'),
help_str=gettext('Specifies whether or not to insert paired brackets in the editor.')
)
self.brace_matching = self.preference.register(
'Options', 'brace_matching',
gettext("Brace matching?"), 'boolean', True,
category_label=gettext('Options'),
help_str=gettext('Specifies whether or not to highlight matched braces in the editor.')
)
blueprint = SqlEditorModule(MODULE_NAME, __name__, static_url_path='/static')

View File

@@ -25,6 +25,8 @@ define([
'codemirror/addon/search/search',
'codemirror/addon/search/searchcursor',
'codemirror/addon/search/jump-to-line',
'codemirror/addon/edit/matchbrackets',
'codemirror/addon/edit/closebrackets',
'backgrid.sizeable.columns',
'slick.pgadmin.formatters',
@@ -111,7 +113,6 @@ define([
$('.editor-title').text(_.unescape(self.editor_title));
self.filter_obj = CodeMirror.fromTextArea(filter.get(0), {
lineNumbers: true,
matchBrackets: true,
indentUnit: 4,
mode: "text/x-pgsql",
foldOptions: {
@@ -124,7 +125,9 @@ define([
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
extraKeys: pgBrowser.editor_shortcut_keys,
tabSize: pgAdmin.Browser.editor_options.tabSize,
lineWrapping: pgAdmin.Browser.editor_options.wrapCode
lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
autoCloseBrackets: pgAdmin.Browser.editor_options.insert_pair_brackets,
matchBrackets: pgAdmin.Browser.editor_options.brace_matching
});
// Create main wcDocker instance
@@ -154,7 +157,6 @@ define([
self.query_tool_obj = CodeMirror.fromTextArea(text_container.get(0), {
lineNumbers: true,
matchBrackets: true,
indentUnit: 4,
styleSelectedText: true,
mode: "text/x-pgsql",
@@ -169,7 +171,9 @@ define([
extraKeys: pgBrowser.editor_shortcut_keys,
tabSize: pgAdmin.Browser.editor_options.tabSize,
lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
scrollbarStyle: 'simple'
scrollbarStyle: 'simple',
autoCloseBrackets: pgAdmin.Browser.editor_options.insert_pair_brackets,
matchBrackets: pgAdmin.Browser.editor_options.brace_matching
});
// Refresh Code mirror on SQL panel resize to