Skip to content

Commit ccfea7b

Browse files
Create todo notes with checkbox markdown, strip checkboxes from preview
- Pass initial markdown to create_note backend so todo notes are stored with "- [ ] " from creation, making them match the todo filter query immediately (no animation delay) - Strip checkbox markers ([ ], [x]) from note card preview text - Handle checkbox markers with or without trailing content
1 parent 760cabd commit ccfea7b

4 files changed

Lines changed: 20 additions & 13 deletions

File tree

src-tauri/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ fn load_note(app: AppHandle, note_id: String) -> Result<LoadedNote, AppError> {
121121
}
122122

123123
#[tauri::command]
124-
fn create_note(app: AppHandle, notebook_id: Option<String>, tags: Vec<String>) -> Result<LoadedNote, AppError> {
125-
notes::create_note(&app, notebook_id.as_deref(), &tags)
124+
fn create_note(app: AppHandle, notebook_id: Option<String>, tags: Vec<String>, markdown: Option<String>) -> Result<LoadedNote, AppError> {
125+
notes::create_note(&app, notebook_id.as_deref(), &tags, markdown.as_deref())
126126
}
127127

128128
#[tauri::command]

src-tauri/src/notes.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,21 @@ pub fn create_note(
241241
app: &AppHandle,
242242
notebook_id: Option<&str>,
243243
tags: &[String],
244+
initial_markdown: Option<&str>,
244245
) -> Result<LoadedNote, AppError> {
245246
let mut conn = database_connection(app)?;
246247
let transaction = conn.transaction()?;
247248
let note_id = generate_note_id();
248-
let markdown = if tags.is_empty() {
249-
"# ".to_string()
250-
} else {
251-
let tag_line = tags.iter().map(|t| format!("#{t}")).collect::<Vec<_>>().join(" ");
252-
format!("# \n\n{tag_line}")
249+
let markdown = match initial_markdown {
250+
Some(md) => md.to_string(),
251+
None => {
252+
if tags.is_empty() {
253+
"# ".to_string()
254+
} else {
255+
let tag_line = tags.iter().map(|t| format!("#{t}")).collect::<Vec<_>>().join(" ");
256+
format!("# \n\n{tag_line}")
257+
}
258+
}
253259
};
254260
let title = title_from_markdown(&markdown);
255261
let now = now_millis();
@@ -1275,8 +1281,10 @@ fn strip_markdown_syntax(line: &str) -> String {
12751281
s = s[3..].trim_start().to_string();
12761282
}
12771283
}
1278-
// Strip checkbox markers
1279-
s = s.strip_prefix("[ ] ").or_else(|| s.strip_prefix("[x] ")).unwrap_or(&s).to_string();
1284+
// Strip checkbox markers (with or without trailing space/content)
1285+
s = s.strip_prefix("[ ] ").or_else(|| s.strip_prefix("[x] "))
1286+
.or_else(|| s.strip_prefix("[ ]")).or_else(|| s.strip_prefix("[x]"))
1287+
.unwrap_or(&s).trim().to_string();
12801288
// Strip inline markdown: bold, italic, strikethrough, inline code
12811289
s = s.replace("***", "").replace("**", "").replace("~~", "");
12821290
// Strip inline code backticks

src/features/shell/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export async function loadNote(noteId: string) {
5353
export async function createNote(input: {
5454
notebookId: string | null;
5555
tags: string[];
56+
markdown?: string;
5657
}) {
5758
return invoke<LoadedNote>("create_note", input);
5859
}

src/features/shell/use-shell-controller.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,7 @@ export function useShellController() {
314314
queryClient.setQueryData(["note", note.id], note);
315315
setCreatingSelectedNoteId(note.id);
316316
setSelectedNoteId(note.id);
317-
// In todo view, start with a checkbox instead of a heading
318-
const initialMarkdown =
319-
noteFilter === "todo" ? "- [ ] " : note.markdown;
320-
setDraft(note.id, initialMarkdown);
317+
setDraft(note.id, note.markdown);
321318
setIsCreatingNoteTransition(false);
322319
void Promise.all([invalidateNotes(), invalidateContextualTags()]);
323320
},
@@ -681,6 +678,7 @@ export function useShellController() {
681678
createNoteMutation.mutate({
682679
notebookId: noteFilter === "notebook" ? activeNotebookId : null,
683680
tags: tagsForNewNote,
681+
markdown: noteFilter === "todo" ? "- [ ] " : undefined,
684682
});
685683
};
686684

0 commit comments

Comments
 (0)