From 3d0f4a77876f62da2a9b3fcbff5697053bdc8d60 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 3 Dec 2025 17:27:15 +1100 Subject: [PATCH] Indent tabs by 4 spaces in code block editor dialog --- CHANGELOG.md | 1 + bouquin/code_block_editor_dialog.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a0c2b7..3a6a1b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Add 'Created at' to time log table. * Show total hours for the day in the time log table (not just in the widget in sidebar) * Pomodoro timer is now in the sidebar when toggled on, rather than as a separate dialog, so it stays out of the way + * Indent tabs by 4 spaces in code block editor dialog # 0.6.1 diff --git a/bouquin/code_block_editor_dialog.py b/bouquin/code_block_editor_dialog.py index af1c99f..59162c0 100644 --- a/bouquin/code_block_editor_dialog.py +++ b/bouquin/code_block_editor_dialog.py @@ -40,9 +40,21 @@ class CodeEditorWithLineNumbers(QPlainTextEdit): self.cursorPositionChanged.connect(self._line_number_area.update) self._update_line_number_area_width() + self._update_tab_stop_width() # ---- layout / sizing ------------------------------------------------- + def setFont(self, font: QFont) -> None: # type: ignore[override] + """Ensure tab width stays at 4 spaces when the font changes.""" + super().setFont(font) + self._update_tab_stop_width() + + def _update_tab_stop_width(self) -> None: + """Set tab width to 4 spaces.""" + metrics = QFontMetrics(self.font()) + # Tab width = width of 4 space characters + self.setTabStopDistance(metrics.horizontalAdvance(" ") * 4) + def line_number_area_width(self) -> int: # Enough digits for large-ish code blocks. digits = max(2, len(str(max(1, self.blockCount()))))