Process pad before and after settings in Preferences (#1985)
This commit is contained in:
@@ -279,6 +279,16 @@ def simplified(text: str) -> str:
|
|||||||
return " ".join(str(text).strip().split())
|
return " ".join(str(text).strip().split())
|
||||||
|
|
||||||
|
|
||||||
|
def compact(text: str) -> str:
|
||||||
|
"""Compact a string by removing spaces."""
|
||||||
|
return "".join(str(text).split())
|
||||||
|
|
||||||
|
|
||||||
|
def uniqueCompact(text: str) -> str:
|
||||||
|
"""Return a unique, compact and sorted string."""
|
||||||
|
return "".join(sorted(set(compact(text))))
|
||||||
|
|
||||||
|
|
||||||
def elide(text: str, length: int) -> str:
|
def elide(text: str, length: int) -> str:
|
||||||
"""Elide a piece of text to a maximum length."""
|
"""Elide a piece of text to a maximum length."""
|
||||||
if len(text) > (cut := max(4, length)):
|
if len(text) > (cut := max(4, length)):
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ from PyQt5.QtWidgets import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
from novelwriter.common import describeFont
|
from novelwriter.common import describeFont, uniqueCompact
|
||||||
from novelwriter.constants import nwUnicode
|
from novelwriter.constants import nwUnicode
|
||||||
from novelwriter.dialogs.quotes import GuiQuoteSelect
|
from novelwriter.dialogs.quotes import GuiQuoteSelect
|
||||||
from novelwriter.extensions.configlayout import NColourLabel, NScrollableForm
|
from novelwriter.extensions.configlayout import NColourLabel, NScrollableForm
|
||||||
@@ -952,8 +952,8 @@ class GuiPreferences(NDialog):
|
|||||||
# Text Highlighting
|
# Text Highlighting
|
||||||
dialogueStyle = self.dialogStyle.currentData()
|
dialogueStyle = self.dialogStyle.currentData()
|
||||||
allowOpenDial = self.allowOpenDial.isChecked()
|
allowOpenDial = self.allowOpenDial.isChecked()
|
||||||
narratorBreak = self.narratorBreak.text()
|
narratorBreak = self.narratorBreak.text().strip()
|
||||||
dialogueLine = self.dialogLine.text()
|
dialogueLine = self.dialogLine.text().strip()
|
||||||
altDialogOpen = self.altDialogOpen.text()
|
altDialogOpen = self.altDialogOpen.text()
|
||||||
altDialogClose = self.altDialogClose.text()
|
altDialogClose = self.altDialogClose.text()
|
||||||
highlightEmph = self.highlightEmph.isChecked()
|
highlightEmph = self.highlightEmph.isChecked()
|
||||||
@@ -983,8 +983,8 @@ class GuiPreferences(NDialog):
|
|||||||
CONFIG.doReplaceDQuote = self.doReplaceDQuote.isChecked()
|
CONFIG.doReplaceDQuote = self.doReplaceDQuote.isChecked()
|
||||||
CONFIG.doReplaceDash = self.doReplaceDash.isChecked()
|
CONFIG.doReplaceDash = self.doReplaceDash.isChecked()
|
||||||
CONFIG.doReplaceDots = self.doReplaceDots.isChecked()
|
CONFIG.doReplaceDots = self.doReplaceDots.isChecked()
|
||||||
CONFIG.fmtPadBefore = self.fmtPadBefore.text().strip()
|
CONFIG.fmtPadBefore = uniqueCompact(self.fmtPadBefore.text())
|
||||||
CONFIG.fmtPadAfter = self.fmtPadAfter.text().strip()
|
CONFIG.fmtPadAfter = uniqueCompact(self.fmtPadAfter.text())
|
||||||
CONFIG.fmtPadThin = self.fmtPadThin.isChecked()
|
CONFIG.fmtPadThin = self.fmtPadThin.isChecked()
|
||||||
|
|
||||||
# Quotation Style
|
# Quotation Style
|
||||||
|
|||||||
@@ -32,12 +32,12 @@ from PyQt5.QtGui import QColor, QDesktopServices, QFontDatabase
|
|||||||
|
|
||||||
from novelwriter.common import (
|
from novelwriter.common import (
|
||||||
NWConfigParser, checkBool, checkFloat, checkInt, checkIntTuple, checkPath,
|
NWConfigParser, checkBool, checkFloat, checkInt, checkIntTuple, checkPath,
|
||||||
checkString, checkStringNone, checkUuid, cssCol, describeFont, elide,
|
checkString, checkStringNone, checkUuid, compact, cssCol, describeFont,
|
||||||
formatFileFilter, formatInt, formatTime, formatTimeStamp, formatVersion,
|
elide, formatFileFilter, formatInt, formatTime, formatTimeStamp,
|
||||||
fuzzyTime, getFileSize, hexToInt, isHandle, isItemClass, isItemLayout,
|
formatVersion, fuzzyTime, getFileSize, hexToInt, isHandle, isItemClass,
|
||||||
isItemType, isListInstance, isTitleTag, jsonEncode, makeFileNameSafe,
|
isItemLayout, isItemType, isListInstance, isTitleTag, jsonEncode,
|
||||||
minmax, numberToRoman, openExternalPath, readTextFile, simplified,
|
makeFileNameSafe, minmax, numberToRoman, openExternalPath, readTextFile,
|
||||||
transferCase, xmlIndent, yesNo
|
simplified, transferCase, uniqueCompact, xmlIndent, yesNo
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.mocked import causeOSError
|
from tests.mocked import causeOSError
|
||||||
@@ -346,6 +346,27 @@ def testBaseCommon_simplified():
|
|||||||
assert simplified("\tHello\n\r\tWorld") == "Hello World"
|
assert simplified("\tHello\n\r\tWorld") == "Hello World"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.base
|
||||||
|
def testBaseCommon_compact():
|
||||||
|
"""Test the compact function."""
|
||||||
|
assert compact("! ! !") == "!!!"
|
||||||
|
assert compact("1\t2\t3") == "123"
|
||||||
|
assert compact("1\n2\n3") == "123"
|
||||||
|
assert compact("1\r2\r3") == "123"
|
||||||
|
assert compact("1\u00a02\u00a03") == "123"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.base
|
||||||
|
def testBaseCommon_uniqueCompact():
|
||||||
|
"""Test the uniqueCompact function."""
|
||||||
|
assert uniqueCompact("! ! !") == "!"
|
||||||
|
assert uniqueCompact("1\t2\t3") == "123"
|
||||||
|
assert uniqueCompact("1\n2\n3") == "123"
|
||||||
|
assert uniqueCompact("1\r2\r3") == "123"
|
||||||
|
assert uniqueCompact("1\u00a02\u00a03") == "123"
|
||||||
|
assert uniqueCompact("3 2 1") == "123"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.base
|
@pytest.mark.base
|
||||||
def testBaseCommon_elide():
|
def testBaseCommon_elide():
|
||||||
"""Test the elide function."""
|
"""Test the elide function."""
|
||||||
|
|||||||
Reference in New Issue
Block a user