Use free string entries for padding instead of many switches

This commit is contained in:
Veronica K. B. Olsen
2021-03-14 14:23:44 +01:00
parent 1d59a67d6e
commit 9f979c02f8
4 changed files with 55 additions and 64 deletions
+43 -45
View File
@@ -98,11 +98,12 @@ class GuiDocEditor(QTextEdit):
self.queuePos = None # Used for delayed change of cursor position
# Typography
self.typPadChar = " "
self.typDQOpen = '"'
self.typDQClose = '"'
self.typSQOpen = "'"
self.typSQClose = "'"
self.typPadChar = " "
self.addPadding = False
# Core Elements and Signals
self.qDocument = self.document()
@@ -204,19 +205,10 @@ class GuiDocEditor(QTextEdit):
else:
self.typPadChar = nwUnicode.U_NBSP
if self.mainConf.fmtPadSingle:
self.typSQOpen = self.mainConf.fmtSingleQuotes[0] + self.typPadChar
self.typSQClose = self.typPadChar + self.mainConf.fmtSingleQuotes[1]
else:
self.typSQOpen = self.mainConf.fmtSingleQuotes[0]
self.typSQClose = self.mainConf.fmtSingleQuotes[1]
if self.mainConf.fmtPadDouble:
self.typDQOpen = self.mainConf.fmtDoubleQuotes[0] + self.typPadChar
self.typDQClose = self.typPadChar + self.mainConf.fmtDoubleQuotes[1]
else:
self.typDQOpen = self.mainConf.fmtDoubleQuotes[0]
self.typDQClose = self.mainConf.fmtDoubleQuotes[1]
self.typSQOpen = self.mainConf.fmtSingleQuotes[0]
self.typSQClose = self.mainConf.fmtSingleQuotes[1]
self.typDQOpen = self.mainConf.fmtDoubleQuotes[0]
self.typDQClose = self.mainConf.fmtDoubleQuotes[1]
# Reload spell check and dictionaries
self._setupSpellChecking()
@@ -1241,56 +1233,62 @@ class GuiDocEditor(QTextEdit):
theTwo = theText[thePos-2:thePos]
theThree = theText[thePos-3:thePos]
if self.mainConf.doReplaceDQuote and theTwo == " \"":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
theCursor.insertText(self.typDQOpen)
if not theOne: # Makes Neo sad
return
elif self.mainConf.doReplaceDQuote and theOne == "\"":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
nDelete = 0
tInsert = theOne
if self.mainConf.doReplaceDQuote and theTwo == ' "':
nDelete = 1
tInsert = self.typDQOpen
elif self.mainConf.doReplaceDQuote and theOne == '"':
nDelete = 1
if thePos == 1:
theCursor.insertText(self.typDQOpen)
tInsert = self.typDQOpen
else:
theCursor.insertText(self.typDQClose)
return
tInsert = self.typDQClose
elif self.mainConf.doReplaceSQuote and theTwo == " '":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
theCursor.insertText(self.typSQOpen)
return
nDelete = 1
tInsert = self.typSQOpen
elif self.mainConf.doReplaceSQuote and theOne == "'":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
nDelete = 1
if thePos == 1:
theCursor.insertText(self.typSQOpen)
tInsert = self.typSQOpen
else:
theCursor.insertText(self.typSQClose)
return
tInsert = self.typSQClose
elif self.mainConf.doReplaceDash and theThree == "---":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 3)
theCursor.insertText(nwUnicode.U_EMDASH)
return
nDelete = 3
tInsert = nwUnicode.U_EMDASH
elif self.mainConf.doReplaceDash and theTwo == "--":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 2)
theCursor.insertText(nwUnicode.U_ENDASH)
return
nDelete = 2
tInsert = nwUnicode.U_ENDASH
elif self.mainConf.doReplaceDash and theTwo == nwUnicode.U_ENDASH + "-":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 2)
theCursor.insertText(nwUnicode.U_EMDASH)
return
nDelete = 2
tInsert = nwUnicode.U_EMDASH
elif self.mainConf.doReplaceDots and theThree == "...":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 3)
theCursor.insertText(nwUnicode.U_HELLIP)
return
nDelete = 3
tInsert = nwUnicode.U_HELLIP
if self.mainConf.fmtPadPunct:
if theOne in ("!", "?", ":", ";"):
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
theCursor.insertText(self.typPadChar + theOne)
tCheck = tInsert
if tCheck in self.mainConf.fmtPadBefore:
nDelete = max(nDelete, 1)
tInsert = self.typPadChar + tInsert
if tCheck in self.mainConf.fmtPadAfter:
nDelete = max(nDelete, 1)
tInsert = tInsert + self.typPadChar
if nDelete > 0:
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, nDelete)
theCursor.insertText(tInsert)
return