From 0a64dc525db6a7829f3f5048442068e8f4bb2d65 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 23 Dec 2025 13:42:33 +1100 Subject: [PATCH] Allow setting a code block on a line that already has text (it will start a newline for the codeblock) --- CHANGELOG.md | 1 + bouquin/markdown_editor.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 260aeca..e25d1b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Add .desktop file for Debian * Fix Pomodoro timer rounding so it rounds up to 0.25, but rounds to closest quarter (up or down) for minutes higher than that, instead of always up to next quarter. + * Allow setting a code block on a line that already has text (it will start a newline for the codeblock) # 0.7.5 diff --git a/bouquin/markdown_editor.py b/bouquin/markdown_editor.py index 3d30889..e77dded 100644 --- a/bouquin/markdown_editor.py +++ b/bouquin/markdown_editor.py @@ -919,8 +919,10 @@ class MarkdownEditor(QTextEdit): before = line[:pos_in_block] # "before" currently contains whatever's before the *third* backtick. - # We trigger only when the line is (whitespace + "``") before the caret. - if before.endswith("``") and before.strip() == "``": + # Trigger when the user types a *third consecutive* backtick anywhere on the line. + # (We require the run immediately before the caret to be exactly two backticks, + # so we don't trigger on 4+ backticks.) + if before.endswith("``") and (len(before) < 3 or before[-3] != "`"): doc = self.document() if doc is not None: # Remove the two backticks that were already typed