eric6/QScintilla/MiniEditor.py

changeset 7775
4a1db75550bd
parent 7771
787a6b3f8c9f
child 7819
d0e9c4cb2aa0
--- a/eric6/QScintilla/MiniEditor.py	Sat Oct 10 16:03:53 2020 +0200
+++ b/eric6/QScintilla/MiniEditor.py	Sun Oct 11 17:54:52 2020 +0200
@@ -4,15 +4,14 @@
 #
 
 """
-Module implementing a minimalistic editor for simple editing tasks.
+Module implementing an editor for simple editing tasks.
 """
 
-
 import os
 import re
 
 from PyQt5.QtCore import (
-    QSignalMapper, QPoint, QTimer, QFileInfo, pyqtSignal, QSize, QRegExp, Qt,
+    pyqtSignal, Qt, QSignalMapper, QPoint, QTimer, QFileInfo, QSize,
     QCoreApplication
 )
 from PyQt5.QtGui import QKeySequence, QPalette, QFont, QPixmap
@@ -114,7 +113,7 @@
 
 class MiniEditor(E5MainWindow):
     """
-    Class implementing a minimalistic editor for simple editing tasks.
+    Class implementing an editor for simple editing tasks.
     
     @signal editorSaved() emitted after the file has been saved
     @signal languageChanged(str) emitted when the editors language was set. The
@@ -3439,35 +3438,31 @@
         """
         Private method to get the word at a position.
         
-        @param line number of line to look at (int)
-        @param index position to look at (int)
-        @return the word at that position (string)
+        @param line number of line to look at
+        @type int
+        @param index position to look at
+        @type int
+        @return the word at that position
+        @rtype str
         """
-        text = self.__textEdit.text(line)
-        if self.__textEdit.caseSensitive():
-            cs = Qt.CaseSensitive
-        else:
-            cs = Qt.CaseInsensitive
         wc = self.__textEdit.wordCharacters()
         if wc is None:
-            regExp = QRegExp(r'[^\w_]', cs)
+            pattern = r"\b[\w_]+\b"
         else:
             wc = re.sub(r'\w', "", wc)
-            regExp = QRegExp(r'[^\w{0}]'.format(re.escape(wc)), cs)
-        start = regExp.lastIndexIn(text, index) + 1
-        end = regExp.indexIn(text, index)
-        if start == end + 1 and index > 0:
-            # we are on a word boundary, try again
-            start = regExp.lastIndexIn(text, index - 1) + 1
-        if start == -1:
-            start = 0
-        if end == -1:
-            end = len(text)
-        if end > start:
-            word = text[start:end]
+            pattern = r"\b[\w{0}]+\b".format(re.escape(wc))
+        if self.__textEdit.caseSensitive():
+            rx = re.compile(pattern)
         else:
-            word = ''
-        return word
+            rx = re.compile(pattern, re.IGNORECASE)
+        
+        text = self.text(line)
+        for match in rx.finditer(text):
+            start, end = match.span()
+            if start <= index <= end:
+                return match.group()
+        
+        return ""
     
     def __getCurrentWord(self):
         """

eric ide

mercurial