IDE: fix completion
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Tue, 20 Aug 2024 01:13:14 +0200
changeset 3973 42730c1cb879
parent 3972 5d46adf7bbba
child 3974 4c9c1cbf69b2
IDE: fix completion

uses ctrl key on Mac
update internal variable list before listing them
avoid exception if empty list
apply selection when pressing return or enter
editors/TextViewer.py
--- a/editors/TextViewer.py	Tue Aug 20 00:35:00 2024 +0200
+++ b/editors/TextViewer.py	Tue Aug 20 01:13:14 2024 +0200
@@ -877,13 +877,15 @@
             lineText = self.Editor.GetTextRange(start_pos, end_pos).replace("\t", " ")
 
             # Code completion
-            if key == wx.WXK_SPACE and event.ControlDown():
+            if key == wx.WXK_SPACE and event.RawControlDown():
 
                 words = lineText.split(" ")
                 words = [word for i, word in enumerate(words) if word != '' or i == len(words) - 1]
 
                 kw = []
 
+                self.RefreshVariableTree()
+
                 if self.TextSyntax == "IL":
                     if len(words) == 1:
                         kw = self.Keywords
@@ -898,13 +900,17 @@
                     kw = self.Keywords + list(self.Variables.keys()) + list(self.Functions.keys())
                 if len(kw) > 0:
                     if len(words[-1]) > 0:
-                        kw = [keyword for keyword in kw if keyword.startswith(words[-1])]
+                        kw = [keyword for keyword in kw if keyword.startswith(words[-1].upper())]
+                if len(kw) > 0:
                     kw.sort()
                     self.Editor.AutoCompSetIgnoreCase(True)
                     self.Editor.AutoCompShow(len(words[-1]), " ".join(kw))
                 key_handled = True
             elif key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER:
-                if self.TextSyntax in ["ST", "ALL"]:
+                if self.Editor.AutoCompActive():
+                    self.Editor.AutoCompComplete()
+                    key_handled = True
+                elif self.TextSyntax in ["ST", "ALL"]:
                     indent = self.Editor.GetLineIndentation(line)
                     if LineStartswith(lineText.strip(), self.BlockStartKeywords):
                         indent = (indent // 2 + 1) * 2