AssistantEric/Assistant.py

changeset 18
b8ece0b784e8
parent 5
e1a56c9a9c9d
child 19
7eb775bb326b
--- a/AssistantEric/Assistant.py	Fri Jul 30 18:53:11 2010 +0200
+++ b/AssistantEric/Assistant.py	Sun Aug 01 13:08:23 2010 +0200
@@ -8,6 +8,8 @@
 calltips system.
 """
 
+import re
+
 from PyQt4.QtCore import *
 
 from E5Gui.E5Application import e5App
@@ -256,7 +258,7 @@
         projectCompletionList = []
         sep = ""
         if context:
-            wc = editor.wordCharacters()
+            wc = re.sub("\w", "", editor.wordCharacters())
             text = editor.text(line)
             
             beg = text[:col]
@@ -266,7 +268,9 @@
                     break
             
             depth = 0
-            while col > 0 and text[col - 1] not in wc:
+            while col > 0 and \
+                  (not text[col - 1].isalnum() or \
+                   (wc and text[col - 1] not in wc)):
                 ch = text[col - 1]
                 if ch == ')':
                     depth = 1
@@ -377,7 +381,12 @@
         if context:
             word += sep
         
-        res = editor.findFirstTarget(word, False, editor.autoCompletionCaseSensitivity(), 
+        if editor.isUtf8():
+            sword = word.encode("utf-8")
+        else:
+            sword = word
+        res = editor.findFirstTarget(sword, False, 
+            editor.autoCompletionCaseSensitivity(), 
             False, begline = 0, begindex = 0, ws_ = True)
         while res:
             start, length = editor.getFoundTarget()
@@ -387,11 +396,9 @@
                     completion = ""
                 else:
                     completion = word
-                ch = editor.charAt(pos)
-                while editor.isWordCharacter(ch):
-                    completion += ch
-                    pos += 1
-                    ch = editor.charAt(pos)
+                line, index = editor.lineIndexFromPosition(pos)
+                curWord = editor.getWord(line, index, useWordChars = False)
+                completion += curWord[len(completion):]
                 if completion and completion not in completionsList:
                     completionsList.append(
                         "{0}?{1}".format(completion, self.__fromDocumentID))
@@ -435,9 +442,11 @@
             return
         
         line, col = editor.lineIndexFromPosition(pos)
-        wc = editor.wordCharacters()
+        wc = re.sub("\w", "", editor.wordCharacters())
         text = editor.text(line)
-        while col > 0 and text[col - 1] not in wc:
+        while col > 0 and \
+              (not text[col - 1].isalnum() or \
+               (wc and text[col - 1] not in wc)):
             col -= 1
         word = editor.getWordLeft(line, col)
         

eric ide

mercurial