Add optional padding for large punctuation symbols

This commit is contained in:
Veronica K. B. Olsen
2021-03-13 23:38:12 +01:00
parent e07a7ac496
commit 5837a4602a
2 changed files with 28 additions and 9 deletions
+6 -1
View File
@@ -166,7 +166,8 @@ class Config:
self.fmtDoubleQuotes = [nwUnicode.U_LDQUO, nwUnicode.U_RDQUO]
self.fmtPadSingle = False
self.fmtPadDouble = False
self.fmtPadThin = True
self.fmtPadThin = False
self.fmtPadPunct = False
## Spell Checking
self.spellTool = None
@@ -590,6 +591,9 @@ class Config:
self.fmtPadThin = self._parseLine(
cnfParse, cnfSec, "fmtpadthin", self.CNF_BOOL, self.fmtPadThin
)
self.fmtPadPunct = self._parseLine(
cnfParse, cnfSec, "fmtpadpunct", self.CNF_BOOL, self.fmtPadPunct
)
self.spellTool = self._parseLine(
cnfParse, cnfSec, "spelltool", self.CNF_STR, self.spellTool
)
@@ -761,6 +765,7 @@ class Config:
cnfParse.set(cnfSec, "fmtpadsingle", str(self.fmtPadSingle))
cnfParse.set(cnfSec, "fmtpaddouble", str(self.fmtPadDouble))
cnfParse.set(cnfSec, "fmtpadthin", str(self.fmtPadThin))
cnfParse.set(cnfSec, "fmtpadpunct", str(self.fmtPadPunct))
cnfParse.set(cnfSec, "spelltool", str(self.spellTool))
cnfParse.set(cnfSec, "spellcheck", str(self.spellLanguage))
cnfParse.set(cnfSec, "showtabsnspaces", str(self.showTabsNSpaces))
+22 -8
View File
@@ -98,6 +98,7 @@ class GuiDocEditor(QTextEdit):
self.queuePos = None # Used for delayed change of cursor position
# Typography
self.typPadChar = " "
self.typDQOpen = '"'
self.typDQClose = '"'
self.typSQOpen = "'"
@@ -199,20 +200,20 @@ class GuiDocEditor(QTextEdit):
# Typography
if self.mainConf.fmtPadThin:
padChar = nwUnicode.U_THNBSP
self.typPadChar = nwUnicode.U_THNBSP
else:
padChar = nwUnicode.U_NBSP
self.typPadChar = nwUnicode.U_NBSP
if self.mainConf.fmtPadSingle:
self.typSQOpen = self.mainConf.fmtSingleQuotes[0] + padChar
self.typSQClose = padChar + self.mainConf.fmtSingleQuotes[1]
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] + padChar
self.typDQClose = padChar + self.mainConf.fmtDoubleQuotes[1]
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]
@@ -1223,7 +1224,7 @@ class GuiDocEditor(QTextEdit):
return
def _docAutoReplace(self, theBlock):
"""Autoreplace text elements based on main configuration.
"""Auto-replace text elements based on main configuration.
"""
if not theBlock.isValid():
return
@@ -1243,6 +1244,7 @@ class GuiDocEditor(QTextEdit):
if self.mainConf.doReplaceDQuote and theTwo == " \"":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
theCursor.insertText(self.typDQOpen)
return
elif self.mainConf.doReplaceDQuote and theOne == "\"":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
@@ -1250,10 +1252,12 @@ class GuiDocEditor(QTextEdit):
theCursor.insertText(self.typDQOpen)
else:
theCursor.insertText(self.typDQClose)
return
elif self.mainConf.doReplaceSQuote and theTwo == " '":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
theCursor.insertText(self.typSQOpen)
return
elif self.mainConf.doReplaceSQuote and theOne == "'":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
@@ -1261,22 +1265,32 @@ class GuiDocEditor(QTextEdit):
theCursor.insertText(self.typSQOpen)
else:
theCursor.insertText(self.typSQClose)
return
elif self.mainConf.doReplaceDash and theThree == "---":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 3)
theCursor.insertText(nwUnicode.U_EMDASH)
return
elif self.mainConf.doReplaceDash and theTwo == "--":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 2)
theCursor.insertText(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)
theCursor.insertText(nwUnicode.U_EMDASH)
return
elif self.mainConf.doReplaceDots and theThree == "...":
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 3)
theCursor.insertText(nwUnicode.U_HELLIP)
return
if self.mainConf.fmtPadPunct:
if theOne in ("!", "?", ":", ";"):
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
theCursor.insertText(self.typPadChar + theOne)
return