Skip to content

Commit

Permalink
Add support for highlighting selection matches in the query editor. p…
Browse files Browse the repository at this point in the history
  • Loading branch information
RohitBhati8269 authored Jul 18, 2024
1 parent fd78faf commit 8030bc7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/en_US/preferences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions web/pgadmin/browser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions web/pgadmin/browser/static/js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
});

Expand Down
1 change: 1 addition & 0 deletions web/pgadmin/browser/templates/browser/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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());
}
Expand Down
10 changes: 10 additions & 0 deletions web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8030bc7

Please sign in to comment.