Implement alternative tag display name format

This commit is contained in:
Veronica Berglyd Olsen
2024-01-30 21:34:36 +01:00
parent c5edbbfaf6
commit ca188fee08
7 changed files with 65 additions and 68 deletions
+3 -4
View File
@@ -56,7 +56,6 @@ from novelwriter import CONFIG, SHARED
from novelwriter.enum import nwDocAction, nwDocInsert, nwDocMode, nwItemClass, nwTrinary
from novelwriter.common import minmax, transferCase
from novelwriter.constants import nwKeyWords, nwLabels, nwShortcode, nwUnicode, trConst
from novelwriter.core.item import NWItem
from novelwriter.core.index import countWords
from novelwriter.tools.lipsum import GuiLipsum
from novelwriter.core.document import NWDocument
@@ -1835,16 +1834,16 @@ class GuiDocEditor(QPlainTextEdit):
if len(text) == 0:
return nwTrinary.NEUTRAL
if text.startswith("@") and isinstance(self._nwItem, NWItem):
if text.startswith("@") and self._docHandle:
isGood, tBits, tPos = SHARED.project.index.scanThis(text)
if not isGood:
if not isGood or not tBits or tBits[0] == nwKeyWords.TAG_KEY:
return nwTrinary.NEUTRAL
tag = ""
exist = False
cPos = cursor.selectionStart() - block.position()
tExist = SHARED.project.index.checkThese(tBits, self._nwItem)
tExist = SHARED.project.index.checkThese(tBits, self._docHandle)
for sTag, sPos, sExist in zip(reversed(tBits), reversed(tPos), reversed(tExist)):
if cPos >= sPos:
# The cursor is between the start of two tags
+17 -17
View File
@@ -279,23 +279,23 @@ class GuiDocHighlighter(QSyntaxHighlighter):
if text.startswith("@"): # Keywords and commands
self.setCurrentBlockState(self.BLOCK_META)
if self._tItem:
pIndex = SHARED.project.index
isValid, bits, pos = pIndex.scanThis(text)
isGood = pIndex.checkThese(bits, self._tItem)
if isValid:
for n, bit in enumerate(bits):
xPos = pos[n]
xLen = len(bit)
if isGood[n]:
if n == 0:
self.setFormat(xPos, xLen, self._hStyles["keyword"])
else:
self.setFormat(xPos, xLen, self._hStyles["value"])
else:
kwFmt = self.format(xPos)
kwFmt.merge(self._hStyles["codeinval"])
self.setFormat(xPos, xLen, kwFmt)
index = SHARED.project.index
isValid, bits, pos = index.scanThis(text)
isGood = index.checkThese(bits, self._tHandle)
if isValid:
for n, bit in enumerate(bits):
xPos = pos[n]
xLen = len(bit)
if not isGood[n]:
self.setFormat(xPos, xLen, self._hStyles["codeinval"])
elif n == 0:
self.setFormat(xPos, xLen, self._hStyles["keyword"])
else:
one, two = index.parseValue(bit)
self.setFormat(xPos, len(one), self._hStyles["value"])
if two:
yPos = xPos + len(bit) - len(two)
self.setFormat(yPos, len(two), self._hStyles["optional"])
# We never want to run the spell checker on keyword/values,
# so we force a return here
+17 -26
View File
@@ -461,15 +461,16 @@ class GuiDocViewer(QTextBrowser):
def _makeStyleSheet(self) -> None:
"""Generate an appropriate style sheet for the document viewer,
based on the current syntax highlighter theme,
based on the current syntax highlighter theme.
"""
colText = SHARED.theme.colText
colHead = SHARED.theme.colHead
colVal = SHARED.theme.colVal
colVals = SHARED.theme.colVal
colEmph = SHARED.theme.colEmph
colKey = SHARED.theme.colKey
colHidden = SHARED.theme.colHidden
colMod = SHARED.theme.colMod
colKeys = SHARED.theme.colKey
colHide = SHARED.theme.colHidden
colMods = SHARED.theme.colMod
colOpts = SHARED.theme.colOpt
styleSheet = (
"body {{"
" color: rgb({tColR}, {tColG}, {tColB});"
@@ -486,6 +487,9 @@ class GuiDocViewer(QTextBrowser):
".tags {{"
" color: rgb({kColR}, {kColG}, {kColB});"
"}}\n"
".optional {{"
" color: rgb({oColR}, {oColG}, {oColB});"
"}}\n"
".comment {{"
" color: rgb({cColR}, {cColG}, {cColB});"
"}}\n"
@@ -496,27 +500,14 @@ class GuiDocViewer(QTextBrowser):
" text-align: center;"
"}}\n"
).format(
tColR=colText.red(),
tColG=colText.green(),
tColB=colText.blue(),
hColR=colHead.red(),
hColG=colHead.green(),
hColB=colHead.blue(),
aColR=colVal.red(),
aColG=colVal.green(),
aColB=colVal.blue(),
eColR=colEmph.red(),
eColG=colEmph.green(),
eColB=colEmph.blue(),
kColR=colKey.red(),
kColG=colKey.green(),
kColB=colKey.blue(),
cColR=colHidden.red(),
cColG=colHidden.green(),
cColB=colHidden.blue(),
mColR=colMod.red(),
mColG=colMod.green(),
mColB=colMod.blue(),
tColR=colText.red(), tColG=colText.green(), tColB=colText.blue(),
hColR=colHead.red(), hColG=colHead.green(), hColB=colHead.blue(),
aColR=colVals.red(), aColG=colVals.green(), aColB=colVals.blue(),
eColR=colEmph.red(), eColG=colEmph.green(), eColB=colEmph.blue(),
kColR=colKeys.red(), kColG=colKeys.green(), kColB=colKeys.blue(),
cColR=colHide.red(), cColG=colHide.green(), cColB=colHide.blue(),
mColR=colMods.red(), mColG=colMods.green(), mColB=colMods.blue(),
oColR=colOpts.red(), oColG=colOpts.green(), oColB=colOpts.blue(),
)
self.document().setDefaultStyleSheet(styleSheet)