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): name task checkboxes from their current task text (#35081)

OrcaWin649cced48190
diff --git a/mobile/src/components/rich-markdown/editor-commands.ts b/mobile/src/components/rich-markdown/editor-commands.ts
index 9ebd7bb692e..e8249e98bac 100644
--- a/mobile/src/components/rich-markdown/editor-commands.ts
+++ b/mobile/src/components/rich-markdown/editor-commands.ts
@@ -1,4 +1,4 @@
-import { emitChange, syncTaskCheckboxesDisabled } from './editor-content'
+import { emitChange } from './editor-content'
import {
rememberSelection,
restoreRememberedSelection,
@@ -156,6 +156,5 @@ export async function runCommand(
return
}
}
- syncTaskCheckboxesDisabled(scope)
emitChange(scope)
}
diff --git a/mobile/src/components/rich-markdown/editor-content.ts b/mobile/src/components/rich-markdown/editor-content.ts
index 0b3c41746ba..a316532598e 100644
--- a/mobile/src/components/rich-markdown/editor-content.ts
+++ b/mobile/src/components/rich-markdown/editor-content.ts
@@ -13,12 +13,32 @@ export function currentMarkdown(scope: RichMarkdownEditorScope): string {
.trimEnd()
}
-/** A checkbox the user could move under a read-only document would record nothing, so it cannot. */
-export function syncTaskCheckboxesDisabled(scope: RichMarkdownEditorScope) {
+// A task's own words: its checkbox label, nested lists and code blocks are not part of its name.
+function ownTaskText(node: Node): string {
+ if (node.nodeType === node.TEXT_NODE) {
+ return node.nodeValue ?? ''
+ }
+ if (!(node instanceof Element) || node.matches('label, ul, ol, pre')) {
+ return ''
+ }
+ if (node.matches('br')) {
+ return ' '
+ }
+ const text = Array.from(node.childNodes, ownTaskText).join('')
+ return node.matches('p, div') ? ` ${text} ` : text
+}
+
+/** Keep task controls named from their own live text and unavailable in read-only documents. */
+export function syncTaskCheckboxes(scope: RichMarkdownEditorScope) {
editorElement(scope)
.querySelectorAll<HTMLInputElement>('input[type="checkbox"]')
.forEach((input) => {
input.disabled = !scope.editable
+ const item = input.closest('li')
+ const label = (item ? ownTaskText(item).replace(/\s+/g, ' ').trim() : '') || 'Task'
+ if (input.getAttribute('aria-label') !== label) {
+ input.setAttribute('aria-label', label)
+ }
})
}
@@ -28,6 +48,7 @@ export function emitChange(scope: RichMarkdownEditorScope) {
return
}
scope.clearTimer(scope.inputTimer)
+ syncTaskCheckboxes(scope)
const pendingGeneration = scope.documentGeneration
scope.lastMarkdown = currentMarkdown(scope)
post(scope, { type: 'change', markdown: scope.lastMarkdown, generation: pendingGeneration })
@@ -42,7 +63,7 @@ export function setMarkdown(scope: RichMarkdownEditorScope, markdown: string, ge
scope.selectionDroppedOnBlur = false
scope.lastMarkdown = String(markdown || '')
editorElement(scope).innerHTML = markdownToHtml(scope, scope.lastMarkdown)
- syncTaskCheckboxesDisabled(scope)
+ syncTaskCheckboxes(scope)
scope.suppressInput = false
}
@@ -55,5 +76,5 @@ export function stopEditorContent(scope: RichMarkdownEditorScope) {
export function setEditable(scope: RichMarkdownEditorScope, editable: boolean) {
scope.editable = Boolean(editable)
editorElement(scope).setAttribute('contenteditable', scope.editable ? 'true' : 'false')
- syncTaskCheckboxesDisabled(scope)
+ syncTaskCheckboxes(scope)
}
diff --git a/mobile/src/components/rich-markdown/task-checkbox-accessible-names.test.ts b/mobile/src/components/rich-markdown/task-checkbox-accessible-names.test.ts
new file mode 100644
index 00000000000..56285b7be39
--- /dev/null
+++ b/mobile/src/components/rich-markdown/task-checkbox-accessible-names.test.ts
@@ -0,0 +1,61 @@
+// @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) {
+ const root = document.createElement('div')
+ root.innerHTML = RICH_MARKDOWN_EDITOR_MARKUP
+ document.body.append(root)
+ const messages: MobileRichMarkdownEditorMessage[] = []
+ const editorDocument = createRichMarkdownEditorDocument({
+ ...quietRichMarkdownEditorHost(),
+ root,
+ postToHost: (message) => messages.push(message)
+ })
+ stopDocuments.push(editorDocument.stop)
+ editorDocument.send.setMarkdown(markdown, 7)
+ const surface = root.querySelector('#editor')!
+ const names = () =>
+ Array.from(root.querySelectorAll('input')).map((input) => input.getAttribute('aria-label'))
+ return { root, surface, names, messages, send: editorDocument.send }
+}
+
+it('names plain, formatted and nested task controls without serializing their labels', () => {
+ const markdown = '- [ ] First task\n- [x] **Second task**\n - [ ] Nested task'
+ const editor = mount(markdown)
+ expect(editor.names()).toEqual(['First task', 'Second task', 'Nested task'])
+ expect(editor.send.currentMarkdown()).toBe(markdown)
+ expect(editor.messages.filter((message) => message.type === 'change')).toEqual([])
+})
+
+it('updates the task name after editing its text', () => {
+ const editor = mount('- [ ] First **task**')
+ editor.root.querySelector('strong')!.append(' updated')
+ editor.surface.dispatchEvent(new InputEvent('input', { bubbles: true, inputType: 'insertText' }))
+ expect(editor.names()).toEqual(['First task updated'])
+})
+
+it('keeps an emptied task control named', () => {
+ const editor = mount('- [ ] Remove text')
+ editor.root.querySelector('p')!.replaceChildren()
+ editor.surface.dispatchEvent(
+ new InputEvent('input', { bubbles: true, inputType: 'deleteContentBackward' })
+ )
+ expect(editor.names()).toEqual(['Task'])
+})
+
+it('names a task from its own line rather than its code block', () => {
+ const editor = mount('- [ ] Install:\n ```sh\n pnpm install\n ```')
+ expect(editor.surface.querySelector('li pre')).not.toBeNull()
+ expect(editor.names()).toEqual(['Install:'])
+})