Skip to content

Commit

Permalink
Add autoSurround setting
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannQDQ authored and nyalldawson committed Jan 10, 2023
1 parent 59332e0 commit e6f2fc1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions python/console/console_settings.py
Expand Up @@ -203,6 +203,7 @@ def saveSettings(self):

settings.setValue("pythonConsole/enableObjectInsp", self.enableObjectInspector.isChecked())
settings.setValue("pythonConsole/autoCloseBracket", self.autoCloseBracket.isChecked())
settings.setValue("pythonConsole/autoSurround", self.autoSurround.isChecked())
settings.setValue("pythonConsole/autoInsertImport", self.autoInsertImport.isChecked())

def restoreSettings(self):
Expand All @@ -227,6 +228,7 @@ def restoreSettings(self):

self.enableObjectInspector.setChecked(settings.value("pythonConsole/enableObjectInsp", False, type=bool))
self.autoCloseBracket.setChecked(settings.value("pythonConsole/autoCloseBracket", True, type=bool))
self.autoSurround.setChecked(settings.value("pythonConsole/autoSurround", True, type=bool))
self.autoInsertImport.setChecked(settings.value("pythonConsole/autoInsertImport", False, type=bool))

if settings.value("pythonConsole/autoCompleteSource") == 'fromDoc':
Expand Down
10 changes: 9 additions & 1 deletion python/console/console_settings.ui
Expand Up @@ -90,7 +90,14 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="1" column="0">
<widget class="QCheckBox" name="autoSurround">
<property name="text">
<string>Automatically surround selection when typing quotes or brackets</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="autoInsertImport">
<property name="text">
<string>Automatic insertion of the 'import' string on 'from xxx'</string>
Expand Down Expand Up @@ -464,6 +471,7 @@
<tabstop>autoCompFromAPI</tabstop>
<tabstop>autoCompFromDocAPI</tabstop>
<tabstop>autoCloseBracket</tabstop>
<tabstop>autoSurround</tabstop>
<tabstop>autoInsertImport</tabstop>
<tabstop>enableObjectInspector</tabstop>
<tabstop>autoSaveScript</tabstop>
Expand Down
3 changes: 2 additions & 1 deletion src/gui/codeeditors/qgscodeeditorpython.cpp
Expand Up @@ -221,6 +221,7 @@ void QgsCodeEditorPython::keyPressEvent( QKeyEvent *event )
const QgsSettings settings;

bool autoCloseBracket = settings.value( QStringLiteral( "/pythonConsole/autoCloseBracket" ), true ).toBool();
bool autoSurround = settings.value( QStringLiteral( "/pythonConsole/autoSurround" ), true ).toBool();
bool autoInsertImport = settings.value( QStringLiteral( "/pythonConsole/autoInsertImport" ), false ).toBool();

// Update calltips when cursor position changes with left and right keys
Expand All @@ -241,7 +242,7 @@ void QgsCodeEditorPython::keyPressEvent( QKeyEvent *event )

// If some text is selected and user presses an opening character
// surround the selection with the opening-closing pair
if ( hasSelectedText() )
if ( hasSelectedText() && autoSurround )
{
if ( PAIRS.contains( eText ) )
{
Expand Down

0 comments on commit e6f2fc1

Please sign in to comment.