From e160827708b047185d2508443c81977e71c7d56f Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Fri, 28 Nov 2025 14:30:21 +1100 Subject: [PATCH] Prevent double-click of checkbox leading to selecting/highlighting it --- CHANGELOG.md | 1 + bouquin/markdown_editor.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d9de02..167d93f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Use DejaVu Sans font for regular text instead of heavier Noto - might help with the freeze issues. * Change History icon (again) * Make it easier to check on or off the checkbox by adding some buffer (instead of having to precisely click inside it) + * Prevent double-click of checkbox leading to selecting/highlighting it # 0.5.2 diff --git a/bouquin/markdown_editor.py b/bouquin/markdown_editor.py index b9a8aff..ab1ee1b 100644 --- a/bouquin/markdown_editor.py +++ b/bouquin/markdown_editor.py @@ -9,6 +9,7 @@ from PySide6.QtGui import ( QFontDatabase, QFontMetrics, QImage, + QMouseEvent, QTextCharFormat, QTextCursor, QTextDocument, @@ -88,6 +89,9 @@ class MarkdownEditor(QTextEdit): # Track if we're currently updating text programmatically self._updating = False + # Help avoid double-click selecting of checkbox + self._suppress_next_checkbox_double_click = False + # Guard to avoid recursive selection tweaks self._adjusting_selection = False @@ -919,6 +923,9 @@ class MarkdownEditor(QTextEdit): def mousePressEvent(self, event): """Toggle a checkbox only when the click lands on its icon.""" + # default: don't suppress any upcoming double-click + self._suppress_next_checkbox_double_click = False + if event.button() == Qt.LeftButton: pt = event.pos() @@ -984,6 +991,9 @@ class MarkdownEditor(QTextEdit): ) edit.insertText(f"{new_icon} ") edit.endEditBlock() + + # if a double-click comes next, ignore it + self._suppress_next_checkbox_double_click = True return # handled # advance past this token @@ -994,6 +1004,17 @@ class MarkdownEditor(QTextEdit): # Default handling for anything else super().mousePressEvent(event) + def mouseDoubleClickEvent(self, event: QMouseEvent) -> None: + # If the previous press toggled a checkbox, swallow this double-click + # so the base class does NOT turn it into a selection. + if getattr(self, "_suppress_next_checkbox_double_click", False): + self._suppress_next_checkbox_double_click = False + event.accept() + return + + # Otherwise, let normal double-click behaviour happen + super().mouseDoubleClickEvent(event) + # ------------------------ Toolbar action handlers ------------------------ def apply_weight(self):