diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index b3709420..627b4ff9 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -345,9 +345,14 @@ class GuiDocEditor(QTextEdit): qApp.processEvents() self.setDocumentChanged(False) - qApp.restoreOverrideCursor() + # This is a hack to fix invisble cursor on an empty document + if self.qDocument.characterCount() <= 1: + self.setPlainText("\n") + self.setPlainText("") + self.setCursorPosition(0) + return True def updateTagHighLighting(self, forceBigDoc=False): @@ -513,9 +518,10 @@ class GuiDocEditor(QTextEdit): if not isinstance(thePosition, int): return False - if thePosition >= 0: + nChars = self.qDocument.characterCount() + if nChars > 1: theCursor = self.textCursor() - theCursor.setPosition(thePosition) + theCursor.setPosition(min(max(thePosition, 0), nChars-1)) self.setTextCursor(theCursor) self.docFooter.updateLineCount()