@@ -590,9 +590,6 @@ def __init__(self, parent=None):
590
590
self .patch = []
591
591
self .leading_whitespaces = {}
592
592
593
- # re-use parent of completion_widget (usually the main window)
594
- completion_parent = self .completion_widget .parent ()
595
-
596
593
# Some events should not be triggered during undo/redo
597
594
# such as line stripping
598
595
self .is_undoing = False
@@ -1500,15 +1497,20 @@ def process_completion(self, params):
1500
1497
1501
1498
try :
1502
1499
completions = params ['params' ]
1503
- completions = ([] if completions is None else
1504
- [completion for completion in completions
1505
- if completion .get ('insertText' )
1506
- or completion .get ('textEdit' , {}).get ('newText' )])
1507
- prefix = self .get_current_word (completion = True ,
1508
- valid_python_variable = False )
1509
- if (len (completions ) == 1
1510
- and completions [0 ].get ('insertText' ) == prefix
1511
- and not completions [0 ].get ('textEdit' , {}).get ('newText' )):
1500
+ completions = (
1501
+ [] if completions is None else
1502
+ [completion for completion in completions
1503
+ if completion .get ('insertText' )
1504
+ or completion .get ('textEdit' , {}).get ('newText' )]
1505
+ )
1506
+ prefix = self .get_current_word (
1507
+ completion = True , valid_python_variable = False )
1508
+
1509
+ if (
1510
+ len (completions ) == 1 and
1511
+ completions [0 ].get ('insertText' ) == prefix and
1512
+ not completions [0 ].get ('textEdit' , {}).get ('newText' )
1513
+ ):
1512
1514
completions .pop ()
1513
1515
1514
1516
replace_end = self .textCursor ().position ()
@@ -1527,12 +1529,14 @@ def sort_key(completion):
1527
1529
text_insertion = completion ['textEdit' ]['newText' ]
1528
1530
else :
1529
1531
text_insertion = completion ['insertText' ]
1532
+
1530
1533
first_insert_letter = text_insertion [0 ]
1531
1534
case_mismatch = (
1532
1535
(first_letter .isupper () and first_insert_letter .islower ())
1533
1536
or
1534
1537
(first_letter .islower () and first_insert_letter .isupper ())
1535
1538
)
1539
+
1536
1540
# False < True, so case matches go first
1537
1541
return (case_mismatch , completion ['sortText' ])
1538
1542
@@ -1545,8 +1549,11 @@ def sort_key(completion):
1545
1549
if 'textEdit' in completion :
1546
1550
c_replace_start = completion ['textEdit' ]['range' ]['start' ]
1547
1551
c_replace_end = completion ['textEdit' ]['range' ]['end' ]
1548
- if (c_replace_start == replace_start
1549
- and c_replace_end == replace_end ):
1552
+
1553
+ if (
1554
+ c_replace_start == replace_start and
1555
+ c_replace_end == replace_end
1556
+ ):
1550
1557
insert_text = completion ['textEdit' ]['newText' ]
1551
1558
completion ['filterText' ] = insert_text
1552
1559
completion ['insertText' ] = insert_text
@@ -4715,8 +4722,11 @@ def keyPressEvent(self, event):
4715
4722
self .completion_widget .hide ()
4716
4723
if key in (Qt .Key_Enter , Qt .Key_Return ):
4717
4724
if not shift and not ctrl :
4718
- if (self .add_colons_enabled and self .is_python_like () and
4719
- self .autoinsert_colons ()):
4725
+ if (
4726
+ self .add_colons_enabled and
4727
+ self .is_python_like () and
4728
+ self .autoinsert_colons ()
4729
+ ):
4720
4730
self .textCursor ().beginEditBlock ()
4721
4731
self .insert_text (':' + self .get_line_separator ())
4722
4732
if self .strip_trailing_spaces_on_modify :
@@ -4764,16 +4774,21 @@ def keyPressEvent(self, event):
4764
4774
trailing_spaces = leading_length - len (leading_text .rstrip ())
4765
4775
trailing_text = self .get_text ('cursor' , 'eol' )
4766
4776
matches = ('()' , '[]' , '{}' , '\' \' ' , '""' )
4767
- if (not leading_text .strip () and
4768
- (leading_length > len (self .indent_chars ))):
4777
+ if (
4778
+ not leading_text .strip () and
4779
+ (leading_length > len (self .indent_chars ))
4780
+ ):
4769
4781
if leading_length % len (self .indent_chars ) == 0 :
4770
4782
self .unindent ()
4771
4783
else :
4772
4784
self ._handle_keypress_event (event )
4773
4785
elif trailing_spaces and not trailing_text .strip ():
4774
4786
self .remove_suffix (leading_text [- trailing_spaces :])
4775
- elif (leading_text and trailing_text and
4776
- (leading_text [- 1 ] + trailing_text [0 ] in matches )):
4787
+ elif (
4788
+ leading_text and
4789
+ trailing_text and
4790
+ (leading_text [- 1 ] + trailing_text [0 ] in matches )
4791
+ ):
4777
4792
cursor = self .textCursor ()
4778
4793
cursor .movePosition (QTextCursor .PreviousCharacter )
4779
4794
cursor .movePosition (QTextCursor .NextCharacter ,
@@ -4788,27 +4803,36 @@ def keyPressEvent(self, event):
4788
4803
# redefine this basic action which should have been implemented
4789
4804
# natively
4790
4805
self .stdkey_end (shift , ctrl )
4791
- elif (text in self .auto_completion_characters and
4792
- self .automatic_completions ):
4806
+ elif (
4807
+ text in self .auto_completion_characters and
4808
+ self .automatic_completions
4809
+ ):
4793
4810
self .insert_text (text )
4794
4811
if text == "." :
4795
4812
if not self .in_comment_or_string ():
4796
4813
text = self .get_text ('sol' , 'cursor' )
4797
4814
last_obj = getobj (text )
4798
4815
prev_char = text [- 2 ] if len (text ) > 1 else ''
4799
- if (prev_char in {')' , ']' , '}' } or
4800
- (last_obj and not last_obj .isdigit ())):
4816
+ if (
4817
+ prev_char in {')' , ']' , '}' } or
4818
+ (last_obj and not last_obj .isdigit ())
4819
+ ):
4801
4820
# Completions should be triggered immediately when
4802
4821
# an autocompletion character is introduced.
4803
4822
self .do_completion (automatic = True )
4804
4823
else :
4805
4824
self .do_completion (automatic = True )
4806
- elif (text in self .signature_completion_characters and
4807
- not self .has_selected_text ()):
4825
+ elif (
4826
+ text in self .signature_completion_characters and
4827
+ not self .has_selected_text ()
4828
+ ):
4808
4829
self .insert_text (text )
4809
4830
self .request_signature ()
4810
- elif (key == Qt .Key_Colon and not has_selection and
4811
- self .auto_unindent_enabled ):
4831
+ elif (
4832
+ key == Qt .Key_Colon and
4833
+ not has_selection and
4834
+ self .auto_unindent_enabled
4835
+ ):
4812
4836
leading_text = self .get_text ('sol' , 'cursor' )
4813
4837
if leading_text .lstrip () in ('else' , 'finally' ):
4814
4838
ind = lambda txt : len (txt ) - len (txt .lstrip ())
@@ -4819,8 +4843,13 @@ def keyPressEvent(self, event):
4819
4843
if ind (leading_text ) == ind (prevtxt ):
4820
4844
self .unindent (force = True )
4821
4845
self ._handle_keypress_event (event )
4822
- elif (key == Qt .Key_Space and not shift and not ctrl and not
4823
- has_selection and self .auto_unindent_enabled ):
4846
+ elif (
4847
+ key == Qt .Key_Space and
4848
+ not shift and
4849
+ not ctrl and
4850
+ not has_selection and
4851
+ self .auto_unindent_enabled
4852
+ ):
4824
4853
self .completion_widget .hide ()
4825
4854
leading_text = self .get_text ('sol' , 'cursor' )
4826
4855
if leading_text .lstrip () in ('elif' , 'except' ):
@@ -4905,13 +4934,20 @@ def do_automatic_completions(self):
4905
4934
is_backspace = (
4906
4935
self .is_completion_widget_visible () and key == Qt .Key_Backspace )
4907
4936
4908
- if (len (text ) >= self .automatic_completions_after_chars
4909
- and self ._last_key_pressed_text or is_backspace ):
4937
+ if (
4938
+ (len (text ) >= self .automatic_completions_after_chars ) and
4939
+ self ._last_key_pressed_text or
4940
+ is_backspace
4941
+ ):
4910
4942
# Perform completion on the fly
4911
4943
if not self .in_comment_or_string ():
4912
4944
# Variables can include numbers and underscores
4913
- if (text .isalpha () or text .isalnum () or '_' in text
4914
- or '.' in text ):
4945
+ if (
4946
+ text .isalpha () or
4947
+ text .isalnum () or
4948
+ '_' in text
4949
+ or '.' in text
4950
+ ):
4915
4951
self .do_completion (automatic = True )
4916
4952
self ._last_key_pressed_text = ''
4917
4953
self ._last_pressed_key = None
0 commit comments