Merge pull request #367 from vkbo/insert_quotes

Insert Quotes in Text
This commit is contained in:
Veronica K. Berglyd Olsen
2020-07-26 14:49:32 +02:00
committed by GitHub
7 changed files with 73 additions and 21 deletions
+5
View File
@@ -183,6 +183,7 @@ These are as following:
On macOS, replace :kbd:`Ctrl` with :kbd:`Cmd`.
A set of insert features are also available through shortcuts, but they require a double combination of shortcuts.
The insert feature is activated with :kbd:`Ctrl-K`, followed by a key for the inserted character or punctuation.
.. csv-table:: Keyboard Shortcuts
:header: "Shortcut", "Description"
@@ -191,6 +192,10 @@ A set of insert features are also available through shortcuts, but they require
":kbd:`Ctrl-K, -`", "Insert a short dash (en dash)."
":kbd:`Ctrl-K, _`", "Insert a long dash (em dash)."
":kbd:`Ctrl-K, .`", "Insert ellipsis."
":kbd:`Ctrl-K, 1`", "Insert left single quote."
":kbd:`Ctrl-K, 2`", "Insert right single quote."
":kbd:`Ctrl-K, 3`", "Insert left double quote."
":kbd:`Ctrl-K, 4`", "Insert right double quote."
":kbd:`Ctrl-K, Return`", "Insert a hard line break."
":kbd:`Ctrl-K, Space`", "Insert a non-breaking space."
":kbd:`Ctrl-K, Shift-Space`", "Insert a thin space."
+1 -3
View File
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
from nw.constants.iso import isoLanguage, isoCountry
from nw.constants.constants import (
nwConst, nwRegEx, nwFiles, nwKeyWords, nwLabels, nwQuotes, nwUnicode,
nwInsertSymbols
nwConst, nwRegEx, nwFiles, nwKeyWords, nwLabels, nwQuotes, nwUnicode
)
from nw.constants.enum import (
nwAlert, nwDocAction, nwItemClass, nwItemLayout, nwItemType, nwOutline,
@@ -19,7 +18,6 @@ __all__ = [
"nwLabels",
"nwQuotes",
"nwUnicode",
"nwInsertSymbols",
"nwAlert",
"nwDocAction",
"nwItemClass",
-15
View File
@@ -299,18 +299,3 @@ class nwUnicode:
H_LTRIS = "◂"
# END Class nwUnicode
class nwInsertSymbols():
SYMBOLS = {
nwDocInsert.NO_INSERT : "",
nwDocInsert.HARD_BREAK : " \n",
nwDocInsert.NB_SPACE : nwUnicode.U_NBSP,
nwDocInsert.THIN_SPACE : nwUnicode.U_THNSP,
nwDocInsert.THIN_NB_SPACE : nwUnicode.U_THNBSP,
nwDocInsert.SHORT_DASH : nwUnicode.U_ENDASH,
nwDocInsert.LONG_DASH : nwUnicode.U_EMDASH,
nwDocInsert.ELLIPSIS : nwUnicode.U_HELLIP,
}
# END Enum nwDocInsert
+4
View File
@@ -107,6 +107,10 @@ class nwDocInsert(Enum):
SHORT_DASH = 5
LONG_DASH = 6
ELLIPSIS = 7
QUOTE_LS = 8
QUOTE_RS = 9
QUOTE_LD = 10
QUOTE_RD = 11
# END Enum nwDocInsert
+28 -3
View File
@@ -52,7 +52,7 @@ from nw.core import NWDoc, NWSpellSimple, countWords
from nw.gui.dochighlight import GuiDocHighlighter
from nw.common import transferCase
from nw.constants import (
nwAlert, nwUnicode, nwDocAction, nwDocInsert, nwInsertSymbols, nwItemClass
nwAlert, nwUnicode, nwDocAction, nwDocInsert, nwItemClass
)
logger = logging.getLogger(__name__)
@@ -590,8 +590,33 @@ class GuiDocEditor(QTextEdit):
"""
if isinstance(theInsert, str):
theText = theInsert
elif theInsert in nwInsertSymbols.SYMBOLS:
theText = nwInsertSymbols.SYMBOLS[theInsert]
elif theInsert in nwDocInsert:
if theInsert == nwDocInsert.NO_INSERT:
theText = "",
elif theInsert == nwDocInsert.HARD_BREAK:
theText = " \n",
elif theInsert == nwDocInsert.NB_SPACE:
theText = nwUnicode.U_NBSP,
elif theInsert == nwDocInsert.THIN_SPACE:
theText = nwUnicode.U_THNSP,
elif theInsert == nwDocInsert.THIN_NB_SPACE:
theText = nwUnicode.U_THNBSP,
elif theInsert == nwDocInsert.SHORT_DASH:
theText = nwUnicode.U_ENDASH,
elif theInsert == nwDocInsert.LONG_DASH:
theText = nwUnicode.U_EMDASH,
elif theInsert == nwDocInsert.ELLIPSIS:
theText = nwUnicode.U_HELLIP,
elif theInsert == nwDocInsert.QUOTE_LS:
theText = self.typSQOpen
elif theInsert == nwDocInsert.QUOTE_RS:
theText = self.typSQClose
elif theInsert == nwDocInsert.QUOTE_LD:
theText = self.typDQOpen
elif theInsert == nwDocInsert.QUOTE_RD:
theText = self.typDQClose
else:
return False
else:
return False
theCursor = self.textCursor()
+31
View File
@@ -485,6 +485,37 @@ class GuiMainMenu(QMenuBar):
# Insert > Separator
self.insertMenu.addSeparator()
# Insert > Left Single Quote
self.aInsQuoteLS = QAction("Left Single Quote", self)
self.aInsQuoteLS.setStatusTip("Insert left single quote")
self.aInsQuoteLS.setShortcut("Ctrl+K, 1")
self.aInsQuoteLS.triggered.connect(lambda: self._docInsert(nwDocInsert.QUOTE_LS))
self.insertMenu.addAction(self.aInsQuoteLS)
# Insert > Right Single Quote
self.aInsQuoteRS = QAction("Right Single Quote", self)
self.aInsQuoteRS.setStatusTip("Insert right single quote")
self.aInsQuoteRS.setShortcut("Ctrl+K, 2")
self.aInsQuoteRS.triggered.connect(lambda: self._docInsert(nwDocInsert.QUOTE_RS))
self.insertMenu.addAction(self.aInsQuoteRS)
# Insert > Left Double Quote
self.aInsQuoteLD = QAction("Left Double Quote", self)
self.aInsQuoteLD.setStatusTip("Insert left double quote")
self.aInsQuoteLD.setShortcut("Ctrl+K, 3")
self.aInsQuoteLD.triggered.connect(lambda: self._docInsert(nwDocInsert.QUOTE_LD))
self.insertMenu.addAction(self.aInsQuoteLD)
# Insert > Right Double Quote
self.aInsQuoteRD = QAction("Right Double Quote", self)
self.aInsQuoteRD.setStatusTip("Insert right double quote")
self.aInsQuoteRD.setShortcut("Ctrl+K, 4")
self.aInsQuoteRD.triggered.connect(lambda: self._docInsert(nwDocInsert.QUOTE_RD))
self.insertMenu.addAction(self.aInsQuoteRD)
# Insert > Separator
self.insertMenu.addSeparator()
# Insert > Hard Line Break
self.aInsHardBreak = QAction("Hard Line Break", self)
self.aInsHardBreak.setStatusTip("Insert a hard line break")
+4
View File
@@ -1004,6 +1004,10 @@ class GuiMain(QMainWindow):
self.addAction(self.mainMenu.aInsENDash)
self.addAction(self.mainMenu.aInsEMDash)
self.addAction(self.mainMenu.aInsEllipsis)
self.addAction(self.mainMenu.aInsQuoteLS)
self.addAction(self.mainMenu.aInsQuoteRS)
self.addAction(self.mainMenu.aInsQuoteLD)
self.addAction(self.mainMenu.aInsQuoteRD)
self.addAction(self.mainMenu.aInsHardBreak)
self.addAction(self.mainMenu.aInsNBSpace)
self.addAction(self.mainMenu.aInsThinSpace)