Skip to content

Commit b5905ef

Browse files
committed
Merge from 3.x: PR #3893
Fixes #3809
2 parents 10b37bb + d06edff commit b5905ef

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

Diff for: spyder/widgets/sourcecode/codeeditor.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -2516,12 +2516,9 @@ def keyPressEvent(self, event):
25162516
self.stdkey_end(shift, ctrl)
25172517
elif text == '(' and not self.has_selected_text():
25182518
self.hide_completion_widget()
2519-
if self.close_parentheses_enabled:
2520-
self.handle_close_parentheses(text)
2521-
else:
2522-
self.insert_text(text)
2523-
elif text in ('[', '{') and not self.has_selected_text() \
2524-
and self.close_parentheses_enabled:
2519+
self.handle_parentheses(text)
2520+
elif (text in ('[', '{') and not self.has_selected_text() and
2521+
self.close_parentheses_enabled):
25252522
s_trailing_text = self.get_text('cursor', 'eol').strip()
25262523
if len(s_trailing_text) == 0 or \
25272524
s_trailing_text[0] in (',', ')', ']', '}'):
@@ -2588,12 +2585,12 @@ def keyPressEvent(self, event):
25882585
if self.is_completion_widget_visible() and text:
25892586
self.completion_text += text
25902587

2591-
def handle_close_parentheses(self, text):
2592-
if not self.close_parentheses_enabled:
2593-
return
2588+
def handle_parentheses(self, text):
2589+
"""Handle left and right parenthesis depending on editor config."""
25942590
position = self.get_position('cursor')
25952591
rest = self.get_text('cursor', 'eol').rstrip()
2596-
if not rest or rest[0] in (',', ')', ']', '}'):
2592+
valid = not rest or rest[0] in (',', ')', ']', '}')
2593+
if self.close_parentheses_enabled and valid:
25972594
self.insert_text('()')
25982595
cursor = self.textCursor()
25992596
cursor.movePosition(QTextCursor.PreviousCharacter)

0 commit comments

Comments
 (0)