Hi Dave,

Please find updated patch.

On Mon, Oct 16, 2017 at 5:56 PM, Dave Page <dp...@pgadmin.org> wrote:

> Hi
>
> On Mon, Oct 16, 2017 at 1:21 PM, Murtuza Zabuawala <
> murtuza.zabuaw...@enterprisedb.com> wrote:
>
>> Sorry, that was a typo in 'sqleditor/__init__.py'.
>>
>> I have updated the patch, We require this option because by default
>> codemirror indent the code with spaces.
>>
>> Steps to re-produce (without patch):
>> 1) With preference option
>>   Use spaces? = False
>>   Tab size = 4
>>
>> 2) Open query tool
>> - Press Tabs key 3-4 times & type select 1; <enter>
>> - Observe the new line indentation using right arrow key. (Attaching
>> screenshot)
>>
>> This patch allow us to use Tab key as indentation.
>>
>> Now apply the patch set the option Use tabs for indentation? to true and
>> check the same behaviour.
>>
>
> I understand the problem, but what I don't understand is why we need a new
> option for it, given that we already have use_spaces.
>
> I can't think of any reason why you would want the two settings to have
> different values... therefore, why not have just one setting that is
> honoured whether the indent is the result of the user pressing the tab key,
> or an auto-indent following an end of line?
>
>>
>>
>> On Mon, Oct 16, 2017 at 2:14 PM, Dave Page <dp...@pgadmin.org> wrote:
>>
>>> Hi
>>>
>>> On Mon, Oct 16, 2017 at 5:43 AM, Murtuza Zabuawala <
>>> murtuza.zabuaw...@enterprisedb.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> PFA patch to fix the issue where indentation is not working as
>>>> expected, when user opt for tab based indentation instead of space based
>>>> indentation.
>>>> RM#2780
>>>>
>>>
>>> Shouldn't we just use the use_spaces option here? I don't see any reason
>>> why pressing tab vs. an auto-indent should be any different.
>>>
>>> As a sidenote, in sqleditor/__init__.py, both config options are being
>>> defined as "self.use_spaces = ..."
>>>
>>> --
>>> Dave Page
>>> Blog: http://pgsnake.blogspot.com
>>> Twitter: @pgsnake
>>>
>>> EnterpriseDB UK: http://www.enterprisedb.com
>>> The Enterprise PostgreSQL Company
>>>
>>
>>
>
>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>
diff --git a/web/pgadmin/browser/__init__.py b/web/pgadmin/browser/__init__.py
index 7778805..f5b88a9 100644
--- a/web/pgadmin/browser/__init__.py
+++ b/web/pgadmin/browser/__init__.py
@@ -555,6 +555,9 @@ def utils():
     insert_pair_brackets_perf = prefs.preference('insert_pair_brackets')
     insert_pair_brackets = insert_pair_brackets_perf.get()
 
+    # This will be opposite of use_space option
+    editor_indent_with_tabs = False if editor_use_spaces else True
+
     # Try to fetch current libpq version from the driver
     try:
         from config import PG_DEFAULT_DRIVER
@@ -578,6 +581,7 @@ def utils():
             editor_wrap_code=editor_wrap_code,
             editor_brace_matching=brace_matching,
             editor_insert_pair_brackets=insert_pair_brackets,
+            editor_indent_with_tabs=editor_indent_with_tabs,
             app_name=config.APP_NAME,
             pg_libpq_version=pg_libpq_version
         ),
diff --git a/web/pgadmin/browser/static/js/browser.js 
b/web/pgadmin/browser/static/js/browser.js
index 5c82743..ad4f84b 100644
--- a/web/pgadmin/browser/static/js/browser.js
+++ b/web/pgadmin/browser/static/js/browser.js
@@ -1970,7 +1970,8 @@ define(
       tabSize: pgBrowser.utils.tabSize,
       wrapCode: pgBrowser.utils.wrapCode,
       insert_pair_brackets: pgBrowser.utils.insertPairBrackets,
-      brace_matching: pgBrowser.utils.braceMatching
+      brace_matching: pgBrowser.utils.braceMatching,
+      indent_with_tabs: pgBrowser.utils.is_indent_with_tabs
     }
 
   });
diff --git a/web/pgadmin/browser/templates/browser/js/utils.js 
b/web/pgadmin/browser/templates/browser/js/utils.js
index fc475dd..be3b712 100644
--- a/web/pgadmin/browser/templates/browser/js/utils.js
+++ b/web/pgadmin/browser/templates/browser/js/utils.js
@@ -23,6 +23,7 @@ define('pgadmin.browser.utils',
     useSpaces: '{{ editor_use_spaces }}',
     insertPairBrackets: '{{ editor_insert_pair_brackets }}' == 'True',
     braceMatching: '{{ editor_brace_matching }}' == 'True',
+    is_indent_with_tabs: '{{ editor_indent_with_tabs }}' == 'True',
     app_name: '{{ app_name }}',
     pg_libpq_version: {{pg_libpq_version|e}},
 
diff --git a/web/pgadmin/static/js/backform.pgadmin.js 
b/web/pgadmin/static/js/backform.pgadmin.js
index 93a933c..0fb8485 100644
--- a/web/pgadmin/static/js/backform.pgadmin.js
+++ b/web/pgadmin/static/js/backform.pgadmin.js
@@ -2049,6 +2049,8 @@
             lineNumbers: true,
             mode: "text/x-pgsql",
             extraKeys: pgAdmin.Browser.editor_shortcut_keys,
+            indentWithTabs: pgAdmin.Browser.editor_options.indent_with_tabs,
+            indentUnit: pgAdmin.Browser.editor_options.tabSize,
             tabSize: pgAdmin.Browser.editor_options.tabSize,
             lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
             autoCloseBrackets: 
pgAdmin.Browser.editor_options.insert_pair_brackets,
diff --git a/web/pgadmin/tools/datagrid/static/js/datagrid.js 
b/web/pgadmin/tools/datagrid/static/js/datagrid.js
index c67bf4e..28ac09b 100644
--- a/web/pgadmin/tools/datagrid/static/js/datagrid.js
+++ b/web/pgadmin/tools/datagrid/static/js/datagrid.js
@@ -258,9 +258,10 @@ define('pgadmin.datagrid', [
                 // Apply CodeMirror to filter text area.
                 this.filter_obj = CodeMirror.fromTextArea($sql_filter.get(0), {
                   lineNumbers: true,
-                  indentUnit: 4,
                   mode: "text/x-pgsql",
                   extraKeys: pgBrowser.editor_shortcut_keys,
+                  indentWithTabs: 
pgAdmin.Browser.editor_options.indent_with_tabs,
+                  indentUnit: pgAdmin.Browser.editor_options.tabSize,
                   tabSize: pgBrowser.editor_options.tabSize,
                   lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
                   autoCloseBrackets: 
pgAdmin.Browser.editor_options.insert_pair_brackets,
diff --git a/web/pgadmin/tools/debugger/static/js/direct.js 
b/web/pgadmin/tools/debugger/static/js/direct.js
index 6906d09..33597a7 100644
--- a/web/pgadmin/tools/debugger/static/js/direct.js
+++ b/web/pgadmin/tools/debugger/static/js/direct.js
@@ -1636,6 +1636,8 @@ define([
           mode: "text/x-pgsql",
           readOnly: true,
           extraKeys: pgAdmin.Browser.editor_shortcut_keys,
+          indentWithTabs: pgAdmin.Browser.editor_options.indent_with_tabs,
+          indentUnit: pgAdmin.Browser.editor_options.tabSize,
           tabSize: pgAdmin.Browser.editor_options.tabSize,
           lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
           autoCloseBrackets: 
pgAdmin.Browser.editor_options.insert_pair_brackets,
diff --git a/web/pgadmin/tools/sqleditor/__init__.py 
b/web/pgadmin/tools/sqleditor/__init__.py
index ee7dc8c..753e09b 100644
--- a/web/pgadmin/tools/sqleditor/__init__.py
+++ b/web/pgadmin/tools/sqleditor/__init__.py
@@ -117,9 +117,13 @@ class SqlEditorModule(PgAdminModule):
             category_label=gettext('Display'),
             min_val=-1,
             max_val=999999,
-            help_str=gettext('The length of time to display the query info 
notifier after execution has completed. '
-                             'A value of -1 disables the notifier and a value 
of 0 displays it until clicked. '
-                             'Values greater than 1 display the notifier for 
the number of seconds specified.')
+            help_str=gettext(
+                'The length of time to display the query info notifier after '
+                'execution has completed. A value of -1 disables the notifier '
+                'and a value of 0 displays it until clicked. Values greater '
+                'than 1 display the notifier for the number of seconds '
+                'specified.'
+            )
         )
 
         self.open_in_new_tab = self.preference.register(
@@ -172,10 +176,13 @@ class SqlEditorModule(PgAdminModule):
             min_val=0.1,
             max_val=10,
             category_label=gettext('Display'),
-            help_str=gettext('The font size to use for the SQL text boxes and 
editors. '
-                             'The value specified is in "em" units, in which 1 
is the default relative font size. '
-                             'For example, to increase the font size by 20 
percent use a value of 1.2, or to reduce '
-                             'by 20 percent, use a value of 0.8. Minimum 0.1, 
maximum 10.')
+            help_str=gettext(
+                'The font size to use for the SQL text boxes and editors. '
+                'The value specified is in "em" units, in which 1 is the '
+                'default relative font size. For example, to increase the '
+                'font size by 20 percent use a value of 1.2, or to reduce '
+                'by 20 percent, use a value of 0.8. Minimum 0.1, maximum 10.'
+            )
         )
 
         self.tab_size = self.preference.register(
@@ -184,35 +191,48 @@ class SqlEditorModule(PgAdminModule):
             min_val=2,
             max_val=8,
             category_label=gettext('Options'),
-            help_str=gettext('The number of spaces per tab. Minimum 2, maximum 
8.')
+            help_str=gettext(
+                'The number of spaces per tab. Minimum 2, maximum 8.'
+            )
         )
 
         self.use_spaces = self.preference.register(
             'Options', 'use_spaces',
             gettext("Use spaces?"), 'boolean', False,
             category_label=gettext('Options'),
-            help_str=gettext('Specifies whether or not to insert spaces 
instead of tabs when the tab key is used.')
+            help_str=gettext(
+                'Specifies whether or not to insert spaces instead of tabs '
+                'when the tab key is used.'
+            )
         )
 
         self.wrap_code = self.preference.register(
             'Options', 'wrap_code',
             gettext("Line wrapping?"), 'boolean', False,
             category_label=gettext('Options'),
-            help_str=gettext('Specifies whether or not to wrap SQL code in the 
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.')
+            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.')
+            help_str=gettext(
+                'Specifies whether or not to highlight matched braces '
+                'in the editor.'
+            )
         )
 
 
@@ -222,7 +242,9 @@ blueprint = SqlEditorModule(MODULE_NAME, __name__, 
static_url_path='/static')
 @blueprint.route('/')
 @login_required
 def index():
-    return bad_request(errormsg=gettext('This URL cannot be requested 
directly.'))
+    return bad_request(
+        errormsg=gettext('This URL cannot be requested directly.')
+    )
 
 
 def update_session_grid_transaction(trans_id, data):
@@ -248,7 +270,9 @@ def check_transaction_status(trans_id):
 
     # Return from the function if transaction id not found
     if str(trans_id) not in grid_data:
-        return False, gettext('Transaction ID not found in the session.'), 
None, None, None
+        return False, gettext(
+            'Transaction ID not found in the session.'
+        ), None, None, None
 
     # Fetch the object for the specified transaction id.
     # Use pickle.loads function to get the command object
diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js 
b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
index 8dc22cf..177788c 100644
--- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
@@ -109,7 +109,6 @@ define('tools.querytool', [
       $('.editor-title').text(_.unescape(self.editor_title));
       self.filter_obj = CodeMirror.fromTextArea(filter.get(0), {
         lineNumbers: true,
-        indentUnit: 4,
         mode: self.handler.server_type === "gpdb" ? "text/x-gpsql" : 
"text/x-pgsql",
         foldOptions: {
           widget: "\u2026"
@@ -120,6 +119,8 @@ define('tools.querytool', [
         },
         gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
         extraKeys: pgBrowser.editor_shortcut_keys,
+        indentWithTabs: pgAdmin.Browser.editor_options.indent_with_tabs,
+        indentUnit: pgAdmin.Browser.editor_options.tabSize,
         tabSize: pgAdmin.Browser.editor_options.tabSize,
         lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
         autoCloseBrackets: pgAdmin.Browser.editor_options.insert_pair_brackets,
@@ -153,7 +154,6 @@ define('tools.querytool', [
 
       self.query_tool_obj = CodeMirror.fromTextArea(text_container.get(0), {
         lineNumbers: true,
-        indentUnit: 4,
         styleSelectedText: true,
         mode: self.handler.server_type === "gpdb" ? "text/x-gpsql" : 
"text/x-pgsql",
         foldOptions: {
@@ -165,6 +165,8 @@ define('tools.querytool', [
         },
         gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
         extraKeys: pgBrowser.editor_shortcut_keys,
+        indentWithTabs: pgAdmin.Browser.editor_options.indent_with_tabs,
+        indentUnit: pgAdmin.Browser.editor_options.tabSize,
         tabSize: pgAdmin.Browser.editor_options.tabSize,
         lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
         scrollbarStyle: 'simple',

Reply via email to