Skip to content

[Feature] Add opt-in task checkbox interaction with host write-back / 支持可选任务勾选与宿主回写 #7

Closed

Description

@dotnet9

English

Use case

In a local-file Markdown editor, clicking - [ ] / - [x] in the reading/preview pane should be able to request a source change through the host's document/undo pipeline. Vex currently supports this interaction and would need an equivalent integration point when adopting StreamMark.

Reviewed: TKCode.StreamMark.Avalonia 0.1.0-alpha.23, Avalonia 12.1.4, .NET 10.

Current behavior

The parser supports task lists. In the reviewed implementation, ListItemBlockView draws the marker using CheckboxRun, whose source describes it as read-only. There is no public host write-back event identified in this path. This is a source/API inspection finding, not a pointer-input test result.

Sources: ContainerViews.cs, InlineRuns.cs.

Requested improvement

Add opt-in task interaction, keeping the current read-only default:

  • a click/keyboard action emits a host request containing entry/document version, task-marker source range, current state and requested state;
  • the host accepts/rejects the request and performs the actual Markdown edit, undo grouping and persistence;
  • StreamMark does not write files or mutate an immutable snapshot on its own;
  • interaction is disabled or version-checked when the source is incomplete/stale.

A public callback/event is sufficient; no full editor is required.

Acceptance criteria

  • Nested tasks, ordered/unordered lists and duplicate task labels identify the correct source marker.
  • Changing [ ] ↔ [x] preserves unrelated text, indentation and CRLF.
  • Read-only hosts produce no edit request; rejected requests leave the rendered state unchanged.
  • The host can apply one undoable edit and reject an outdated request by version.
  • Keyboard activation and accessibility state are considered, and clicking task text can still select text normally.

中文

使用场景与当前边界

本地 Markdown 编辑器通常支持在阅读/预览界面点击任务框,再通过宿主文档与撤销系统回写原文。Vex 已有该交互,迁移到 StreamMark 时需要对应入口。

当前解析器支持任务列表,但所检查的实现使用只读 CheckboxRun 绘制任务框,尚未在这条调用路径中发现公开的宿主回写事件。此结论来自源码/API 检查,不是实际鼠标点击测试。

建议

提供默认关闭的任务交互功能。点击或键盘操作时,向宿主发送包含文档/条目版本、任务标记源码范围、当前与目标状态的请求。由宿主接受或拒绝,并负责修改原文、记录撤销和保存;StreamMark 不自行写文件,也不把派生快照当作可变原文。

源码未完成或版本过期时应禁用交互或校验版本。公开事件/回调即可,不要求内置完整编辑器。

验收

嵌套、不同列表类型和重复文本均能定位正确任务;只修改目标状态,保留缩进、CRLF 和其他原文;只读模式不发请求,拒绝请求不改变勾选状态;宿主可作为单次操作撤销并拒绝过期请求;考虑键盘和无障碍,同时保留任务正文的正常选区行为。

Activity

  1. 239573049 commented on Oct 21, 2026

    @239573049
    Collaborator

    Implemented in #8 (released in 0.1.0-alpha.24). The default stays read-only.

    • Set MarkdownView.IsTaskInteractionEnabled = true. A click on the box, or Space/Enter once it has focus, raises TaskToggleRequested instead of changing anything. StreamMark never edits the source or the snapshot; a rejected request leaves the screen unchanged.
    • TaskToggleRequestedEventArgs has Marker (the source range of [ ] / [x]), IsChecked, RequestedChecked, DocumentId and Version. ApplyTo(source) replaces only the character inside the brackets, so indentation and CRLF are kept, and returns null if the source no longer matches. view.IsCurrent(request) lets you reject a stale request.
    • Requests are only raised for a complete document (not while a stream is running). Clicking the task text still selects text. Task items expose a CheckBox automation peer with IToggleProvider.
    • Tested with nested, ordered/unordered and duplicate-label tasks, and CRLF.

    Limits: TranscriptView is not wired up (only MarkdownView). Feedback on the event shape is welcome.

    已在 #8 中实现(已随 0.1.0-alpha.24 发布),默认仍然只读。

    • 设置 MarkdownView.IsTaskInteractionEnabled = true 后,点击复选框(或聚焦后按空格 / 回车)只会触发 TaskToggleRequested,不会自行修改任何东西。StreamMark 不改原文也不改快照,拒绝请求时画面不变。
    • TaskToggleRequestedEventArgs 带 Marker([ ] / [x] 的源码区间)、IsChecked、RequestedChecked、DocumentId、Version。ApplyTo(source) 只替换方括号里的那个字符,缩进和 CRLF 原样保留,源码已变化时返回 null;view.IsCurrent(request) 用来拒绝过期的请求。
    • 只在文档完整时发请求(流式进行中不发)。点任务正文仍是正常选区。任务项提供带 IToggleProvider 的 CheckBox 无障碍节点。
    • 测试覆盖嵌套、有序 / 无序、重复标签和 CRLF。

    局限:TranscriptView 尚未接入(只做了 MarkdownView)。欢迎对事件形态提意见。

  2. added a commit that references this issue on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions