Add block format that completely ignores a line of text in the tokenizer

This commit is contained in:
Veronica Berglyd Olsen
2024-02-10 15:40:30 +01:00
parent 467772c489
commit 9c1bdef9ad
5 changed files with 41 additions and 23 deletions
+1
View File
@@ -107,6 +107,7 @@ Text Formatting Shortcuts
":kbd:`Ctrl+D`", "Strike through selected text, or word under cursor" ":kbd:`Ctrl+D`", "Strike through selected text, or word under cursor"
":kbd:`Ctrl+I`", "Format selected text, or word under cursor, with emphasis (italic)" ":kbd:`Ctrl+I`", "Format selected text, or word under cursor, with emphasis (italic)"
":kbd:`Ctrl+Shift+/`", "Remove block formatting for block under cursor" ":kbd:`Ctrl+Shift+/`", "Remove block formatting for block under cursor"
":kbd:`Ctrl+Shift+D`", "Toggle block format as ignored text"
Other Editor Shortcuts Other Editor Shortcuts
+4
View File
@@ -467,6 +467,10 @@ class Tokenizer(ABC):
continue continue
if aLine[0] == "%": if aLine[0] == "%":
if aLine[1] == "~":
# Completely ignore the paragraph
continue
cStyle, cText, _ = processComment(aLine) cStyle, cText, _ = processComment(aLine)
if cStyle == nwComment.SYNOPSIS: if cStyle == nwComment.SYNOPSIS:
self._tokens.append(( self._tokens.append((
+18 -17
View File
@@ -108,23 +108,24 @@ class nwDocAction(Enum):
BLOCK_H3 = 15 BLOCK_H3 = 15
BLOCK_H4 = 16 BLOCK_H4 = 16
BLOCK_COM = 17 BLOCK_COM = 17
BLOCK_TXT = 18 BLOCK_IGN = 18
BLOCK_TTL = 19 BLOCK_TXT = 19
BLOCK_UNN = 20 BLOCK_TTL = 20
REPL_SNG = 21 BLOCK_UNN = 21
REPL_DBL = 22 REPL_SNG = 22
RM_BREAKS = 23 REPL_DBL = 23
ALIGN_L = 24 RM_BREAKS = 24
ALIGN_C = 25 ALIGN_L = 25
ALIGN_R = 26 ALIGN_C = 26
INDENT_L = 27 ALIGN_R = 27
INDENT_R = 28 INDENT_L = 28
SC_ITALIC = 29 INDENT_R = 29
SC_BOLD = 30 SC_ITALIC = 30
SC_STRIKE = 31 SC_BOLD = 31
SC_ULINE = 32 SC_STRIKE = 32
SC_SUP = 33 SC_ULINE = 33
SC_SUB = 34 SC_SUP = 34
SC_SUB = 35
# END Enum nwDocAction # END Enum nwDocAction
+11 -6
View File
@@ -737,6 +737,8 @@ class GuiDocEditor(QPlainTextEdit):
self._formatBlock(nwDocAction.BLOCK_H4) self._formatBlock(nwDocAction.BLOCK_H4)
elif action == nwDocAction.BLOCK_COM: elif action == nwDocAction.BLOCK_COM:
self._formatBlock(nwDocAction.BLOCK_COM) self._formatBlock(nwDocAction.BLOCK_COM)
elif action == nwDocAction.BLOCK_IGN:
self._formatBlock(nwDocAction.BLOCK_IGN)
elif action == nwDocAction.BLOCK_TXT: elif action == nwDocAction.BLOCK_TXT:
self._formatBlock(nwDocAction.BLOCK_TXT) self._formatBlock(nwDocAction.BLOCK_TXT)
elif action == nwDocAction.BLOCK_TTL: elif action == nwDocAction.BLOCK_TTL:
@@ -1648,14 +1650,14 @@ class GuiDocEditor(QPlainTextEdit):
if setText.startswith("@"): if setText.startswith("@"):
logger.error("Cannot apply block format to keyword/value line") logger.error("Cannot apply block format to keyword/value line")
return False return False
elif setText.startswith("% "): elif setText.startswith("%~"):
newText = setText[2:] newText = setText[2:].lstrip()
cOffset = 2 cOffset = len(setText) - len(newText)
if action == nwDocAction.BLOCK_COM: if action == nwDocAction.BLOCK_IGN:
action = nwDocAction.BLOCK_TXT action = nwDocAction.BLOCK_TXT
elif setText.startswith("%"): elif setText.startswith("%"):
newText = setText[1:] newText = setText[1:].lstrip()
cOffset = 1 cOffset = len(setText) - len(newText)
if action == nwDocAction.BLOCK_COM: if action == nwDocAction.BLOCK_COM:
action = nwDocAction.BLOCK_TXT action = nwDocAction.BLOCK_TXT
elif setText.startswith("# "): elif setText.startswith("# "):
@@ -1706,6 +1708,9 @@ class GuiDocEditor(QPlainTextEdit):
if action == nwDocAction.BLOCK_COM: if action == nwDocAction.BLOCK_COM:
setText = "% "+newText setText = "% "+newText
cOffset -= 2 cOffset -= 2
elif action == nwDocAction.BLOCK_IGN:
setText = "%~ "+newText
cOffset -= 3
elif action == nwDocAction.BLOCK_H1: elif action == nwDocAction.BLOCK_H1:
setText = "# "+newText setText = "# "+newText
cOffset -= 2 cOffset -= 2
+7
View File
@@ -781,6 +781,13 @@ class GuiMainMenu(QMenuBar):
lambda: self.requestDocAction.emit(nwDocAction.BLOCK_COM) lambda: self.requestDocAction.emit(nwDocAction.BLOCK_COM)
) )
# Format > Ignore Text
self.aFmtComment = self.fmtMenu.addAction(self.tr("Toggle Ignore Text"))
self.aFmtComment.setShortcut("Ctrl+Shift+D")
self.aFmtComment.triggered.connect(
lambda: self.requestDocAction.emit(nwDocAction.BLOCK_IGN)
)
# Format > Remove Block Format # Format > Remove Block Format
self.aFmtNoFormat = self.fmtMenu.addAction(self.tr("Remove Block Format")) self.aFmtNoFormat = self.fmtMenu.addAction(self.tr("Remove Block Format"))
self.aFmtNoFormat.setShortcuts(["Ctrl+0", "Ctrl+Shift+/"]) self.aFmtNoFormat.setShortcuts(["Ctrl+0", "Ctrl+Shift+/"])