From 8030bc708b32ad0a4743ea3c2b8a111287645d4d Mon Sep 17 00:00:00 2001 From: Rohit Bhati Date: Thu, 18 Jul 2024 17:51:20 +0530 Subject: [PATCH] Add support for highlighting selection matches in the query editor. #7530 --- docs/en_US/preferences.rst | 3 +++ web/pgadmin/browser/__init__.py | 6 ++++++ web/pgadmin/browser/static/js/browser.js | 1 + web/pgadmin/browser/templates/browser/js/utils.js | 1 + .../components/ReactCodeMirror/components/Editor.jsx | 7 ++++++- .../tools/sqleditor/utils/query_tool_preferences.py | 10 ++++++++++ 6 files changed, 27 insertions(+), 1 deletion(-) diff --git a/docs/en_US/preferences.rst b/docs/en_US/preferences.rst index 0a0ff3154b4..c2d6105fff8 100644 --- a/docs/en_US/preferences.rst +++ b/docs/en_US/preferences.rst @@ -400,6 +400,9 @@ Use the fields on the *Editor* panel to change settings of the query editor. changed to text/plain. Keyword highlighting and code folding will be disabled. This will improve editor performance with large files. +* When the *Highlight selection matches?* switch is set to *True*, the editor will + highlight matched selected text. + .. image:: images/preferences_sql_explain.png :alt: Preferences dialog sqleditor explain options :align: center diff --git a/web/pgadmin/browser/__init__.py b/web/pgadmin/browser/__init__.py index f5a3ee8917e..1867d6e8677 100644 --- a/web/pgadmin/browser/__init__.py +++ b/web/pgadmin/browser/__init__.py @@ -490,6 +490,11 @@ def utils(): brace_matching_pref = prefs.preference('brace_matching') brace_matching = brace_matching_pref.get() + highlight_selection_matches_pref = prefs.preference( + 'highlight_selection_matches' + ) + highlight_selection_matches = highlight_selection_matches_pref.get() + insert_pair_brackets_perf = prefs.preference('insert_pair_brackets') insert_pair_brackets = insert_pair_brackets_perf.get() @@ -542,6 +547,7 @@ def utils(): editor_use_spaces=editor_use_spaces, editor_wrap_code=editor_wrap_code, editor_brace_matching=brace_matching, + editor_highlight_selection_matches=highlight_selection_matches, editor_insert_pair_brackets=insert_pair_brackets, editor_indent_with_tabs=editor_indent_with_tabs, app_name=config.APP_NAME, diff --git a/web/pgadmin/browser/static/js/browser.js b/web/pgadmin/browser/static/js/browser.js index b3c428972fb..96bc2970506 100644 --- a/web/pgadmin/browser/static/js/browser.js +++ b/web/pgadmin/browser/static/js/browser.js @@ -1728,6 +1728,7 @@ define('pgadmin.browser', [ insert_pair_brackets: pgBrowser.utils.insertPairBrackets, brace_matching: pgBrowser.utils.braceMatching, indent_with_tabs: pgBrowser.utils.is_indent_with_tabs, + highlightSelectionMatches:pgBrowser.utils.highlightSelectionMatches }, }); diff --git a/web/pgadmin/browser/templates/browser/js/utils.js b/web/pgadmin/browser/templates/browser/js/utils.js index c0435b3ac32..c30a851ab17 100644 --- a/web/pgadmin/browser/templates/browser/js/utils.js +++ b/web/pgadmin/browser/templates/browser/js/utils.js @@ -93,6 +93,7 @@ define('pgadmin.browser.utils', useSpaces: '{{ editor_use_spaces }}', insertPairBrackets: '{{ editor_insert_pair_brackets }}' == 'True', braceMatching: '{{ editor_brace_matching }}' == 'True', + highlightSelectionMatches: '{{editor_highlight_selection_matches}}' == 'True', is_indent_with_tabs: '{{ editor_indent_with_tabs }}' == 'True', app_name: '{{ app_name }}', app_version_int: '{{ app_version_int}}', diff --git a/web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx b/web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx index d6e4c08e086..f7c22f74484 100644 --- a/web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx +++ b/web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx @@ -38,7 +38,7 @@ import { foldKeymap, indentService } from '@codemirror/language'; - +import { highlightSelectionMatches } from '@codemirror/search'; import syntaxHighlighting from '../extensions/highlighting'; import PgSQL from '../extensions/dialect'; import { sql } from '@codemirror/lang-sql'; @@ -343,6 +343,11 @@ export default function Editor({ if (pref.insert_pair_brackets) { newConfigExtn.push(closeBrackets()); } + + if (pref.highlight_selection_matches){ + newConfigExtn.push(highlightSelectionMatches()); + } + if (pref.brace_matching) { newConfigExtn.push(bracketMatching()); } diff --git a/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py b/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py index e120644ca77..354a36ad57a 100644 --- a/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py +++ b/web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py @@ -208,6 +208,16 @@ def register_query_tool_preferences(self): ) ) + self.highlight_selection_matches = self.preference.register( + 'Editor', 'highlight_selection_matches', + gettext("Highlight selection matches?"), 'boolean', True, + category_label=PREF_LABEL_OPTIONS, + help_str=gettext( + 'Specifies whether or not to highlight matched selected text ' + 'in the editor.' + ) + ) + self.brace_matching = self.preference.register( 'Editor', 'brace_matching', gettext("Brace matching?"), 'boolean', True,