From 5adb2f9f977b4816d64b42c562d429f2834f2cc6 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Fri, 10 May 2019 19:56:10 +0200 Subject: [PATCH] Remove the 'hack' to get a word under cursor position as we can just use self.cursorForPosition() --- nw/gui/doceditor.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 61303a2f..cd03c712 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -155,25 +155,13 @@ class GuiDocEditor(QTextEdit): QTextEdit.keyPressEvent(self, keyEvent) return - def mousePressEvent(self, theEvent): - """Capture right click events and rewrite them to left button event. This moves the cursor - to the location of the pointer. Needed to select the word under the right click. - Adapted from: https://nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check - """ - if theEvent.button() == Qt.RightButton: - theEvent = QMouseEvent( - QEvent.MouseButtonPress, theEvent.pos(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier - ) - QTextEdit.mousePressEvent(self, theEvent) - return - def contextMenuEvent(self, theEvent): """Intercept the context menu and insert spelling suggestions, if any. Uses the custom QAction class SpellAction from the same example code. Adapted from: https://nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check """ - mnuSpell = self.createStandardContextMenu() - theCursor = self.textCursor() + mnuSpell = self.createStandardContextMenu(theEvent.pos()) + theCursor = self.cursorForPosition(theEvent.pos()) theCursor.select(QTextCursor.WordUnderCursor) self.setTextCursor(theCursor)