Indent tabs by 4 spaces in code block editor dialog

This commit is contained in:
Miguel Jacq 2025-12-03 17:27:15 +11:00
parent b06f213522
commit 3d0f4a7787
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
2 changed files with 13 additions and 0 deletions

View file

@ -4,6 +4,7 @@
* Add 'Created at' to time log table. * 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) * 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 * 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 # 0.6.1

View file

@ -40,9 +40,21 @@ class CodeEditorWithLineNumbers(QPlainTextEdit):
self.cursorPositionChanged.connect(self._line_number_area.update) self.cursorPositionChanged.connect(self._line_number_area.update)
self._update_line_number_area_width() self._update_line_number_area_width()
self._update_tab_stop_width()
# ---- layout / sizing ------------------------------------------------- # ---- 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: def line_number_area_width(self) -> int:
# Enough digits for large-ish code blocks. # Enough digits for large-ish code blocks.
digits = max(2, len(str(max(1, self.blockCount())))) digits = max(2, len(str(max(1, self.blockCount()))))