Add 'Close tab' nav item and shortcut. Add extra newline after headings
All checks were successful
CI / test (push) Successful in 3m57s
Lint / test (push) Successful in 28s
Trivy / test (push) Successful in 20s

This commit is contained in:
Miguel Jacq 2025-11-20 17:18:45 +11:00
parent 243980e006
commit cff5f864e4
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
4 changed files with 28 additions and 0 deletions

View file

@ -36,6 +36,7 @@
"behaviour": "Behaviour",
"never": "Never",
"browse": "Browse",
"close_tab": "Close tab",
"previous": "Previous",
"previous_day": "Previous day",
"next": "Next",

View file

@ -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:

View file

@ -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)