Yuya Nishihara committed 86653e6

annotate: show annotate menu even if no character exists under mouse cursor

lineAt() strictly checks the existence of character, but we want more relaxed
version. It can be achieved by using SCI_POSITIONFROMPOINT in place of

Tested compatibility with Ubuntu 10.10.

Comments (0)

Files changed (2)


     def menuRequest(self, point):
         menu = self.sci.createStandardContextMenu()
-        line = self.sci.lineAt(point)
+        line = self.sci.lineNearPoint(point)
         point = self.sci.viewport().mapToGlobal(point)
         selection = self.sci.selectedText()


             tabs = findTabIndentsInLines(hglib.fromunicode(self.text()))
         super(Scintilla, self).setIndentationsUseTabs(tabs)
+    def lineNearPoint(self, point):
+        """Return the closest line to the pixel position; similar to lineAt(),
+        but returns valid line number even if no character fount at point"""
+        # lineAt() uses the strict request, SCI_POSITIONFROMPOINTCLOSE
+        chpos = self.SendScintilla(self.SCI_POSITIONFROMPOINT,
+                                   point.x(), point.y())
+        return self.SendScintilla(self.SCI_LINEFROMPOSITION, chpos)
     # compability mode with QScintilla from Ubuntu 10.04
     if not hasattr(QsciScintilla, 'HiddenIndicator'):
         HiddenIndicator = QsciScintilla.INDIC_HIDDEN