Add button and menu entry for markdown highlight
This commit is contained in:
@@ -101,6 +101,7 @@ Text Formatting Shortcuts
|
|||||||
":kbd:`Ctrl+B`", "Format selected text, or word under cursor, with bold"
|
":kbd:`Ctrl+B`", "Format selected text, or word under cursor, with bold"
|
||||||
":kbd:`Ctrl+D`", "Format selected text, or word under cursor, with strike through"
|
":kbd:`Ctrl+D`", "Format selected text, or word under cursor, with strike through"
|
||||||
":kbd:`Ctrl+I`", "Format selected text, or word under cursor, with italic"
|
":kbd:`Ctrl+I`", "Format selected text, or word under cursor, with italic"
|
||||||
|
":kbd:`Ctrl+M`", "Highlight selected text, or word under cursor"
|
||||||
":kbd:`Ctrl+Shift+/`", "Remove format for block or selected text"
|
":kbd:`Ctrl+Shift+/`", "Remove format for block or selected text"
|
||||||
":kbd:`Ctrl+Shift+D`", "Toggle ignored text format for block or selected text"
|
":kbd:`Ctrl+Shift+D`", "Toggle ignored text format for block or selected text"
|
||||||
|
|
||||||
|
|||||||
+30
-29
@@ -92,35 +92,36 @@ class nwDocAction(Enum):
|
|||||||
MD_ITALIC = 6
|
MD_ITALIC = 6
|
||||||
MD_BOLD = 7
|
MD_BOLD = 7
|
||||||
MD_STRIKE = 8
|
MD_STRIKE = 8
|
||||||
S_QUOTE = 9
|
MD_MARK = 9
|
||||||
D_QUOTE = 10
|
S_QUOTE = 10
|
||||||
SEL_ALL = 11
|
D_QUOTE = 11
|
||||||
SEL_PARA = 12
|
SEL_ALL = 12
|
||||||
BLOCK_H1 = 13
|
SEL_PARA = 13
|
||||||
BLOCK_H2 = 14
|
BLOCK_H1 = 14
|
||||||
BLOCK_H3 = 15
|
BLOCK_H2 = 15
|
||||||
BLOCK_H4 = 16
|
BLOCK_H3 = 16
|
||||||
BLOCK_COM = 17
|
BLOCK_H4 = 17
|
||||||
BLOCK_IGN = 18
|
BLOCK_COM = 18
|
||||||
BLOCK_TXT = 19
|
BLOCK_IGN = 19
|
||||||
BLOCK_TTL = 20
|
BLOCK_TXT = 20
|
||||||
BLOCK_UNN = 21
|
BLOCK_TTL = 21
|
||||||
BLOCK_HSC = 22
|
BLOCK_UNN = 22
|
||||||
REPL_SNG = 23
|
BLOCK_HSC = 23
|
||||||
REPL_DBL = 24
|
REPL_SNG = 24
|
||||||
RM_BREAKS = 25
|
REPL_DBL = 25
|
||||||
ALIGN_L = 26
|
RM_BREAKS = 26
|
||||||
ALIGN_C = 27
|
ALIGN_L = 27
|
||||||
ALIGN_R = 28
|
ALIGN_C = 28
|
||||||
INDENT_L = 29
|
ALIGN_R = 29
|
||||||
INDENT_R = 30
|
INDENT_L = 30
|
||||||
SC_ITALIC = 31
|
INDENT_R = 31
|
||||||
SC_BOLD = 32
|
SC_ITALIC = 32
|
||||||
SC_STRIKE = 33
|
SC_BOLD = 33
|
||||||
SC_ULINE = 34
|
SC_STRIKE = 34
|
||||||
SC_MARK = 35
|
SC_ULINE = 35
|
||||||
SC_SUP = 36
|
SC_MARK = 36
|
||||||
SC_SUB = 37
|
SC_SUP = 37
|
||||||
|
SC_SUB = 38
|
||||||
|
|
||||||
|
|
||||||
class nwDocInsert(Enum):
|
class nwDocInsert(Enum):
|
||||||
|
|||||||
@@ -286,6 +286,7 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
self.docHeader.clearHeader()
|
self.docHeader.clearHeader()
|
||||||
self.docFooter.setHandle(self._docHandle)
|
self.docFooter.setHandle(self._docHandle)
|
||||||
self.docToolBar.setVisible(False)
|
self.docToolBar.setVisible(False)
|
||||||
|
self.setExtraSelections([])
|
||||||
|
|
||||||
self.itemHandleChanged.emit("")
|
self.itemHandleChanged.emit("")
|
||||||
|
|
||||||
@@ -742,6 +743,8 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
self._toggleFormat(2, "*")
|
self._toggleFormat(2, "*")
|
||||||
elif action == nwDocAction.MD_STRIKE:
|
elif action == nwDocAction.MD_STRIKE:
|
||||||
self._toggleFormat(2, "~")
|
self._toggleFormat(2, "~")
|
||||||
|
elif action == nwDocAction.MD_MARK:
|
||||||
|
self._toggleFormat(2, "=")
|
||||||
elif action == nwDocAction.S_QUOTE:
|
elif action == nwDocAction.S_QUOTE:
|
||||||
self._wrapSelection(CONFIG.fmtSQuoteOpen, CONFIG.fmtSQuoteClose)
|
self._wrapSelection(CONFIG.fmtSQuoteOpen, CONFIG.fmtSQuoteClose)
|
||||||
elif action == nwDocAction.D_QUOTE:
|
elif action == nwDocAction.D_QUOTE:
|
||||||
@@ -2418,6 +2421,12 @@ class GuiDocToolBar(QWidget):
|
|||||||
qtLambda(self.requestDocAction.emit, nwDocAction.MD_STRIKE)
|
qtLambda(self.requestDocAction.emit, nwDocAction.MD_STRIKE)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.tbMarkMD = NIconToolButton(self, iSz)
|
||||||
|
self.tbMarkMD.setToolTip(self.tr("Markdown Highlight"))
|
||||||
|
self.tbMarkMD.clicked.connect(
|
||||||
|
qtLambda(self.requestDocAction.emit, nwDocAction.MD_MARK)
|
||||||
|
)
|
||||||
|
|
||||||
self.tbBold = NIconToolButton(self, iSz)
|
self.tbBold = NIconToolButton(self, iSz)
|
||||||
self.tbBold.setToolTip(self.tr("Shortcode Bold"))
|
self.tbBold.setToolTip(self.tr("Shortcode Bold"))
|
||||||
self.tbBold.clicked.connect(
|
self.tbBold.clicked.connect(
|
||||||
@@ -2467,6 +2476,7 @@ class GuiDocToolBar(QWidget):
|
|||||||
self.outerBox.addWidget(self.tbBoldMD)
|
self.outerBox.addWidget(self.tbBoldMD)
|
||||||
self.outerBox.addWidget(self.tbItalicMD)
|
self.outerBox.addWidget(self.tbItalicMD)
|
||||||
self.outerBox.addWidget(self.tbStrikeMD)
|
self.outerBox.addWidget(self.tbStrikeMD)
|
||||||
|
self.outerBox.addWidget(self.tbMarkMD)
|
||||||
self.outerBox.addSpacing(4)
|
self.outerBox.addSpacing(4)
|
||||||
self.outerBox.addWidget(self.tbBold)
|
self.outerBox.addWidget(self.tbBold)
|
||||||
self.outerBox.addWidget(self.tbItalic)
|
self.outerBox.addWidget(self.tbItalic)
|
||||||
@@ -2501,6 +2511,7 @@ class GuiDocToolBar(QWidget):
|
|||||||
self.tbBoldMD.setThemeIcon("fmt_bold", "orange")
|
self.tbBoldMD.setThemeIcon("fmt_bold", "orange")
|
||||||
self.tbItalicMD.setThemeIcon("fmt_italic", "orange")
|
self.tbItalicMD.setThemeIcon("fmt_italic", "orange")
|
||||||
self.tbStrikeMD.setThemeIcon("fmt_strike", "orange")
|
self.tbStrikeMD.setThemeIcon("fmt_strike", "orange")
|
||||||
|
self.tbMarkMD.setThemeIcon("fmt_mark", "orange")
|
||||||
self.tbBold.setThemeIcon("fmt_bold")
|
self.tbBold.setThemeIcon("fmt_bold")
|
||||||
self.tbItalic.setThemeIcon("fmt_italic")
|
self.tbItalic.setThemeIcon("fmt_italic")
|
||||||
self.tbStrike.setThemeIcon("fmt_strike")
|
self.tbStrike.setThemeIcon("fmt_strike")
|
||||||
|
|||||||
@@ -675,6 +675,14 @@ class GuiMainMenu(QMenuBar):
|
|||||||
)
|
)
|
||||||
self.mainGui.addAction(self.aFmtStrike)
|
self.mainGui.addAction(self.aFmtStrike)
|
||||||
|
|
||||||
|
# Format > Highlight
|
||||||
|
self.aFmtMark = qtAddAction(self.fmtMenu, self.tr("Highlight"))
|
||||||
|
self.aFmtMark.setShortcut("Ctrl+M")
|
||||||
|
self.aFmtMark.triggered.connect(
|
||||||
|
lambda: self.requestDocAction.emit(nwDocAction.MD_MARK)
|
||||||
|
)
|
||||||
|
self.mainGui.addAction(self.aFmtStrike)
|
||||||
|
|
||||||
# Edit > Separator
|
# Edit > Separator
|
||||||
self.fmtMenu.addSeparator()
|
self.fmtMenu.addSeparator()
|
||||||
|
|
||||||
|
|||||||
@@ -674,9 +674,16 @@ def testGuiEditor_Actions(qtbot, nwGUI, projPath, ipsumText, mockRnd):
|
|||||||
assert docEditor.docAction(nwDocAction.UNDO) is True
|
assert docEditor.docAction(nwDocAction.UNDO) is True
|
||||||
assert docEditor.getText() == text
|
assert docEditor.getText() == text
|
||||||
|
|
||||||
|
# Mark
|
||||||
|
docEditor.setCursorPosition(50)
|
||||||
|
assert docEditor.docAction(nwDocAction.MD_MARK) is True
|
||||||
|
assert docEditor.getText() == text.replace("consectetur", "==consectetur==")
|
||||||
|
assert docEditor.docAction(nwDocAction.UNDO) is True
|
||||||
|
assert docEditor.getText() == text
|
||||||
|
|
||||||
# Redo
|
# Redo
|
||||||
assert docEditor.docAction(nwDocAction.REDO) is True
|
assert docEditor.docAction(nwDocAction.REDO) is True
|
||||||
assert docEditor.getText() == text.replace("consectetur", "~~consectetur~~")
|
assert docEditor.getText() == text.replace("consectetur", "==consectetur==")
|
||||||
assert docEditor.docAction(nwDocAction.UNDO) is True
|
assert docEditor.docAction(nwDocAction.UNDO) is True
|
||||||
assert docEditor.getText() == text
|
assert docEditor.getText() == text
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user