Make sure existing space is stripped before inserting non-breaking space (#1061)

This commit is contained in:
Veronica Berglyd Olsen
2022-10-01 22:35:00 +02:00
parent 3efbc14d97
commit 1aeb66d9af
+16 -9
View File
@@ -111,6 +111,7 @@ class GuiDocEditor(QTextEdit):
self._typSQOpen = "'" self._typSQOpen = "'"
self._typSQClose = "'" self._typSQClose = "'"
self._typPadChar = " " self._typPadChar = " "
self._doSpacePad = False
# Core Elements and Signals # Core Elements and Signals
qDoc = self.document() qDoc = self.document()
@@ -221,6 +222,7 @@ class GuiDocEditor(QTextEdit):
self._nonWord += "".join(self.mainConf.fmtSingleQuotes) self._nonWord += "".join(self.mainConf.fmtSingleQuotes)
# Typography # Typography
self._doSpacePad = bool(self.mainConf.fmtPadBefore) or bool(self.mainConf.fmtPadAfter)
if self.mainConf.fmtPadThin: if self.mainConf.fmtPadThin:
self._typPadChar = nwUnicode.U_THNBSP self._typPadChar = nwUnicode.U_THNBSP
else: else:
@@ -1992,16 +1994,21 @@ class GuiDocEditor(QTextEdit):
nDelete = 3 nDelete = 3
tInsert = nwUnicode.U_HELLIP tInsert = nwUnicode.U_HELLIP
tCheck = tInsert if self._doSpacePad:
if tCheck in self.mainConf.fmtPadBefore: tCheck = tInsert
if self._allowSpaceBeforeColon(theText, tCheck): if tCheck in self.mainConf.fmtPadBefore:
nDelete = max(nDelete, 1) if self._allowSpaceBeforeColon(theText, tCheck):
tInsert = self._typPadChar + tInsert nDelete = max(nDelete, 1)
chkPos = thePos - nDelete - 1
if chkPos >= 0 and theText[chkPos].isspace():
# Strip existing space before inserting a new (#1061)
nDelete += 1
tInsert = self._typPadChar + tInsert
if tCheck in self.mainConf.fmtPadAfter: if tCheck in self.mainConf.fmtPadAfter:
if self._allowSpaceBeforeColon(theText, tCheck): if self._allowSpaceBeforeColon(theText, tCheck):
nDelete = max(nDelete, 1) nDelete = max(nDelete, 1)
tInsert = tInsert + self._typPadChar tInsert = tInsert + self._typPadChar
if nDelete > 0: if nDelete > 0:
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, nDelete) theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, nDelete)