@@ -2516,12 +2516,9 @@ def keyPressEvent(self, event):
2516
2516
self .stdkey_end (shift , ctrl )
2517
2517
elif text == '(' and not self .has_selected_text ():
2518
2518
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 ):
2525
2522
s_trailing_text = self .get_text ('cursor' , 'eol' ).strip ()
2526
2523
if len (s_trailing_text ) == 0 or \
2527
2524
s_trailing_text [0 ] in (',' , ')' , ']' , '}' ):
@@ -2588,12 +2585,12 @@ def keyPressEvent(self, event):
2588
2585
if self .is_completion_widget_visible () and text :
2589
2586
self .completion_text += text
2590
2587
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."""
2594
2590
position = self .get_position ('cursor' )
2595
2591
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 :
2597
2594
self .insert_text ('()' )
2598
2595
cursor = self .textCursor ()
2599
2596
cursor .movePosition (QTextCursor .PreviousCharacter )
0 commit comments