@@ -605,9 +605,6 @@ def __init__(self, parent=None):
605
605
self .patch = []
606
606
self .leading_whitespaces = {}
607
607
608
- # re-use parent of completion_widget (usually the main window)
609
- completion_parent = self .completion_widget .parent ()
610
-
611
608
# Some events should not be triggered during undo/redo
612
609
# such as line stripping
613
610
self .is_undoing = False
@@ -1523,15 +1520,20 @@ def process_completion(self, params):
1523
1520
1524
1521
try :
1525
1522
completions = params ['params' ]
1526
- completions = ([] if completions is None else
1527
- [completion for completion in completions
1528
- if completion .get ('insertText' )
1529
- or completion .get ('textEdit' , {}).get ('newText' )])
1530
- prefix = self .get_current_word (completion = True ,
1531
- valid_python_variable = False )
1532
- if (len (completions ) == 1
1533
- and completions [0 ].get ('insertText' ) == prefix
1534
- and not completions [0 ].get ('textEdit' , {}).get ('newText' )):
1523
+ completions = (
1524
+ [] if completions is None else
1525
+ [completion for completion in completions
1526
+ if completion .get ('insertText' )
1527
+ or completion .get ('textEdit' , {}).get ('newText' )]
1528
+ )
1529
+ prefix = self .get_current_word (
1530
+ completion = True , valid_python_variable = False )
1531
+
1532
+ if (
1533
+ len (completions ) == 1 and
1534
+ completions [0 ].get ('insertText' ) == prefix and
1535
+ not completions [0 ].get ('textEdit' , {}).get ('newText' )
1536
+ ):
1535
1537
completions .pop ()
1536
1538
1537
1539
replace_end = self .textCursor ().position ()
@@ -1550,12 +1552,14 @@ def sort_key(completion):
1550
1552
text_insertion = completion ['textEdit' ]['newText' ]
1551
1553
else :
1552
1554
text_insertion = completion ['insertText' ]
1555
+
1553
1556
first_insert_letter = text_insertion [0 ]
1554
1557
case_mismatch = (
1555
1558
(first_letter .isupper () and first_insert_letter .islower ())
1556
1559
or
1557
1560
(first_letter .islower () and first_insert_letter .isupper ())
1558
1561
)
1562
+
1559
1563
# False < True, so case matches go first
1560
1564
return (case_mismatch , completion ['sortText' ])
1561
1565
@@ -1568,8 +1572,11 @@ def sort_key(completion):
1568
1572
if 'textEdit' in completion :
1569
1573
c_replace_start = completion ['textEdit' ]['range' ]['start' ]
1570
1574
c_replace_end = completion ['textEdit' ]['range' ]['end' ]
1571
- if (c_replace_start == replace_start
1572
- and c_replace_end == replace_end ):
1575
+
1576
+ if (
1577
+ c_replace_start == replace_start and
1578
+ c_replace_end == replace_end
1579
+ ):
1573
1580
insert_text = completion ['textEdit' ]['newText' ]
1574
1581
completion ['filterText' ] = insert_text
1575
1582
completion ['insertText' ] = insert_text
@@ -4766,8 +4773,11 @@ def keyPressEvent(self, event):
4766
4773
self .completion_widget .hide ()
4767
4774
if key in (Qt .Key_Enter , Qt .Key_Return ):
4768
4775
if not shift and not ctrl :
4769
- if (self .add_colons_enabled and self .is_python_like () and
4770
- self .autoinsert_colons ()):
4776
+ if (
4777
+ self .add_colons_enabled and
4778
+ self .is_python_like () and
4779
+ self .autoinsert_colons ()
4780
+ ):
4771
4781
self .textCursor ().beginEditBlock ()
4772
4782
self .insert_text (':' + self .get_line_separator ())
4773
4783
if self .strip_trailing_spaces_on_modify :
@@ -4815,16 +4825,21 @@ def keyPressEvent(self, event):
4815
4825
trailing_spaces = leading_length - len (leading_text .rstrip ())
4816
4826
trailing_text = self .get_text ('cursor' , 'eol' )
4817
4827
matches = ('()' , '[]' , '{}' , '\' \' ' , '""' )
4818
- if (not leading_text .strip () and
4819
- (leading_length > len (self .indent_chars ))):
4828
+ if (
4829
+ not leading_text .strip () and
4830
+ (leading_length > len (self .indent_chars ))
4831
+ ):
4820
4832
if leading_length % len (self .indent_chars ) == 0 :
4821
4833
self .unindent ()
4822
4834
else :
4823
4835
self ._handle_keypress_event (event )
4824
4836
elif trailing_spaces and not trailing_text .strip ():
4825
4837
self .remove_suffix (leading_text [- trailing_spaces :])
4826
- elif (leading_text and trailing_text and
4827
- (leading_text [- 1 ] + trailing_text [0 ] in matches )):
4838
+ elif (
4839
+ leading_text and
4840
+ trailing_text and
4841
+ (leading_text [- 1 ] + trailing_text [0 ] in matches )
4842
+ ):
4828
4843
cursor = self .textCursor ()
4829
4844
cursor .movePosition (QTextCursor .PreviousCharacter )
4830
4845
cursor .movePosition (QTextCursor .NextCharacter ,
@@ -4839,27 +4854,36 @@ def keyPressEvent(self, event):
4839
4854
# redefine this basic action which should have been implemented
4840
4855
# natively
4841
4856
self .stdkey_end (shift , ctrl )
4842
- elif (text in self .auto_completion_characters and
4843
- self .automatic_completions ):
4857
+ elif (
4858
+ text in self .auto_completion_characters and
4859
+ self .automatic_completions
4860
+ ):
4844
4861
self .insert_text (text )
4845
4862
if text == "." :
4846
4863
if not self .in_comment_or_string ():
4847
4864
text = self .get_text ('sol' , 'cursor' )
4848
4865
last_obj = getobj (text )
4849
4866
prev_char = text [- 2 ] if len (text ) > 1 else ''
4850
- if (prev_char in {')' , ']' , '}' } or
4851
- (last_obj and not last_obj .isdigit ())):
4867
+ if (
4868
+ prev_char in {')' , ']' , '}' } or
4869
+ (last_obj and not last_obj .isdigit ())
4870
+ ):
4852
4871
# Completions should be triggered immediately when
4853
4872
# an autocompletion character is introduced.
4854
4873
self .do_completion (automatic = True )
4855
4874
else :
4856
4875
self .do_completion (automatic = True )
4857
- elif (text in self .signature_completion_characters and
4858
- not self .has_selected_text ()):
4876
+ elif (
4877
+ text in self .signature_completion_characters and
4878
+ not self .has_selected_text ()
4879
+ ):
4859
4880
self .insert_text (text )
4860
4881
self .request_signature ()
4861
- elif (key == Qt .Key_Colon and not has_selection and
4862
- self .auto_unindent_enabled ):
4882
+ elif (
4883
+ key == Qt .Key_Colon and
4884
+ not has_selection and
4885
+ self .auto_unindent_enabled
4886
+ ):
4863
4887
leading_text = self .get_text ('sol' , 'cursor' )
4864
4888
if leading_text .lstrip () in ('else' , 'finally' ):
4865
4889
ind = lambda txt : len (txt ) - len (txt .lstrip ())
@@ -4870,8 +4894,13 @@ def keyPressEvent(self, event):
4870
4894
if ind (leading_text ) == ind (prevtxt ):
4871
4895
self .unindent (force = True )
4872
4896
self ._handle_keypress_event (event )
4873
- elif (key == Qt .Key_Space and not shift and not ctrl and not
4874
- has_selection and self .auto_unindent_enabled ):
4897
+ elif (
4898
+ key == Qt .Key_Space and
4899
+ not shift and
4900
+ not ctrl and
4901
+ not has_selection and
4902
+ self .auto_unindent_enabled
4903
+ ):
4875
4904
self .completion_widget .hide ()
4876
4905
leading_text = self .get_text ('sol' , 'cursor' )
4877
4906
if leading_text .lstrip () in ('elif' , 'except' ):
@@ -4956,13 +4985,20 @@ def do_automatic_completions(self):
4956
4985
is_backspace = (
4957
4986
self .is_completion_widget_visible () and key == Qt .Key_Backspace )
4958
4987
4959
- if (len (text ) >= self .automatic_completions_after_chars
4960
- and self ._last_key_pressed_text or is_backspace ):
4988
+ if (
4989
+ (len (text ) >= self .automatic_completions_after_chars ) and
4990
+ self ._last_key_pressed_text or
4991
+ is_backspace
4992
+ ):
4961
4993
# Perform completion on the fly
4962
4994
if not self .in_comment_or_string ():
4963
4995
# Variables can include numbers and underscores
4964
- if (text .isalpha () or text .isalnum () or '_' in text
4965
- or '.' in text ):
4996
+ if (
4997
+ text .isalpha () or
4998
+ text .isalnum () or
4999
+ '_' in text
5000
+ or '.' in text
5001
+ ):
4966
5002
self .do_completion (automatic = True )
4967
5003
self ._last_key_pressed_text = ''
4968
5004
self ._last_pressed_key = None
0 commit comments