QScintilla/QsciScintillaCompat.py

changeset 4253
508b025f5d8e
parent 4021
195a471c327b
child 4331
711e7c35a49b
--- a/QScintilla/QsciScintillaCompat.py	Sat May 09 14:10:59 2015 +0200
+++ b/QScintilla/QsciScintillaCompat.py	Sat May 09 17:07:56 2015 +0200
@@ -1093,6 +1093,135 @@
         if hasattr(QsciScintilla, "SCI_FINDINDICATORHIDE"):
             self.SendScintilla(QsciScintilla.SCI_FINDINDICATORHIDE)
     
+    def getIndicatorStartPos(self, indicator, pos):
+        """
+        Public method to get the start position of an indicator at a position.
+        
+        @param indicator ID of the indicator (integer)
+        @param pos position within the indicator (integer)
+        @return start position of the indicator (integer)
+        """
+        return self.SendScintilla(QsciScintilla.SCI_INDICATORSTART,
+                                  indicator, pos)
+    
+    def getIndicatorEndPos(self, indicator, pos):
+        """
+        Public method to get the end position of an indicator at a position.
+        
+        @param indicator ID of the indicator (integer)
+        @param pos position within the indicator (integer)
+        @return end position of the indicator (integer)
+        """
+        return self.SendScintilla(QsciScintilla.SCI_INDICATOREND,
+                                  indicator, pos)
+    
+    def gotoPreviousIndicator(self, indicator, wrap):
+        """
+        Public method to move the cursor to the previous position of an
+        indicator.
+        
+        This method ensures, that the position found is visible (i.e. unfolded
+        and inside the visible range). The text containing the indicator is
+        selected.
+        
+        @param indicator ID of the indicator to search (integer)
+        @param wrap flag indicating to wrap around at the beginning of the
+            text (boolean)
+        @return flag indicating if the indicator was found (boolean)
+        """
+        pos = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS)
+        docLen = self.SendScintilla(QsciScintilla.SCI_GETTEXTLENGTH)
+        isInIndicator = self.hasIndicator(indicator, pos)
+        posStart = self.getIndicatorStartPos(indicator, pos)
+        posEnd = self.getIndicatorEndPos(indicator, pos)
+        
+        if posStart == 0 and posEnd == docLen - 1:
+            # indicator does not exist
+            return False
+        
+        if posStart <= 0:
+            if not wrap:
+                return False
+            
+            isInIndicator = self.hasIndicator(indicator, docLen - 1)
+            posStart = self.getIndicatorStartPos(indicator, docLen - 1)
+        
+        if isInIndicator:
+            # get out of it
+            posStart = self.getIndicatorStartPos(indicator, posStart - 1)
+            if posStart <= 0:
+                if not wrap:
+                    return False
+                
+                posStart = self.getIndicatorStartPos(indicator, docLen - 1)
+        
+        newPos = posStart - 1
+        posStart = self.getIndicatorStartPos(indicator, newPos)
+        posEnd = self.getIndicatorEndPos(indicator, newPos)
+        
+        if self.hasIndicator(indicator, posStart):
+            # found it
+            line, index = self.lineIndexFromPosition(posEnd)
+            self.ensureLineVisible(line)
+            self.SendScintilla(QsciScintilla.SCI_SETSEL, posEnd, posStart)
+            self.SendScintilla(QsciScintilla.SCI_SCROLLCARET)
+            return True
+        
+        return False
+    
+    def gotoNextIndicator(self, indicator, wrap):
+        """
+        Public method to move the cursor to the next position of an indicator.
+        
+        This method ensures, that the position found is visible (i.e. unfolded
+        and inside the visible range). The text containing the indicator is
+        selected.
+        
+        @param indicator ID of the indicator to search (integer)
+        @param wrap flag indicating to wrap around at the beginning of the
+            text (boolean)
+        @return flag indicating if the indicator was found (boolean)
+        """
+        pos = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS)
+        docLen = self.SendScintilla(QsciScintilla.SCI_GETTEXTLENGTH)
+        isInIndicator = self.hasIndicator(indicator, pos)
+        posStart = self.getIndicatorStartPos(indicator, pos)
+        posEnd = self.getIndicatorEndPos(indicator, pos)
+        
+        if posStart == 0 and posEnd == docLen - 1:
+            # indicator does not exist
+            return False
+        
+        if posEnd >= docLen:
+            if not wrap:
+                return False
+            
+            isInIndicator = self.hasIndicator(indicator, 0)
+            posEnd = self.getIndicatorEndPos(indicator, 0)
+        
+        if isInIndicator:
+            # get out of it
+            posEnd = self.getIndicatorEndPos(indicator, posEnd)
+            if posEnd >= docLen:
+                if not wrap:
+                    return False
+                
+                posEnd = self.getIndicatorEndPos(indicator, 0)
+        
+        newPos = posEnd + 1
+        posStart = self.getIndicatorStartPos(indicator, newPos)
+        posEnd = self.getIndicatorEndPos(indicator, newPos)
+        
+        if self.hasIndicator(indicator, posStart):
+            # found it
+            line, index = self.lineIndexFromPosition(posEnd)
+            self.ensureLineVisible(line)
+            self.SendScintilla(QsciScintilla.SCI_SETSEL, posStart, posEnd)
+            self.SendScintilla(QsciScintilla.SCI_SCROLLCARET)
+            return True
+        
+        return False
+    
     ###########################################################################
     ## methods to perform folding related stuff
     ###########################################################################

eric ide

mercurial