Improve size of checkboxes. Convert bullet '-' to actual unicode bullets
All checks were successful
CI / test (push) Successful in 3m30s
Lint / test (push) Successful in 27s
Trivy / test (push) Successful in 20s

This commit is contained in:
Miguel Jacq 2025-11-18 18:21:09 +11:00
parent a375be629c
commit 63cf561bfe
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
6 changed files with 431 additions and 11 deletions

View file

@ -53,6 +53,10 @@ class MarkdownEditor(QTextEdit):
self._CHECK_UNCHECKED_STORAGE = "[ ]"
self._CHECK_CHECKED_STORAGE = "[x]"
# Bullet character (Unicode for display, "- " for markdown)
self._BULLET_DISPLAY = ""
self._BULLET_STORAGE = "-"
# Install syntax highlighter
self.highlighter = MarkdownHighlighter(self.document(), theme_manager)
@ -258,6 +262,13 @@ class MarkdownEditor(QTextEdit):
f"{self._CHECK_UNCHECKED_DISPLAY} ", f"- {self._CHECK_UNCHECKED_STORAGE} "
)
# Convert Unicode bullets back to "- " at the start of a line
text = re.sub(
rf"(?m)^(\s*){re.escape(self._BULLET_DISPLAY)}\s+",
rf"\1{self._BULLET_STORAGE} ",
text,
)
return text
def _extract_images_to_markdown(self) -> str:
@ -310,6 +321,14 @@ class MarkdownEditor(QTextEdit):
display_text,
)
# Convert simple markdown bullets ("- ", "* ", "+ ") to Unicode bullets,
# but skip checkbox lines (- [ ] / - [x])
display_text = re.sub(
r"(?m)^([ \t]*)[-*+]\s+(?!\[[ xX]\])",
rf"\1{self._BULLET_DISPLAY} ",
display_text,
)
self._updating = True
try:
self.setPlainText(display_text)
@ -392,7 +411,11 @@ class MarkdownEditor(QTextEdit):
):
return ("checkbox", f"{self._CHECK_UNCHECKED_DISPLAY} ")
# Bullet list
# Bullet list Unicode bullet
if line.startswith(f"{self._BULLET_DISPLAY} "):
return ("bullet", f"{self._BULLET_DISPLAY} ")
# Bullet list - markdown bullet
if re.match(r"^[-*+]\s", line):
match = re.match(r"^([-*+]\s)", line)
return ("bullet", match.group(1))
@ -524,7 +547,10 @@ class MarkdownEditor(QTextEdit):
f"{self._CHECK_UNCHECKED_DISPLAY} "
) or stripped.startswith(f"{self._CHECK_CHECKED_DISPLAY} "):
prefix_len = leading_spaces + 2 # icon + space
# Check for bullet list
# Check for Unicode bullet
elif stripped.startswith(f"{self._BULLET_DISPLAY} "):
prefix_len = leading_spaces + 2 # bullet + space
# Check for markdown bullet list (-, *, +)
elif re.match(r"^[-*+]\s", stripped):
prefix_len = leading_spaces + 2 # marker + space
# Check for numbered list
@ -951,14 +977,19 @@ class MarkdownEditor(QTextEdit):
QTextCursor.MoveOperation.EndOfLine, QTextCursor.MoveMode.KeepAnchor
)
line = cursor.selectedText()
stripped = line.lstrip()
# Check if already a bullet
if line.lstrip().startswith("- ") or line.lstrip().startswith("* "):
# Remove bullet
new_line = re.sub(r"^\s*[-*]\s+", "", line)
# Consider existing markdown markers OR our Unicode bullet as "a bullet"
if (
stripped.startswith(f"{self._BULLET_DISPLAY} ")
or stripped.startswith("- ")
or stripped.startswith("* ")
):
# Remove any of those bullet markers
pattern = rf"^\s*([{re.escape(self._BULLET_DISPLAY)}\-*])\s+"
new_line = re.sub(pattern, "", line)
else:
# Add bullet
new_line = "- " + line.lstrip()
new_line = f"{self._BULLET_DISPLAY} " + stripped
cursor.insertText(new_line)

View file

@ -98,6 +98,20 @@ class MarkdownHighlighter(QSyntaxHighlighter):
self.link_format.setFontUnderline(True)
self.link_format.setAnchor(True)
# Base size from the document/editor font
doc = self.document()
base_font = doc.defaultFont() if doc is not None else QGuiApplication.font()
base_size = base_font.pointSizeF()
if base_size <= 0:
base_size = 10.0 # fallback
# Checkboxes: make them a bit bigger so they stand out
self.checkbox_format = QTextCharFormat()
self.checkbox_format.setFontPointSize(base_size * 1.4)
# Bullets
self.bullet_format = QTextCharFormat()
self.bullet_format.setFontPointSize(base_size * 1.2)
# Markdown syntax (the markers themselves) - make invisible
self.syntax_format = QTextCharFormat()
# Make the markers invisible by setting font size to 0.1 points
@ -262,3 +276,11 @@ class MarkdownHighlighter(QSyntaxHighlighter):
fmt.setAnchorHref(url)
# Overlay link attributes on top of whatever formatting is already there
self._overlay_range(start, end - start, fmt)
# Make checkbox glyphs bigger
for m in re.finditer(r"[☐☑]", text):
self._overlay_range(m.start(), 1, self.checkbox_format)
# (If you add Unicode bullets later…)
for m in re.finditer(r"", text):
self._overlay_range(m.start(), 1, self.bullet_format)

View file

@ -30,7 +30,7 @@ def load_db_config() -> DBConfig:
legacy = s.value("db/path", "", type=str)
if legacy:
path_str = legacy
# Optional: migrate and clean up the old key
# migrate and clean up the old key
s.setValue("db/default_db", legacy)
s.remove("db/path")
path = Path(path_str) if path_str else _default_db_location()