Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

fix(mobile): preserve empty tasks through save and reload (#35085)

OrcaWin3eda769de321
diff --git a/mobile/src/components/rich-markdown/html-list-markdown.ts b/mobile/src/components/rich-markdown/html-list-markdown.ts
index 372b78006df..4893afb2c5c 100644
--- a/mobile/src/components/rich-markdown/html-list-markdown.ts
+++ b/mobile/src/components/rich-markdown/html-list-markdown.ts
@@ -132,6 +132,11 @@ export function holdsUnownedList(element: Element): boolean {
return Array.from(element.querySelectorAll('ul, ol')).some((list) => list.closest('li') === null)
}
+// An empty task saves as a bare `- [ ]` rather than leaving trailing whitespace on its line.
+function itemLine(prefix: string, text: string, isTask: boolean): string {
+ return isTask && !text ? prefix.trimEnd() : prefix + text
+}
+
// Indent two spaces per list level; prefer markup item number over position to preserve pasted/split browser renumbering.
export function listMarkdown(element: Element, depth: number): string {
const tag = element.tagName.toLowerCase()
@@ -163,7 +168,7 @@ export function listMarkdown(element: Element, depth: number): string {
.split('\n')
.map((text, lineIndex) => (lineIndex === 0 || !text ? text : continuation + text))
.join('\n')
- : indent + marker + listItemText(item)
+ : itemLine(indent + marker, listItemText(item), isTask)
// Children of a wide ordered marker start at its content column, or readers end the item.
const nestedIndent = blocks
? ' '.repeat(Math.max(0, continuation.length - indent.length - 2))
diff --git a/mobile/src/components/rich-markdown/markdown-empty-tasks.test.ts b/mobile/src/components/rich-markdown/markdown-empty-tasks.test.ts
new file mode 100644
index 00000000000..3dad7a19afb
--- /dev/null
+++ b/mobile/src/components/rich-markdown/markdown-empty-tasks.test.ts
@@ -0,0 +1,58 @@
+// @vitest-environment happy-dom
+import { afterEach, expect, it } from 'vitest'
+import { createRichMarkdownEditorDocument } from './create-rich-markdown-editor-document'
+import { RICH_MARKDOWN_EDITOR_MARKUP } from './document-markup'
+import { quietRichMarkdownEditorHost } from './rich-markdown-editor-host.test-support'
+import type { MobileRichMarkdownEditorMessage } from '../mobile-rich-markdown-editor-contract'
+
+const stopDocuments: (() => void)[] = []
+
+afterEach(() => {
+ stopDocuments.splice(0).forEach((stop) => stop())
+ document.body.innerHTML = ''
+})
+
+function mount(markdown: string) {
+ document.body.innerHTML = RICH_MARKDOWN_EDITOR_MARKUP
+ const messages: MobileRichMarkdownEditorMessage[] = []
+ const editor = createRichMarkdownEditorDocument({
+ ...quietRichMarkdownEditorHost(),
+ postToHost: (message) => messages.push(message)
+ })
+ stopDocuments.push(editor.stop)
+ editor.send.setMarkdown(markdown, 7)
+ const surface = document.getElementById('editor')!
+ const checks = () =>
+ Array.from(surface.querySelectorAll<HTMLInputElement>('input')).map((input) => input.checked)
+ return { surface, messages, send: editor.send, checks }
+}
+
+it.each([
+ ['- [ ]', '- [ ]', [false]],
+ ['- [x]', '- [x]', [true]],
+ ['- [ ] ', '- [ ]', [false]],
+ ['- [ ] Parent\n - [x]', '- [ ] Parent\n - [x]', [false, true]]
+])(
+ 'reloads the empty task in %j without turning its marker into prose',
+ (source, saved, checks) => {
+ const editor = mount(source)
+ expect(editor.checks()).toEqual(checks)
+ expect(editor.send.currentMarkdown()).toBe(saved)
+ expect(editor.messages.filter((message) => message.type === 'change')).toEqual([])
+ }
+)
+
+it('saves a toggled empty task as a task marker', () => {
+ const editor = mount('- [x]\n- [ ] Next')
+ editor.surface.querySelector<HTMLInputElement>('input')!.click()
+ expect(editor.messages.filter((message) => message.type === 'change')).toEqual([
+ { type: 'change', generation: 7, markdown: '- [ ]\n- [ ] Next' }
+ ])
+})
+
+it('keeps incomplete task markers and bracket-prefixed text as ordinary list text', () => {
+ const markdown = '- [ ]suffix\n- [x]suffix\n- []\n- [z]'
+ const editor = mount(markdown)
+ expect(editor.checks()).toEqual([])
+ expect(editor.send.currentMarkdown()).toBe(markdown)
+})
diff --git a/mobile/src/components/rich-markdown/markdown-list-parse.ts b/mobile/src/components/rich-markdown/markdown-list-parse.ts
index 39267c2c5e1..6f706870dcc 100644
--- a/mobile/src/components/rich-markdown/markdown-list-parse.ts
+++ b/mobile/src/components/rich-markdown/markdown-list-parse.ts
@@ -26,14 +26,14 @@ export function parseListLine(line: string): ParsedListItem | null {
}
const marker = match[2] ?? ''
const rawText = match[3] ?? ''
- const task = rawText.match(/^\[([ xX])\]\s+(.+)$/)
+ const task = rawText.match(/^\[([ xX])\](?:\s+(.*))?$/)
const ordered = /^\d/.test(marker)
return {
indent: indentationWidth(match[1] ?? ''),
ordered,
orderedNumber: ordered ? Number.parseInt(marker, 10) : null,
task: task ? task[1]!.toLowerCase() === 'x' : null,
- text: task ? task[2]! : rawText,
+ text: task ? (task[2] ?? '') : rawText,
children: []
}
}