Skip to content

Commit

Permalink
Fix clipping of cursor due to 0 doc margin, issue #1112
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Sep 14, 2022
1 parent 90fbfc3 commit af55e57
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions novelwriter/gui/doceditor.py
Expand Up @@ -92,6 +92,7 @@ def __init__(self, mainGui):

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
Expand Down Expand Up @@ -271,9 +272,12 @@ def initEditor(self):
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()
Expand Down Expand Up @@ -537,18 +541,17 @@ def updateDocMargins(self):
"""
wW = self.width()
wH = self.height()
cM = self.mainConf.getTextMargin()

vBar = self.verticalScrollBar()
sW = vBar.width() if vBar.isVisible() else 0

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
Expand All @@ -565,8 +568,8 @@ def updateDocMargins(self):
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
Expand Down

0 comments on commit af55e57

Please sign in to comment.