diff --git a/nw/constants/constants.py b/nw/constants/constants.py index 3bfc9125..8e2a7d66 100644 --- a/nw/constants/constants.py +++ b/nw/constants/constants.py @@ -245,6 +245,7 @@ class nwUnicode: ## Symbols U_CHECK = "\u2714" # Heavy check mark U_MULT = "\u2715" # Multiplication x + U_BULL = "\u2022" # List bullet ## Arrows U_UTRI = "\u25b2" # Up-pointing triangle @@ -294,6 +295,7 @@ class nwUnicode: ## Symbols H_CHECK = "✔" H_MULT = "✕" + H_BULL = "•" ## Arrows H_UTRI = "▲" diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index c949ad85..5ebdf19e 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -732,14 +732,14 @@ class GuiDocEditor(QTextEdit): """Triggered by right click to open the context menu. Also triggered by the Ctrl+. shortcut. """ - if not self.spellCheck: - return - userCursor = self.textCursor() userSelection = userCursor.hasSelection() mnuContext = QMenu() + # Cut, Copy and Paste + # =================== + if userSelection: mnuCut = QAction("Cut", mnuContext) mnuCut.triggered.connect(lambda: self.docAction(nwDocAction.CUT)) @@ -753,11 +753,37 @@ class GuiDocEditor(QTextEdit): mnuPaste.triggered.connect(lambda: self.docAction(nwDocAction.PASTE)) mnuContext.addAction(mnuPaste) - # Check if we should look up the spelling - posCursor = self.cursorForPosition(thePos) - posCursor.select(QTextCursor.WordUnderCursor) - theWord = posCursor.selectedText().strip().strip(self.nonWord) - spellCheck = theWord != "" + mnuContext.addSeparator() + + # Selections + # ========== + + mnuSelAll = QAction("Select All", mnuContext) + mnuSelAll.triggered.connect(lambda: self.docAction(nwDocAction.SEL_ALL)) + mnuContext.addAction(mnuSelAll) + + mnuSelWord = QAction("Select Word", mnuContext) + mnuSelWord.triggered.connect( + lambda: self._makePosSelection(QTextCursor.WordUnderCursor, thePos) + ) + mnuContext.addAction(mnuSelWord) + + mnuSelPara = QAction("Select Paragraph", mnuContext) + mnuSelPara.triggered.connect( + lambda: self._makePosSelection(QTextCursor.BlockUnderCursor, thePos) + ) + mnuContext.addAction(mnuSelPara) + + # Spell Checking + # ============== + + spellCheck = self.spellCheck + + if spellCheck: + posCursor = self.cursorForPosition(thePos) + posCursor.select(QTextCursor.WordUnderCursor) + theWord = posCursor.selectedText().strip().strip(self.nonWord) + spellCheck &= theWord != "" if spellCheck: logger.verbose("Looking up '%s' in the dictionary" % theWord) @@ -771,7 +797,7 @@ class GuiDocEditor(QTextEdit): theSuggest = self.theDict.suggestWords(theWord) if len(theSuggest) > 0: for aWord in theSuggest: - mnuWord = QAction(aWord, mnuContext) + mnuWord = QAction("%s %s" % (nwUnicode.U_ENDASH, aWord), mnuContext) mnuWord.triggered.connect( lambda thePos, aWord=aWord : self._correctWord(posCursor, aWord) ) @@ -785,6 +811,7 @@ class GuiDocEditor(QTextEdit): mnuHead = QAction("No Suggestions", mnuContext) mnuContext.addAction(mnuHead) + # Open the context menu mnuContext.exec_(self.viewport().mapToGlobal(thePos)) return @@ -1215,7 +1242,7 @@ class GuiDocEditor(QTextEdit): return def _makeSelection(self, selMode): - """Wrapper function to select a word based on a selection mode. + """Wrapper function to select text based on a selection mode. """ theCursor = self.textCursor() theCursor.clearSelection() @@ -1235,6 +1262,15 @@ class GuiDocEditor(QTextEdit): return + def _makePosSelection(self, selMode, thePos): + """Wrapper function to select text based on selection mode, but + first move cursor to given position. + """ + theCursor = self.cursorForPosition(thePos) + self.setTextCursor(theCursor) + self._makeSelection(selMode) + return + def _beginSearch(self): """Sets the selected text as the search text for the search bar. """