From cff5f864e46435561b2f2f96adb4616bed6bbe91 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 20 Nov 2025 17:18:45 +1100 Subject: [PATCH] Add 'Close tab' nav item and shortcut. Add extra newline after headings --- CHANGELOG.md | 1 + bouquin/locales/en.json | 1 + bouquin/main_window.py | 13 +++++++++++++ bouquin/markdown_editor.py | 13 +++++++++++++ 4 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 378e13b..f9290ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Allow time log entries to be edited directly in their table cells * Miscellaneous bug fixes for editing (list cursor positions/text selectivity, alarm removing newline) + * Add 'Close tab' nav item and shortcut # 0.4 diff --git a/bouquin/locales/en.json b/bouquin/locales/en.json index f7a38ea..9b70cfd 100644 --- a/bouquin/locales/en.json +++ b/bouquin/locales/en.json @@ -36,6 +36,7 @@ "behaviour": "Behaviour", "never": "Never", "browse": "Browse", + "close_tab": "Close tab", "previous": "Previous", "previous_day": "Previous day", "next": "Next", diff --git a/bouquin/main_window.py b/bouquin/main_window.py index c2f3d40..b5dab36 100644 --- a/bouquin/main_window.py +++ b/bouquin/main_window.py @@ -260,6 +260,13 @@ class MainWindow(QMainWindow): nav_menu.addAction(act_today) self.addAction(act_today) + act_close_tab = QAction(strings._("close_tab"), self) + act_close_tab.setShortcut("Ctrl+W") + act_close_tab.setShortcutContext(Qt.ApplicationShortcut) + act_close_tab.triggered.connect(self._close_current_tab) + nav_menu.addAction(act_close_tab) + self.addAction(act_close_tab) + act_find = QAction(strings._("find_on_page"), self) act_find.setShortcut(QKeySequence.Find) act_find.triggered.connect(self.findBar.show_bar) @@ -520,6 +527,12 @@ class MainWindow(QMainWindow): self.tab_widget.removeTab(index) + def _close_current_tab(self): + """Close the currently active tab via shortcuts (Ctrl+W).""" + idx = self.tab_widget.currentIndex() + if idx >= 0: + self._close_tab(idx) + def _on_tab_changed(self, index: int): """Handle tab change - reconnect toolbar and sync UI.""" if index < 0: diff --git a/bouquin/markdown_editor.py b/bouquin/markdown_editor.py index 6436ec8..7fea40c 100644 --- a/bouquin/markdown_editor.py +++ b/bouquin/markdown_editor.py @@ -753,6 +753,19 @@ class MarkdownEditor(QTextEdit): super().keyPressEvent(event) return + # Auto-insert an extra blank line after headings (#, ##, ###) + # when pressing Enter at the end of the line. + if re.match(r"^#{1,3}\s+", stripped) and pos_in_block >= len(line_text): + cursor.beginEditBlock() + # First blank line: visual separator between heading and body + cursor.insertBlock() + # Second blank line: where body text will start (caret ends here) + cursor.insertBlock() + cursor.endEditBlock() + + self.setTextCursor(cursor) + return + # Check for list continuation list_type, prefix = self._detect_list_type(current_line)