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
+8 -13
View File
@@ -164,10 +164,9 @@ class Config:
self.fmtApostrophe = nwUnicode.U_RSQUO self.fmtApostrophe = nwUnicode.U_RSQUO
self.fmtSingleQuotes = [nwUnicode.U_LSQUO, nwUnicode.U_RSQUO] self.fmtSingleQuotes = [nwUnicode.U_LSQUO, nwUnicode.U_RSQUO]
self.fmtDoubleQuotes = [nwUnicode.U_LDQUO, nwUnicode.U_RDQUO] self.fmtDoubleQuotes = [nwUnicode.U_LDQUO, nwUnicode.U_RDQUO]
self.fmtPadSingle = False self.fmtPadBefore = ""
self.fmtPadDouble = False self.fmtPadAfter = ""
self.fmtPadThin = False self.fmtPadThin = False
self.fmtPadPunct = False
## Spell Checking ## Spell Checking
self.spellTool = None self.spellTool = None
@@ -582,18 +581,15 @@ class Config:
self.fmtDoubleQuotes = self._parseLine( self.fmtDoubleQuotes = self._parseLine(
cnfParse, cnfSec, "fmtdoublequote", self.CNF_S_LST, self.fmtDoubleQuotes cnfParse, cnfSec, "fmtdoublequote", self.CNF_S_LST, self.fmtDoubleQuotes
) )
self.fmtPadSingle = self._parseLine( self.fmtPadBefore = self._parseLine(
cnfParse, cnfSec, "fmtpadsingle", self.CNF_BOOL, self.fmtPadSingle cnfParse, cnfSec, "fmtpadbefore", self.CNF_STR, self.fmtPadBefore
) )
self.fmtPadDouble = self._parseLine( self.fmtPadAfter = self._parseLine(
cnfParse, cnfSec, "fmtpaddouble", self.CNF_BOOL, self.fmtPadDouble cnfParse, cnfSec, "fmtpadafter", self.CNF_STR, self.fmtPadAfter
) )
self.fmtPadThin = self._parseLine( self.fmtPadThin = self._parseLine(
cnfParse, cnfSec, "fmtpadthin", self.CNF_BOOL, self.fmtPadThin cnfParse, cnfSec, "fmtpadthin", self.CNF_BOOL, self.fmtPadThin
) )
self.fmtPadPunct = self._parseLine(
cnfParse, cnfSec, "fmtpadpunct", self.CNF_BOOL, self.fmtPadPunct
)
self.spellTool = self._parseLine( self.spellTool = self._parseLine(
cnfParse, cnfSec, "spelltool", self.CNF_STR, self.spellTool cnfParse, cnfSec, "spelltool", self.CNF_STR, self.spellTool
) )
@@ -762,10 +758,9 @@ class Config:
cnfParse.set(cnfSec, "autoscrollpos", str(self.autoScrollPos)) cnfParse.set(cnfSec, "autoscrollpos", str(self.autoScrollPos))
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, "fmtpadsingle", str(self.fmtPadSingle)) cnfParse.set(cnfSec, "fmtpadbefore", str(self.fmtPadBefore))
cnfParse.set(cnfSec, "fmtpaddouble", str(self.fmtPadDouble)) cnfParse.set(cnfSec, "fmtpadafter", str(self.fmtPadAfter))
cnfParse.set(cnfSec, "fmtpadthin", str(self.fmtPadThin)) cnfParse.set(cnfSec, "fmtpadthin", str(self.fmtPadThin))
cnfParse.set(cnfSec, "fmtpadpunct", str(self.fmtPadPunct))
cnfParse.set(cnfSec, "spelltool", str(self.spellTool)) cnfParse.set(cnfSec, "spelltool", str(self.spellTool))
cnfParse.set(cnfSec, "spellcheck", str(self.spellLanguage)) cnfParse.set(cnfSec, "spellcheck", str(self.spellLanguage))
cnfParse.set(cnfSec, "showtabsnspaces", str(self.showTabsNSpaces)) cnfParse.set(cnfSec, "showtabsnspaces", str(self.showTabsNSpaces))
+43 -45
View File
@@ -98,11 +98,12 @@ class GuiDocEditor(QTextEdit):
self.queuePos = None # Used for delayed change of cursor position self.queuePos = None # Used for delayed change of cursor position
# Typography # Typography
self.typPadChar = " "
self.typDQOpen = '"' self.typDQOpen = '"'
self.typDQClose = '"' self.typDQClose = '"'
self.typSQOpen = "'" self.typSQOpen = "'"
self.typSQClose = "'" self.typSQClose = "'"
self.typPadChar = " "
self.addPadding = False
# Core Elements and Signals # Core Elements and Signals
self.qDocument = self.document() self.qDocument = self.document()
@@ -204,19 +205,10 @@ class GuiDocEditor(QTextEdit):
else: else:
self.typPadChar = nwUnicode.U_NBSP self.typPadChar = nwUnicode.U_NBSP
if self.mainConf.fmtPadSingle: self.typSQOpen = self.mainConf.fmtSingleQuotes[0]
self.typSQOpen = self.mainConf.fmtSingleQuotes[0] + self.typPadChar self.typSQClose = self.mainConf.fmtSingleQuotes[1]
self.typSQClose = self.typPadChar + self.mainConf.fmtSingleQuotes[1] self.typDQOpen = self.mainConf.fmtDoubleQuotes[0]
else: self.typDQClose = self.mainConf.fmtDoubleQuotes[1]
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]
# Reload spell check and dictionaries # Reload spell check and dictionaries
self._setupSpellChecking() self._setupSpellChecking()
@@ -1241,56 +1233,62 @@ class GuiDocEditor(QTextEdit):
theTwo = theText[thePos-2:thePos] theTwo = theText[thePos-2:thePos]
theThree = theText[thePos-3:thePos] theThree = theText[thePos-3:thePos]
if self.mainConf.doReplaceDQuote and theTwo == " \"": if not theOne: # Makes Neo sad
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
theCursor.insertText(self.typDQOpen)
return return
elif self.mainConf.doReplaceDQuote and theOne == "\"": nDelete = 0
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1) tInsert = theOne
if self.mainConf.doReplaceDQuote and theTwo == ' "':
nDelete = 1
tInsert = self.typDQOpen
elif self.mainConf.doReplaceDQuote and theOne == '"':
nDelete = 1
if thePos == 1: if thePos == 1:
theCursor.insertText(self.typDQOpen) tInsert = self.typDQOpen
else: else:
theCursor.insertText(self.typDQClose) tInsert = self.typDQClose
return
elif self.mainConf.doReplaceSQuote and theTwo == " '": elif self.mainConf.doReplaceSQuote and theTwo == " '":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1) nDelete = 1
theCursor.insertText(self.typSQOpen) tInsert = self.typSQOpen
return
elif self.mainConf.doReplaceSQuote and theOne == "'": elif self.mainConf.doReplaceSQuote and theOne == "'":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1) nDelete = 1
if thePos == 1: if thePos == 1:
theCursor.insertText(self.typSQOpen) tInsert = self.typSQOpen
else: else:
theCursor.insertText(self.typSQClose) tInsert = self.typSQClose
return
elif self.mainConf.doReplaceDash and theThree == "---": elif self.mainConf.doReplaceDash and theThree == "---":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 3) nDelete = 3
theCursor.insertText(nwUnicode.U_EMDASH) tInsert = nwUnicode.U_EMDASH
return
elif self.mainConf.doReplaceDash and theTwo == "--": elif self.mainConf.doReplaceDash and theTwo == "--":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 2) nDelete = 2
theCursor.insertText(nwUnicode.U_ENDASH) tInsert = nwUnicode.U_ENDASH
return
elif self.mainConf.doReplaceDash and theTwo == nwUnicode.U_ENDASH + "-": elif self.mainConf.doReplaceDash and theTwo == nwUnicode.U_ENDASH + "-":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 2) nDelete = 2
theCursor.insertText(nwUnicode.U_EMDASH) tInsert = nwUnicode.U_EMDASH
return
elif self.mainConf.doReplaceDots and theThree == "...": elif self.mainConf.doReplaceDots and theThree == "...":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 3) nDelete = 3
theCursor.insertText(nwUnicode.U_HELLIP) tInsert = nwUnicode.U_HELLIP
return
if self.mainConf.fmtPadPunct: tCheck = tInsert
if theOne in ("!", "?", ":", ";"): if tCheck in self.mainConf.fmtPadBefore:
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1) nDelete = max(nDelete, 1)
theCursor.insertText(self.typPadChar + theOne) 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 return
+2 -3
View File
@@ -48,10 +48,9 @@ autoscroll = False
autoscrollpos = 30 autoscrollpos = 30
fmtsinglequote = , fmtsinglequote = ,
fmtdoublequote = “, ” fmtdoublequote = “, ”
fmtpadsingle = False fmtpadbefore =
fmtpaddouble = False fmtpadafter =
fmtpadthin = False fmtpadthin = False
fmtpadpunct = False
spelltool = internal spelltool = internal
spellcheck = en spellcheck = en
showtabsnspaces = False showtabsnspaces = False
@@ -48,10 +48,9 @@ autoscroll = True
autoscrollpos = 30 autoscrollpos = 30
fmtsinglequote = , fmtsinglequote = ,
fmtdoublequote = “, ” fmtdoublequote = “, ”
fmtpadsingle = False fmtpadbefore =
fmtpaddouble = False fmtpadafter =
fmtpadthin = False fmtpadthin = False
fmtpadpunct = False
spelltool = internal spelltool = internal
spellcheck = en spellcheck = en
showtabsnspaces = True showtabsnspaces = True