Simplify the typewriter mode
This commit is contained in:
@@ -128,6 +128,7 @@ class Config:
|
||||
self.doReplaceDots = True
|
||||
self.scrollPastEnd = True
|
||||
self.scollWithCursor = False
|
||||
self.scollFromPoint = 40
|
||||
|
||||
self.wordCountTimer = 5.0
|
||||
self.showTabsNSpaces = False
|
||||
@@ -467,6 +468,9 @@ class Config:
|
||||
self.scollWithCursor = self._parseLine(
|
||||
cnfParse, cnfSec, "scollwithcursor", self.CNF_BOOL, self.scollWithCursor
|
||||
)
|
||||
self.scollFromPoint = self._parseLine(
|
||||
cnfParse, cnfSec, "scollfrompoint", self.CNF_INT, self.scollFromPoint
|
||||
)
|
||||
self.fmtSingleQuotes = self._parseLine(
|
||||
cnfParse, cnfSec, "fmtsinglequote", self.CNF_LIST, self.fmtSingleQuotes
|
||||
)
|
||||
@@ -613,6 +617,7 @@ class Config:
|
||||
cnfParse.set(cnfSec, "repdots", str(self.doReplaceDots))
|
||||
cnfParse.set(cnfSec, "scrollpastend", str(self.scrollPastEnd))
|
||||
cnfParse.set(cnfSec, "scollwithcursor", str(self.scollWithCursor))
|
||||
cnfParse.set(cnfSec, "scollfrompoint", str(self.scollFromPoint))
|
||||
cnfParse.set(cnfSec, "fmtsinglequote", self._packList(self.fmtSingleQuotes))
|
||||
cnfParse.set(cnfSec, "fmtdoublequote", self._packList(self.fmtDoubleQuotes))
|
||||
cnfParse.set(cnfSec, "spelltool", str(self.spellTool))
|
||||
|
||||
+7
-35
@@ -88,8 +88,6 @@ class GuiDocEditor(QTextEdit):
|
||||
self.bigDoc = False # Flag for very large document size
|
||||
self.doReplace = False # Switch to temporarily disable auto-replace
|
||||
self.queuePos = None # Used for delayed change of cursor position
|
||||
self.cursorLast = 0 # The last known vertical position of the cursor
|
||||
self.lengthLast = 0
|
||||
|
||||
# Typography
|
||||
self.typDQOpen = self.mainConf.fmtDoubleQuotes[0]
|
||||
@@ -102,8 +100,6 @@ class GuiDocEditor(QTextEdit):
|
||||
self.qDocument.contentsChange.connect(self._docChange)
|
||||
self.qDocument.documentLayout().documentSizeChanged.connect(self._docSizeChanged)
|
||||
|
||||
self.verticalScrollBar().sliderMoved.connect(self._doVerticalScroll)
|
||||
|
||||
# Document Title
|
||||
self.docHeader = GuiDocEditHeader(self)
|
||||
self.docFooter = GuiDocEditFooter(self)
|
||||
@@ -440,7 +436,7 @@ class GuiDocEditor(QTextEdit):
|
||||
|
||||
if self.mainConf.scrollPastEnd:
|
||||
docFrame = self.qDocument.rootFrame().frameFormat()
|
||||
docMargin = wH - uM - lM - 5*self.theTheme.fontPixelSize
|
||||
docMargin = wH - uM - lM - 4*tB - 5*self.theTheme.fontPixelSize
|
||||
docFrame.setBottomMargin(max(0, docMargin))
|
||||
self.qDocument.rootFrame().setFrameFormat(docFrame)
|
||||
|
||||
@@ -496,7 +492,6 @@ class GuiDocEditor(QTextEdit):
|
||||
theCursor.setPosition(thePosition)
|
||||
self.setTextCursor(theCursor)
|
||||
self.docFooter.updateLineCount()
|
||||
self.cursorLast = self.cursorRect().center().y()
|
||||
|
||||
return True
|
||||
|
||||
@@ -777,20 +772,13 @@ class GuiDocEditor(QTextEdit):
|
||||
self.docFooter.updateLineCount()
|
||||
|
||||
if self.mainConf.scollWithCursor:
|
||||
docLen = self.qDocument.characterCount()
|
||||
if docLen == self.lengthLast:
|
||||
# No change, so just update last position
|
||||
self.cursorLast = self.cursorRect().center().y()
|
||||
else:
|
||||
# The user typed something, so check if we need to
|
||||
# scroll, and move the scroll bar the same distance
|
||||
self.lengthLast = docLen
|
||||
self.ensureCursorVisible()
|
||||
kMod = keyEvent.modifiers()
|
||||
if kMod == Qt.NoModifier or kMod == Qt.ShiftModifier:
|
||||
cPos = self.cursorRect().center().y()
|
||||
if cPos != self.cursorLast:
|
||||
vBar = self.verticalScrollBar()
|
||||
vBar.setValue(vBar.value() + cPos - self.cursorLast)
|
||||
self.cursorLast = self.cursorRect().center().y()
|
||||
mPos = self.mainConf.scollFromPoint*self.height()*0.01
|
||||
vBar = self.verticalScrollBar()
|
||||
vBar.setValue(vBar.value() + cPos - round(mPos))
|
||||
self.ensureCursorVisible()
|
||||
|
||||
return
|
||||
|
||||
@@ -817,18 +805,9 @@ class GuiDocEditor(QTextEdit):
|
||||
|
||||
QTextEdit.mouseReleaseEvent(self, mEvent)
|
||||
self.docFooter.updateLineCount()
|
||||
self.cursorLast = self.cursorRect().center().y()
|
||||
|
||||
return
|
||||
|
||||
def wheelEvent(self, theEvent):
|
||||
"""Briefly capture the mouse wheel event to capture the cursor
|
||||
position.
|
||||
"""
|
||||
QTextEdit.wheelEvent(self, theEvent)
|
||||
self.cursorLast = self.cursorRect().center().y()
|
||||
return
|
||||
|
||||
def resizeEvent(self, theEvent):
|
||||
"""If the text editor is resize, we must make sure the document
|
||||
has its margins adjusted according to user preferences.
|
||||
@@ -863,13 +842,6 @@ class GuiDocEditor(QTextEdit):
|
||||
self._docAutoReplace(self.qDocument.findBlock(thePos))
|
||||
return
|
||||
|
||||
@pyqtSlot(int)
|
||||
def _doVerticalScroll(self, theChange):
|
||||
"""Update the cursor position on vertical scrolling.
|
||||
"""
|
||||
self.cursorLast = self.cursorRect().center().y()
|
||||
return
|
||||
|
||||
@pyqtSlot("QPoint")
|
||||
def _openContextMenu(self, thePos):
|
||||
"""Triggered by right click to open the context menu. Also
|
||||
|
||||
+22
-2
@@ -555,6 +555,10 @@ class GuiConfigEditLayoutTab(QWidget):
|
||||
theUnit="px"
|
||||
)
|
||||
|
||||
# Scroll Behaviour
|
||||
# ================
|
||||
self.mainForm.addGroupLabel("Scroll Behaviour")
|
||||
|
||||
## Scroll Past End
|
||||
self.scrollPastEnd = QSwitch()
|
||||
self.scrollPastEnd.setChecked(self.mainConf.scrollPastEnd)
|
||||
@@ -568,11 +572,25 @@ class GuiConfigEditLayoutTab(QWidget):
|
||||
self.scollWithCursor = QSwitch()
|
||||
self.scollWithCursor.setChecked(self.mainConf.scollWithCursor)
|
||||
self.mainForm.addRow(
|
||||
"Typewriter style scrolling",
|
||||
"Typewriter style scrolling when you type",
|
||||
self.scollWithCursor,
|
||||
"Scrolls up when the cursor moves to a new line."
|
||||
"Tries to keep the cursor at a fixed vertical position."
|
||||
)
|
||||
|
||||
## Font Size
|
||||
self.scollFromPoint = QSpinBox(self)
|
||||
self.scollFromPoint.setMinimum(10)
|
||||
self.scollFromPoint.setMaximum(90)
|
||||
self.scollFromPoint.setSingleStep(1)
|
||||
self.scollFromPoint.setValue(self.mainConf.scollFromPoint)
|
||||
self.mainForm.addRow(
|
||||
"Position in the editor to keep the cursor",
|
||||
self.scollFromPoint,
|
||||
"In units of percentage of the editor height.",
|
||||
theUnit = "%"
|
||||
)
|
||||
|
||||
|
||||
return
|
||||
|
||||
def saveValues(self):
|
||||
@@ -592,6 +610,7 @@ class GuiConfigEditLayoutTab(QWidget):
|
||||
tabWidth = self.tabWidth.value()
|
||||
scrollPastEnd = self.scrollPastEnd.isChecked()
|
||||
scollWithCursor = self.scollWithCursor.isChecked()
|
||||
scollFromPoint = self.scollFromPoint.value()
|
||||
|
||||
self.mainConf.textFont = textFont
|
||||
self.mainConf.textSize = textSize
|
||||
@@ -604,6 +623,7 @@ class GuiConfigEditLayoutTab(QWidget):
|
||||
self.mainConf.tabWidth = tabWidth
|
||||
self.mainConf.scrollPastEnd = scrollPastEnd
|
||||
self.mainConf.scollWithCursor = scollWithCursor
|
||||
self.mainConf.scollFromPoint = scollFromPoint
|
||||
|
||||
self.mainConf.confChanged = True
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[Main]
|
||||
timestamp = 2020-10-11 18:29:34
|
||||
timestamp = 2020-10-11 22:50:45
|
||||
theme = default
|
||||
syntax = default_light
|
||||
icons = typicons_colour_light
|
||||
@@ -41,6 +41,7 @@ repdash = True
|
||||
repdots = True
|
||||
scrollpastend = True
|
||||
scollwithcursor = False
|
||||
scollfrompoint = 40
|
||||
fmtsinglequote = ‘, ’
|
||||
fmtdoublequote = “, ”
|
||||
spelltool = internal
|
||||
|
||||
@@ -41,6 +41,7 @@ repdash = True
|
||||
repdots = True
|
||||
scrollpastend = False
|
||||
scollwithcursor = True
|
||||
scollfrompoint = 40
|
||||
fmtsinglequote = ‘, ’
|
||||
fmtdoublequote = “, ”
|
||||
spelltool = internal
|
||||
|
||||
Reference in New Issue
Block a user