Skip to content

Commit e757627

Browse files
committed
feat: custom task-list checkbox symbols
Pick the SF Symbol drawn for `- [ ]` / `- [x]` task-list items in Settings → Editor — Square (default), Circle, Diamond, Shield, Triangle, Star, Hexagon, or Heart. Display-only: the underlying markdown stays standard GitHub task-list syntax, so notes stay portable and nothing is rewritten on change. The default (Square) matches the engine's own default, so existing users see no change until they pick a shape. Built on swift-markdown-engine 0.10.1's opt-in TaskCheckboxStyle; a shared editor-config factory keeps the live editor and read-only previews in sync.
1 parent f060e59 commit e757627

10 files changed

Lines changed: 190 additions & 27 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import MarkdownEngine
2+
import MarkdownEngineCodeBlocks
3+
import MarkdownEngineLatex
4+
import SwiftUI
5+
6+
// MARK: - Shared editor configuration
7+
8+
extension MarkdownEditorConfiguration {
9+
/// Shared config for the live editor and the read-only preview/card view.
10+
///
11+
/// Both call sites must stay in sync so previews match the editor. Keeps the
12+
/// text insets, highlight/strikethrough extensions, task-checkbox style, and the
13+
/// image/syntax/latex services in one place. The live editor passes its
14+
/// formatting-request `bus`; the read-only view uses the default (no formatting).
15+
static func makeEdgeMarkConfig(
16+
noteFolder: String,
17+
bus: MarkdownEditorBus = .default,
18+
) -> MarkdownEditorConfiguration {
19+
let preset = AppSettings.shared.taskCheckboxPreset
20+
var config = MarkdownEditorConfiguration.default
21+
config.textInsets = TextInsets(horizontal: 16, vertical: 12)
22+
// Register highlight (==text==) and strikethrough (~~text~~). Opt-in since
23+
// swift-markdown-engine 0.10; without this, the markers render as literal text.
24+
config.extensions = [HighlightExtension(), StrikethroughExtension()]
25+
config.taskCheckbox = TaskCheckboxStyle(
26+
uncheckedSymbolName: preset.uncheckedSymbolName,
27+
checkedSymbolName: preset.checkedSymbolName,
28+
)
29+
config.services = MarkdownEditorServices(
30+
images: EdgeMarkImageProvider(noteFolder: noteFolder),
31+
syntaxHighlighter: HighlighterSwiftBridge(),
32+
latex: SwiftMathBridge(),
33+
bus: bus,
34+
)
35+
return config
36+
}
37+
}

‎EdgeMark/Core/Editor/MarkdownEditorView.swift‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,8 @@ struct MarkdownEditorView: View {
8888
let appSettings = AppSettings.shared
8989
let fontName = Self.resolvedFontFamily(from: appSettings.editorFontName) ?? "SF Pro"
9090

91-
var config = MarkdownEditorConfiguration.default
92-
config.textInsets = TextInsets(horizontal: 16, vertical: 12)
93-
config.spellChecking = SpellCheckingPolicy(
94-
continuousSpellChecking: appSettings.spellCheckingEnabled,
95-
grammarChecking: appSettings.grammarCheckingEnabled,
96-
automaticSpellingCorrection: appSettings.automaticSpellingCorrectionEnabled,
97-
)
98-
// Register the highlight (==text==) and strikethrough (~~text~~) extensions.
99-
// As of swift-markdown-engine 0.10 these are opt-in — unregistered, the
100-
// syntax stays literal text (regressing the v2.5.0 highlight feature and
101-
// the ⇧⌘X strikethrough shortcut restored in 3e3a86c).
102-
config.extensions = [HighlightExtension(), StrikethroughExtension()]
103-
config.services = MarkdownEditorServices(
104-
images: EdgeMarkImageProvider(noteFolder: noteFolder),
105-
syntaxHighlighter: HighlighterSwiftBridge(),
106-
latex: SwiftMathBridge(),
91+
var config = MarkdownEditorConfiguration.makeEdgeMarkConfig(
92+
noteFolder: noteFolder,
10793
bus: MarkdownEditorBus(
10894
// Formatting-request channels — posting these drives the engine's
10995
// didMarkdown* actions (bold/italic/code/link/strikethrough), which in
@@ -117,6 +103,11 @@ struct MarkdownEditorView: View {
117103
findClearHighlights: .editorFindClearHighlights,
118104
),
119105
)
106+
config.spellChecking = SpellCheckingPolicy(
107+
continuousSpellChecking: appSettings.spellCheckingEnabled,
108+
grammarChecking: appSettings.grammarCheckingEnabled,
109+
automaticSpellingCorrection: appSettings.automaticSpellingCorrectionEnabled,
110+
)
120111

121112
return ZStack(alignment: .bottom) {
122113
NativeTextViewWrapper(
@@ -140,6 +131,10 @@ struct MarkdownEditorView: View {
140131
AppSettings.shared.automaticSpellingCorrectionEnabled = policy.automaticSpellingCorrection
141132
},
142133
)
134+
// Force the text view to rebuild (makeNSView) when the task-checkbox style
135+
// changes — the engine's updateNSView doesn't sync taskCheckbox, so only a
136+
// full config re-application picks up the new SF Symbols.
137+
.id(appSettings.taskCheckboxPreset)
143138
.onChange(of: text) { _, newText in
144139
let cursorPos = (NSApp.keyWindow?.firstResponder as? NSTextView)?.selectedRange().location ?? 0
145140
slashHandler.contentDidChange(content: newText, cursorPos: cursorPos)

‎EdgeMark/Core/Editor/ReadOnlyMarkdownView.swift‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,15 @@ struct ReadOnlyMarkdownView: View {
1010
var noteFolder: String = ""
1111

1212
var body: some View {
13-
var config = MarkdownEditorConfiguration.default
14-
config.textInsets = TextInsets(horizontal: 16, vertical: 12)
15-
// Register highlight (==text==) and strikethrough (~~text~~). Opt-in since
16-
// swift-markdown-engine 0.10; without this, trashed/peeked notes render the
17-
// markers as literal text.
18-
config.extensions = [HighlightExtension(), StrikethroughExtension()]
19-
config.services = MarkdownEditorServices(
20-
images: EdgeMarkImageProvider(noteFolder: noteFolder),
21-
syntaxHighlighter: HighlighterSwiftBridge(),
22-
latex: SwiftMathBridge(),
23-
)
13+
// Shared with the live editor so previews match. `.id` rebuilds the view
14+
// (makeNSView) when the task-checkbox style changes — updateNSView doesn't
15+
// sync taskCheckbox, so only a full re-apply picks up the new symbols.
16+
let config = MarkdownEditorConfiguration.makeEdgeMarkConfig(noteFolder: noteFolder)
2417
return NativeTextViewWrapper(
2518
text: .constant(content),
2619
configuration: config,
2720
isEditable: false,
2821
)
22+
.id(AppSettings.shared.taskCheckboxPreset)
2923
}
3024
}

‎EdgeMark/Core/Settings/AppSettings.swift‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,57 @@ final class AppSettings {
6868
}
6969
}
7070

71+
// MARK: - Task checkbox symbols
72+
73+
/// SF Symbol presets drawn for `- [ ]` / `- [x]` task-list items. Display-only —
74+
/// the underlying markdown stays standard GitHub task-list syntax; this only
75+
/// changes which glyph the engine draws over `[ ]` / `[x]`. Backed by
76+
/// `swift-markdown-engine` 0.10.1's `TaskCheckboxStyle`; names that fail to
77+
/// resolve fall back to the stock look at draw time.
78+
enum TaskCheckboxPreset: String, CaseIterable, Codable {
79+
case square
80+
case circle
81+
case diamond
82+
case shield
83+
case triangle
84+
case star
85+
case hexagon
86+
case heart
87+
88+
var uncheckedSymbolName: String {
89+
switch self {
90+
case .square: "square"
91+
case .circle: "circle"
92+
case .diamond: "diamond"
93+
case .shield: "shield"
94+
case .triangle: "triangle"
95+
case .star: "star"
96+
case .hexagon: "hexagon"
97+
case .heart: "heart"
98+
}
99+
}
100+
101+
var checkedSymbolName: String {
102+
switch self {
103+
case .square: "checkmark.square.fill"
104+
case .circle: "checkmark.circle.fill"
105+
case .diamond: "checkmark.diamond.fill"
106+
case .shield: "checkmark.shield.fill"
107+
case .triangle: "triangle.fill"
108+
case .star: "star.fill"
109+
case .hexagon: "hexagon.fill"
110+
case .heart: "heart.fill"
111+
}
112+
}
113+
}
114+
115+
/// Default `.square` matches the engine default — no visual change for existing users.
116+
/// Live re-render of the editor is driven by `@Observable` tracking (the editor
117+
/// reads this via `.id(...)` in its body, so a change recreates the text view).
118+
var taskCheckboxPreset: TaskCheckboxPreset = .square {
119+
didSet { UserDefaults.standard.set(taskCheckboxPreset.rawValue, forKey: "taskCheckboxPreset") }
120+
}
121+
71122
// MARK: - Panel opacity
72123

73124
enum PanelStyle: String, CaseIterable {
@@ -208,6 +259,11 @@ final class AppSettings {
208259
}
209260
let savedSize = UserDefaults.standard.object(forKey: "editorFontSize") as? Double
210261
editorFontSize = savedSize ?? 16
262+
if let raw = UserDefaults.standard.string(forKey: "taskCheckboxPreset"),
263+
let value = TaskCheckboxPreset(rawValue: raw)
264+
{
265+
taskCheckboxPreset = value
266+
}
211267
if let raw = UserDefaults.standard.object(forKey: "spellCheckingEnabled") as? Bool {
212268
spellCheckingEnabled = raw
213269
}

‎EdgeMark/Resources/Locales/de.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@
139139
"settings.editor.chooseFont": "Auswählen…",
140140
"settings.editor.resetFont": "Zurücksetzen",
141141
"settings.editor.fontSize": "Schriftgröße",
142+
"settings.editor.checkboxStyle": "Kontrollkästchen-Stil",
143+
"settings.editor.checkboxStyle.square": "Quadrat",
144+
"settings.editor.checkboxStyle.circle": "Kreis",
145+
"settings.editor.checkboxStyle.diamond": "Raute",
146+
"settings.editor.checkboxStyle.shield": "Schild",
147+
"settings.editor.checkboxStyle.triangle": "Dreieck",
148+
"settings.editor.checkboxStyle.star": "Stern",
149+
"settings.editor.checkboxStyle.hexagon": "Sechseck",
150+
"settings.editor.checkboxStyle.heart": "Herz",
142151
"settings.editor.systemFont": "System",
143152
"settings.editor.spellChecking": "Rechtschreibung prüfen",
144153
"settings.editor.grammarChecking": "Grammatik prüfen",

‎EdgeMark/Resources/Locales/en.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@
139139
"settings.editor.chooseFont": "Choose…",
140140
"settings.editor.resetFont": "Reset",
141141
"settings.editor.fontSize": "Font size",
142+
"settings.editor.checkboxStyle": "Checkbox style",
143+
"settings.editor.checkboxStyle.square": "Square",
144+
"settings.editor.checkboxStyle.circle": "Circle",
145+
"settings.editor.checkboxStyle.diamond": "Diamond",
146+
"settings.editor.checkboxStyle.shield": "Shield",
147+
"settings.editor.checkboxStyle.triangle": "Triangle",
148+
"settings.editor.checkboxStyle.star": "Star",
149+
"settings.editor.checkboxStyle.hexagon": "Hexagon",
150+
"settings.editor.checkboxStyle.heart": "Heart",
142151
"settings.editor.systemFont": "System",
143152
"settings.editor.spellChecking": "Check spelling",
144153
"settings.editor.grammarChecking": "Check grammar",

‎EdgeMark/Resources/Locales/es.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@
139139
"settings.editor.chooseFont": "Elegir\u2026",
140140
"settings.editor.resetFont": "Restablecer",
141141
"settings.editor.fontSize": "Tamaño de fuente",
142+
"settings.editor.checkboxStyle": "Estilo de casilla",
143+
"settings.editor.checkboxStyle.square": "Cuadrado",
144+
"settings.editor.checkboxStyle.circle": "Círculo",
145+
"settings.editor.checkboxStyle.diamond": "Diamante",
146+
"settings.editor.checkboxStyle.shield": "Escudo",
147+
"settings.editor.checkboxStyle.triangle": "Triángulo",
148+
"settings.editor.checkboxStyle.star": "Estrella",
149+
"settings.editor.checkboxStyle.hexagon": "Hexágono",
150+
"settings.editor.checkboxStyle.heart": "Corazón",
142151
"settings.editor.systemFont": "Sistema",
143152
"settings.editor.spellChecking": "Corrección ortográfica",
144153
"settings.editor.grammarChecking": "Corrección gramatical",

‎EdgeMark/Resources/Locales/hi.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@
139139
"settings.editor.chooseFont": "चुनें…",
140140
"settings.editor.resetFont": "रीसेट",
141141
"settings.editor.fontSize": "फ़ॉन्ट साइज़",
142+
"settings.editor.checkboxStyle": "चेकबॉक्स शैली",
143+
"settings.editor.checkboxStyle.square": "वर्ग",
144+
"settings.editor.checkboxStyle.circle": "वृत्त",
145+
"settings.editor.checkboxStyle.diamond": "हीरा",
146+
"settings.editor.checkboxStyle.shield": "ढाल",
147+
"settings.editor.checkboxStyle.triangle": "त्रिभुज",
148+
"settings.editor.checkboxStyle.star": "तारा",
149+
"settings.editor.checkboxStyle.hexagon": "षट्कोण",
150+
"settings.editor.checkboxStyle.heart": "दिल",
142151
"settings.editor.systemFont": "सिस्टम",
143152
"settings.editor.spellChecking": "स्पेलिंग जांचें",
144153
"settings.editor.grammarChecking": "व्याकरण जांचें",

‎EdgeMark/Resources/Locales/zh-Hans.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@
139139
"settings.editor.chooseFont": "选择…",
140140
"settings.editor.resetFont": "重置",
141141
"settings.editor.fontSize": "字号",
142+
"settings.editor.checkboxStyle": "复选框样式",
143+
"settings.editor.checkboxStyle.square": "方形",
144+
"settings.editor.checkboxStyle.circle": "圆形",
145+
"settings.editor.checkboxStyle.diamond": "菱形",
146+
"settings.editor.checkboxStyle.shield": "盾形",
147+
"settings.editor.checkboxStyle.triangle": "三角形",
148+
"settings.editor.checkboxStyle.star": "星形",
149+
"settings.editor.checkboxStyle.hexagon": "六边形",
150+
"settings.editor.checkboxStyle.heart": "心形",
142151
"settings.editor.systemFont": "系统",
143152
"settings.editor.spellChecking": "拼写检查",
144153
"settings.editor.grammarChecking": "语法检查",

‎EdgeMark/UI/Settings/GeneralSettingsTab.swift‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct GeneralSettingsTab: View {
1515
@State private var activeRootID: String?
1616
@State private var askOnLaunch: Bool
1717
@State private var removalBlockedMessage: String?
18+
@State private var hoveredCheckboxPreset: AppSettings.TaskCheckboxPreset?
1819

1920
init() {
2021
let s = ShortcutSettings.shared
@@ -104,6 +105,41 @@ struct GeneralSettingsTab: View {
104105
}
105106
}
106107

108+
LabeledContent(l10n["settings.editor.checkboxStyle"]) {
109+
ScrollView(.horizontal, showsIndicators: false) {
110+
HStack(spacing: 10) {
111+
ForEach(AppSettings.TaskCheckboxPreset.allCases, id: \.self) { preset in
112+
let isSelected = settings.taskCheckboxPreset == preset
113+
let isHovered = hoveredCheckboxPreset == preset
114+
Button {
115+
settings.taskCheckboxPreset = preset
116+
} label: {
117+
HStack(spacing: 6) {
118+
Image(systemName: preset.uncheckedSymbolName)
119+
Image(systemName: preset.checkedSymbolName)
120+
}
121+
.font(.title3)
122+
.foregroundStyle(isSelected ? Color.accentColor : (isHovered ? .primary : .secondary))
123+
.padding(.horizontal, 8)
124+
.padding(.vertical, 4)
125+
.background(
126+
RoundedRectangle(cornerRadius: 6)
127+
.fill(.primary.opacity(isSelected ? 0.12 : (isHovered ? 0.08 : 0))),
128+
)
129+
.overlay(
130+
RoundedRectangle(cornerRadius: 6)
131+
.strokeBorder(Color.accentColor, lineWidth: isSelected ? 1.5 : 0),
132+
)
133+
}
134+
.buttonStyle(.plain)
135+
.onHover { hoveredCheckboxPreset = $0 ? preset : nil }
136+
.help(l10n["settings.editor.checkboxStyle.\(preset.rawValue)"])
137+
}
138+
}
139+
.animation(.easeInOut(duration: 0.15), value: hoveredCheckboxPreset)
140+
}
141+
}
142+
107143
Toggle(l10n["settings.editor.spellChecking"], isOn: $settings.spellCheckingEnabled)
108144
Toggle(l10n["settings.editor.grammarChecking"], isOn: $settings.grammarCheckingEnabled)
109145
Toggle(l10n["settings.editor.autocorrect"], isOn: $settings.automaticSpellingCorrectionEnabled)

0 commit comments

Comments
 (0)