eric6/QScintilla/Editor.py

changeset 7775
4a1db75550bd
parent 7771
787a6b3f8c9f
child 7783
36f66ce496bd
--- a/eric6/QScintilla/Editor.py	Sat Oct 10 16:03:53 2020 +0200
+++ b/eric6/QScintilla/Editor.py	Sun Oct 11 17:54:52 2020 +0200
@@ -7,14 +7,13 @@
 Module implementing the editor component of the eric6 IDE.
 """
 
-
 import os
 import re
 import difflib
 
 from PyQt5.QtCore import (
-    QDir, QTimer, QModelIndex, QFileInfo, pyqtSignal, pyqtSlot,
-    QCryptographicHash, QEvent, QDateTime, QRegExp, Qt, QPoint
+    pyqtSignal, pyqtSlot, Qt, QDir, QTimer, QModelIndex, QFileInfo,
+    QCryptographicHash, QEvent, QDateTime, QPoint
 )
 from PyQt5.QtGui import QPalette, QFont, QPixmap, QPainter
 from PyQt5.QtWidgets import (
@@ -3520,29 +3519,25 @@
         @return tuple with start and end indexes of the word at the position
             (integer, integer)
         """
-        text = self.text(line)
-        if self.caseSensitive():
-            cs = Qt.CaseSensitive
-        else:
-            cs = Qt.CaseInsensitive
         wc = self.wordCharacters()
         if wc is None or not useWordChars:
-            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)
-        
-        return (start, end)
-        
+            pattern = r"\b[\w{0}]+\b".format(re.escape(wc))
+        if self.caseSensitive():
+            rx = re.compile(pattern)
+        else:
+            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 (start, end)
+        
+        return (0, len(text))
+    
     def getWord(self, line, index, direction=0, useWordChars=True):
         """
         Public method to get the word at a position.

eric ide

mercurial