diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index b127090f..b1274f34 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -92,6 +92,7 @@ class GuiDocEditor(QTextEdit): self._spellCheck = False # Flag for spell checking enabled self._nonWord = "\"'" # Characters to not include in spell checking + self._vpMargin = 0 # The editor viewport margin, set during init # Document Variables self._charCount = 0 # Character count @@ -271,9 +272,12 @@ class GuiDocEditor(QTextEdit): self.docFooter.matchColours() # Set default text margins - cM = self.mainConf.getTextMargin() - qDoc.setDocumentMargin(0) - self.setViewportMargins(cM, cM, cM, cM) + # Due to cursor visibility, a part of the margin must be + # allocated to the document itself. See issue #1112. + cW = self.cursorWidth() + qDoc.setDocumentMargin(cW) + self._vpMargin = max(self.mainConf.getTextMargin() - cW, 0) + self.setViewportMargins(self._vpMargin, self._vpMargin, self._vpMargin, self._vpMargin) # Also set the document text options for the document text flow theOpt = QTextOption() @@ -537,7 +541,6 @@ class GuiDocEditor(QTextEdit): """ wW = self.width() wH = self.height() - cM = self.mainConf.getTextMargin() vBar = self.verticalScrollBar() sW = vBar.width() if vBar.isVisible() else 0 @@ -545,10 +548,10 @@ class GuiDocEditor(QTextEdit): hBar = self.horizontalScrollBar() sH = hBar.height() if hBar.isVisible() else 0 - tM = cM + tM = self._vpMargin if self.mainConf.textWidth > 0 or self.mainGui.isFocusMode: tW = self.mainConf.getTextWidth(self.mainGui.isFocusMode) - tM = max((wW - sW - tW)//2, cM) + tM = max((wW - sW - tW)//2, self._vpMargin) tB = self.frameWidth() tW = wW - 2*tB - sW @@ -565,8 +568,8 @@ class GuiDocEditor(QTextEdit): rL = wW - sW - rW - 2*tB self.docSearch.move(rL, 2*tB) - uM = max(cM, tH, rH) - lM = max(cM, fH) + uM = max(self._vpMargin, tH, rH) + lM = max(self._vpMargin, fH) self.setViewportMargins(tM, uM, tM, lM) return