mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit book: Fix double clicking to select a word also selecting smart quotes surrounding the word
This commit is contained in:
parent
b7db7cf446
commit
7431c7fe85
@ -14,7 +14,7 @@ from qt.core import (
|
|||||||
QDialogButtonBox, QEvent, QFormLayout, QFrame, QGridLayout, QGroupBox,
|
QDialogButtonBox, QEvent, QFormLayout, QFrame, QGridLayout, QGroupBox,
|
||||||
QHBoxLayout, QIcon, QItemSelectionModel, QLabel, QLineEdit, QListView, QMimeData,
|
QHBoxLayout, QIcon, QItemSelectionModel, QLabel, QLineEdit, QListView, QMimeData,
|
||||||
QModelIndex, QPainter, QPalette, QPixmap, QPlainTextEdit, QPoint, QRect, QSize,
|
QModelIndex, QPainter, QPalette, QPixmap, QPlainTextEdit, QPoint, QRect, QSize,
|
||||||
QSizePolicy, QSplitter, QStaticText, QStyle, QStyledItemDelegate, Qt,
|
QSizePolicy, QSplitter, QStaticText, QStyle, QStyledItemDelegate, Qt, QTextCursor,
|
||||||
QTextDocument, QTextOption, QToolButton, QVBoxLayout, QWidget, pyqtSignal
|
QTextDocument, QTextOption, QToolButton, QVBoxLayout, QWidget, pyqtSignal
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1287,6 +1287,31 @@ class PlainTextEdit(QPlainTextEdit): # {{{
|
|||||||
return True
|
return True
|
||||||
return QPlainTextEdit.event(self, ev)
|
return QPlainTextEdit.event(self, ev)
|
||||||
|
|
||||||
|
def mouseDoubleClickEvent(self, ev):
|
||||||
|
super().mouseDoubleClickEvent(ev)
|
||||||
|
c = self.textCursor()
|
||||||
|
# Workaround for QTextCursor considering smart quotes as word
|
||||||
|
# characters https://bugreports.qt.io/browse/QTBUG-101372
|
||||||
|
changed = False
|
||||||
|
while True:
|
||||||
|
q = c.selectedText()
|
||||||
|
if not q:
|
||||||
|
break
|
||||||
|
left = min(c.anchor(), c.position())
|
||||||
|
right = max(c.anchor(), c.position())
|
||||||
|
if q[0] in '“‘':
|
||||||
|
changed = True
|
||||||
|
c.setPosition(left + 1)
|
||||||
|
c.setPosition(right, QTextCursor.MoveMode.KeepAnchor)
|
||||||
|
elif q[-1] in '’”':
|
||||||
|
changed = True
|
||||||
|
c.setPosition(left)
|
||||||
|
c.setPosition(right - 1, QTextCursor.MoveMode.KeepAnchor)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
if changed:
|
||||||
|
self.setTextCursor(c)
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user