Fixes bugs in focus mode (#259)

This commit is contained in:
Olivier Keshavjee 2017-12-05 23:45:16 +01:00
parent 826d53933f
commit 46384b68eb
3 changed files with 5 additions and 9 deletions

View file

@ -105,7 +105,7 @@ class MarkdownHighlighter(BasicHighlighter):
line = block.layout().lineAt(i)
start = line.textStart()
end = line.textStart() + line.textLength()
if start <= pos < end:
if start <= pos <= end:
return (start, end)
else:
return True

View file

@ -3,7 +3,7 @@
import re
from PyQt5.QtCore import QRegExp, Qt
from PyQt5.QtCore import QRegExp, Qt, QTimer
from PyQt5.QtGui import QTextCursor
# from PyQt5.QtWidgets import
@ -173,6 +173,9 @@ class MDEditView(textEditView):
def cursorPositionHasChanged(self):
self.centerCursor()
# Focus mode
if self.highlighter:
QTimer.singleShot(50, self.highlighter.rehighlight)
def centerCursor(self, force=False):
cursor = self.cursorRect()

View file

@ -67,9 +67,6 @@ class textEditView(QTextEdit):
# self.document().contentsChanged.connect(lambda: print(self.objectName(), "Contents changed"))
# Focus mode
self.cursorPositionChanged.connect(self.cursorHasMoved)
self.setEnabled(False)
if index:
@ -94,10 +91,6 @@ class textEditView(QTextEdit):
self.highlighter = self._highlighterClass(self)
self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
def cursorHasMoved(self):
if self.highlighter:
self.highlighter.rehighlight()
def getDefaultLocale(self):
default_locale = enchant.get_default_language()
if default_locale is None: