Simplify the typewriter mode

This commit is contained in:
Veronica K. B. Olsen
2020-10-11 22:52:06 +02:00
parent 77ec41a820
commit c76c2df925
5 changed files with 37 additions and 38 deletions
+5
View File
@@ -128,6 +128,7 @@ class Config:
self.doReplaceDots = True self.doReplaceDots = True
self.scrollPastEnd = True self.scrollPastEnd = True
self.scollWithCursor = False self.scollWithCursor = False
self.scollFromPoint = 40
self.wordCountTimer = 5.0 self.wordCountTimer = 5.0
self.showTabsNSpaces = False self.showTabsNSpaces = False
@@ -467,6 +468,9 @@ class Config:
self.scollWithCursor = self._parseLine( self.scollWithCursor = self._parseLine(
cnfParse, cnfSec, "scollwithcursor", self.CNF_BOOL, self.scollWithCursor cnfParse, cnfSec, "scollwithcursor", self.CNF_BOOL, self.scollWithCursor
) )
self.scollFromPoint = self._parseLine(
cnfParse, cnfSec, "scollfrompoint", self.CNF_INT, self.scollFromPoint
)
self.fmtSingleQuotes = self._parseLine( self.fmtSingleQuotes = self._parseLine(
cnfParse, cnfSec, "fmtsinglequote", self.CNF_LIST, self.fmtSingleQuotes cnfParse, cnfSec, "fmtsinglequote", self.CNF_LIST, self.fmtSingleQuotes
) )
@@ -613,6 +617,7 @@ class Config:
cnfParse.set(cnfSec, "repdots", str(self.doReplaceDots)) cnfParse.set(cnfSec, "repdots", str(self.doReplaceDots))
cnfParse.set(cnfSec, "scrollpastend", str(self.scrollPastEnd)) cnfParse.set(cnfSec, "scrollpastend", str(self.scrollPastEnd))
cnfParse.set(cnfSec, "scollwithcursor", str(self.scollWithCursor)) 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, "fmtsinglequote", self._packList(self.fmtSingleQuotes))
cnfParse.set(cnfSec, "fmtdoublequote", self._packList(self.fmtDoubleQuotes)) cnfParse.set(cnfSec, "fmtdoublequote", self._packList(self.fmtDoubleQuotes))
cnfParse.set(cnfSec, "spelltool", str(self.spellTool)) cnfParse.set(cnfSec, "spelltool", str(self.spellTool))
+7 -35
View File
@@ -88,8 +88,6 @@ class GuiDocEditor(QTextEdit):
self.bigDoc = False # Flag for very large document size self.bigDoc = False # Flag for very large document size
self.doReplace = False # Switch to temporarily disable auto-replace self.doReplace = False # Switch to temporarily disable auto-replace
self.queuePos = None # Used for delayed change of cursor position 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 # Typography
self.typDQOpen = self.mainConf.fmtDoubleQuotes[0] self.typDQOpen = self.mainConf.fmtDoubleQuotes[0]
@@ -102,8 +100,6 @@ class GuiDocEditor(QTextEdit):
self.qDocument.contentsChange.connect(self._docChange) self.qDocument.contentsChange.connect(self._docChange)
self.qDocument.documentLayout().documentSizeChanged.connect(self._docSizeChanged) self.qDocument.documentLayout().documentSizeChanged.connect(self._docSizeChanged)
self.verticalScrollBar().sliderMoved.connect(self._doVerticalScroll)
# Document Title # Document Title
self.docHeader = GuiDocEditHeader(self) self.docHeader = GuiDocEditHeader(self)
self.docFooter = GuiDocEditFooter(self) self.docFooter = GuiDocEditFooter(self)
@@ -440,7 +436,7 @@ class GuiDocEditor(QTextEdit):
if self.mainConf.scrollPastEnd: if self.mainConf.scrollPastEnd:
docFrame = self.qDocument.rootFrame().frameFormat() 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)) docFrame.setBottomMargin(max(0, docMargin))
self.qDocument.rootFrame().setFrameFormat(docFrame) self.qDocument.rootFrame().setFrameFormat(docFrame)
@@ -496,7 +492,6 @@ class GuiDocEditor(QTextEdit):
theCursor.setPosition(thePosition) theCursor.setPosition(thePosition)
self.setTextCursor(theCursor) self.setTextCursor(theCursor)
self.docFooter.updateLineCount() self.docFooter.updateLineCount()
self.cursorLast = self.cursorRect().center().y()
return True return True
@@ -777,20 +772,13 @@ class GuiDocEditor(QTextEdit):
self.docFooter.updateLineCount() self.docFooter.updateLineCount()
if self.mainConf.scollWithCursor: if self.mainConf.scollWithCursor:
docLen = self.qDocument.characterCount() kMod = keyEvent.modifiers()
if docLen == self.lengthLast: if kMod == Qt.NoModifier or kMod == Qt.ShiftModifier:
# 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()
cPos = self.cursorRect().center().y() cPos = self.cursorRect().center().y()
if cPos != self.cursorLast: mPos = self.mainConf.scollFromPoint*self.height()*0.01
vBar = self.verticalScrollBar() vBar = self.verticalScrollBar()
vBar.setValue(vBar.value() + cPos - self.cursorLast) vBar.setValue(vBar.value() + cPos - round(mPos))
self.cursorLast = self.cursorRect().center().y() self.ensureCursorVisible()
return return
@@ -817,18 +805,9 @@ class GuiDocEditor(QTextEdit):
QTextEdit.mouseReleaseEvent(self, mEvent) QTextEdit.mouseReleaseEvent(self, mEvent)
self.docFooter.updateLineCount() self.docFooter.updateLineCount()
self.cursorLast = self.cursorRect().center().y()
return 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): def resizeEvent(self, theEvent):
"""If the text editor is resize, we must make sure the document """If the text editor is resize, we must make sure the document
has its margins adjusted according to user preferences. has its margins adjusted according to user preferences.
@@ -863,13 +842,6 @@ class GuiDocEditor(QTextEdit):
self._docAutoReplace(self.qDocument.findBlock(thePos)) self._docAutoReplace(self.qDocument.findBlock(thePos))
return return
@pyqtSlot(int)
def _doVerticalScroll(self, theChange):
"""Update the cursor position on vertical scrolling.
"""
self.cursorLast = self.cursorRect().center().y()
return
@pyqtSlot("QPoint") @pyqtSlot("QPoint")
def _openContextMenu(self, thePos): def _openContextMenu(self, thePos):
"""Triggered by right click to open the context menu. Also """Triggered by right click to open the context menu. Also
+22 -2
View File
@@ -555,6 +555,10 @@ class GuiConfigEditLayoutTab(QWidget):
theUnit="px" theUnit="px"
) )
# Scroll Behaviour
# ================
self.mainForm.addGroupLabel("Scroll Behaviour")
## Scroll Past End ## Scroll Past End
self.scrollPastEnd = QSwitch() self.scrollPastEnd = QSwitch()
self.scrollPastEnd.setChecked(self.mainConf.scrollPastEnd) self.scrollPastEnd.setChecked(self.mainConf.scrollPastEnd)
@@ -568,11 +572,25 @@ class GuiConfigEditLayoutTab(QWidget):
self.scollWithCursor = QSwitch() self.scollWithCursor = QSwitch()
self.scollWithCursor.setChecked(self.mainConf.scollWithCursor) self.scollWithCursor.setChecked(self.mainConf.scollWithCursor)
self.mainForm.addRow( self.mainForm.addRow(
"Typewriter style scrolling", "Typewriter style scrolling when you type",
self.scollWithCursor, 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 return
def saveValues(self): def saveValues(self):
@@ -592,6 +610,7 @@ class GuiConfigEditLayoutTab(QWidget):
tabWidth = self.tabWidth.value() tabWidth = self.tabWidth.value()
scrollPastEnd = self.scrollPastEnd.isChecked() scrollPastEnd = self.scrollPastEnd.isChecked()
scollWithCursor = self.scollWithCursor.isChecked() scollWithCursor = self.scollWithCursor.isChecked()
scollFromPoint = self.scollFromPoint.value()
self.mainConf.textFont = textFont self.mainConf.textFont = textFont
self.mainConf.textSize = textSize self.mainConf.textSize = textSize
@@ -604,6 +623,7 @@ class GuiConfigEditLayoutTab(QWidget):
self.mainConf.tabWidth = tabWidth self.mainConf.tabWidth = tabWidth
self.mainConf.scrollPastEnd = scrollPastEnd self.mainConf.scrollPastEnd = scrollPastEnd
self.mainConf.scollWithCursor = scollWithCursor self.mainConf.scollWithCursor = scollWithCursor
self.mainConf.scollFromPoint = scollFromPoint
self.mainConf.confChanged = True self.mainConf.confChanged = True
+2 -1
View File
@@ -1,5 +1,5 @@
[Main] [Main]
timestamp = 2020-10-11 18:29:34 timestamp = 2020-10-11 22:50:45
theme = default theme = default
syntax = default_light syntax = default_light
icons = typicons_colour_light icons = typicons_colour_light
@@ -41,6 +41,7 @@ repdash = True
repdots = True repdots = True
scrollpastend = True scrollpastend = True
scollwithcursor = False scollwithcursor = False
scollfrompoint = 40
fmtsinglequote = , fmtsinglequote = ,
fmtdoublequote = “, ” fmtdoublequote = “, ”
spelltool = internal spelltool = internal
+1
View File
@@ -41,6 +41,7 @@ repdash = True
repdots = True repdots = True
scrollpastend = False scrollpastend = False
scollwithcursor = True scollwithcursor = True
scollfrompoint = 40
fmtsinglequote = , fmtsinglequote = ,
fmtdoublequote = “, ” fmtdoublequote = “, ”
spelltool = internal spelltool = internal