From 9c1bdef9adfc866a7c72e6d7d3799bcdfa4ccd6c Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 10 Feb 2024 15:40:30 +0100 Subject: [PATCH] Add block format that completely ignores a line of text in the tokenizer --- docs/source/usage_shortcuts.rst | 1 + novelwriter/core/tokenizer.py | 4 ++++ novelwriter/enum.py | 35 +++++++++++++++++---------------- novelwriter/gui/doceditor.py | 17 ++++++++++------ novelwriter/gui/mainmenu.py | 7 +++++++ 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/docs/source/usage_shortcuts.rst b/docs/source/usage_shortcuts.rst index 8c9fb8cb..3dc15049 100644 --- a/docs/source/usage_shortcuts.rst +++ b/docs/source/usage_shortcuts.rst @@ -107,6 +107,7 @@ Text Formatting Shortcuts ":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+Shift+/`", "Remove block formatting for block under cursor" + ":kbd:`Ctrl+Shift+D`", "Toggle block format as ignored text" Other Editor Shortcuts diff --git a/novelwriter/core/tokenizer.py b/novelwriter/core/tokenizer.py index 7f0bb7d2..90f771f8 100644 --- a/novelwriter/core/tokenizer.py +++ b/novelwriter/core/tokenizer.py @@ -467,6 +467,10 @@ class Tokenizer(ABC): continue if aLine[0] == "%": + if aLine[1] == "~": + # Completely ignore the paragraph + continue + cStyle, cText, _ = processComment(aLine) if cStyle == nwComment.SYNOPSIS: self._tokens.append(( diff --git a/novelwriter/enum.py b/novelwriter/enum.py index bbfed775..aa9106e3 100644 --- a/novelwriter/enum.py +++ b/novelwriter/enum.py @@ -108,23 +108,24 @@ class nwDocAction(Enum): BLOCK_H3 = 15 BLOCK_H4 = 16 BLOCK_COM = 17 - BLOCK_TXT = 18 - BLOCK_TTL = 19 - BLOCK_UNN = 20 - REPL_SNG = 21 - REPL_DBL = 22 - RM_BREAKS = 23 - ALIGN_L = 24 - ALIGN_C = 25 - ALIGN_R = 26 - INDENT_L = 27 - INDENT_R = 28 - SC_ITALIC = 29 - SC_BOLD = 30 - SC_STRIKE = 31 - SC_ULINE = 32 - SC_SUP = 33 - SC_SUB = 34 + BLOCK_IGN = 18 + BLOCK_TXT = 19 + BLOCK_TTL = 20 + BLOCK_UNN = 21 + REPL_SNG = 22 + REPL_DBL = 23 + RM_BREAKS = 24 + ALIGN_L = 25 + ALIGN_C = 26 + ALIGN_R = 27 + INDENT_L = 28 + INDENT_R = 29 + SC_ITALIC = 30 + SC_BOLD = 31 + SC_STRIKE = 32 + SC_ULINE = 33 + SC_SUP = 34 + SC_SUB = 35 # END Enum nwDocAction diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index b3223aab..2ad62e27 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -737,6 +737,8 @@ class GuiDocEditor(QPlainTextEdit): self._formatBlock(nwDocAction.BLOCK_H4) elif action == nwDocAction.BLOCK_COM: self._formatBlock(nwDocAction.BLOCK_COM) + elif action == nwDocAction.BLOCK_IGN: + self._formatBlock(nwDocAction.BLOCK_IGN) elif action == nwDocAction.BLOCK_TXT: self._formatBlock(nwDocAction.BLOCK_TXT) elif action == nwDocAction.BLOCK_TTL: @@ -1648,14 +1650,14 @@ class GuiDocEditor(QPlainTextEdit): if setText.startswith("@"): logger.error("Cannot apply block format to keyword/value line") return False - elif setText.startswith("% "): - newText = setText[2:] - cOffset = 2 - if action == nwDocAction.BLOCK_COM: + elif setText.startswith("%~"): + newText = setText[2:].lstrip() + cOffset = len(setText) - len(newText) + if action == nwDocAction.BLOCK_IGN: action = nwDocAction.BLOCK_TXT elif setText.startswith("%"): - newText = setText[1:] - cOffset = 1 + newText = setText[1:].lstrip() + cOffset = len(setText) - len(newText) if action == nwDocAction.BLOCK_COM: action = nwDocAction.BLOCK_TXT elif setText.startswith("# "): @@ -1706,6 +1708,9 @@ class GuiDocEditor(QPlainTextEdit): if action == nwDocAction.BLOCK_COM: setText = "% "+newText cOffset -= 2 + elif action == nwDocAction.BLOCK_IGN: + setText = "%~ "+newText + cOffset -= 3 elif action == nwDocAction.BLOCK_H1: setText = "# "+newText cOffset -= 2 diff --git a/novelwriter/gui/mainmenu.py b/novelwriter/gui/mainmenu.py index 279fce07..6f91bd05 100644 --- a/novelwriter/gui/mainmenu.py +++ b/novelwriter/gui/mainmenu.py @@ -781,6 +781,13 @@ class GuiMainMenu(QMenuBar): 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 self.aFmtNoFormat = self.fmtMenu.addAction(self.tr("Remove Block Format")) self.aFmtNoFormat.setShortcuts(["Ctrl+0", "Ctrl+Shift+/"])