@@ -91,6 +91,7 @@ def __init__(self, theParent):
9191
9292 self ._spellCheck = False # Flag for spell checking enabled
9393 self ._nonWord = "\" '" # Characters to not include in spell checking
94+ self ._vpMargin = 0 # The editor viewport margin, set during init
9495
9596 # Document Variables
9697 self ._charCount = 0 # Character count
@@ -268,10 +269,12 @@ def initEditor(self):
268269 self .docHeader .matchColours ()
269270 self .docFooter .matchColours ()
270271
271- # Set default text margins
272- cM = self .mainConf .getTextMargin ()
273- qDoc .setDocumentMargin (0 )
274- self .setViewportMargins (cM , cM , cM , cM )
272+ # Due to cursor visibility, a part of the margin must be
273+ # allocated to the document itself. See issue #1112.
274+ cW = self .cursorWidth ()
275+ qDoc .setDocumentMargin (cW )
276+ self ._vpMargin = max (self .mainConf .getTextMargin () - cW , 0 )
277+ self .setViewportMargins (self ._vpMargin , self ._vpMargin , self ._vpMargin , self ._vpMargin )
275278
276279 # Also set the document text options for the document text flow
277280 theOpt = QTextOption ()
@@ -533,18 +536,17 @@ def updateDocMargins(self):
533536 """
534537 wW = self .width ()
535538 wH = self .height ()
536- cM = self .mainConf .getTextMargin ()
537539
538540 vBar = self .verticalScrollBar ()
539541 sW = vBar .width () if vBar .isVisible () else 0
540542
541543 hBar = self .horizontalScrollBar ()
542544 sH = hBar .height () if hBar .isVisible () else 0
543545
544- tM = cM
546+ tM = self . _vpMargin
545547 if self .mainConf .textWidth > 0 or self .theParent .isFocusMode :
546548 tW = self .mainConf .getTextWidth (self .theParent .isFocusMode )
547- tM = max ((wW - sW - tW )// 2 , cM )
549+ tM = max ((wW - sW - tW )// 2 , self . _vpMargin )
548550
549551 tB = self .frameWidth ()
550552 tW = wW - 2 * tB - sW
@@ -561,8 +563,8 @@ def updateDocMargins(self):
561563 rL = wW - sW - rW - 2 * tB
562564 self .docSearch .move (rL , 2 * tB )
563565
564- uM = max (cM , tH , rH )
565- lM = max (cM , fH )
566+ uM = max (self . _vpMargin , tH , rH )
567+ lM = max (self . _vpMargin , fH )
566568 self .setViewportMargins (tM , uM , tM , lM )
567569
568570 return
0 commit comments