Repository navigation
Description
English
Use case
Vex is evaluating StreamMark as the reading/preview renderer beside a source editor. Typing can modify any part of the source, so the preview must refresh complete text rather than append chat tokens.
Environment: Windows, .NET SDK 10.0.303 / net10.0, Avalonia 12.1.4, TKCode.StreamMark.Avalonia 0.1.0-alpha.23.
Reproduction (executed against the published NuGet package)
using StreamMark.Avalonia;
using StreamMark.Avalonia.Selection;
var view = new MarkdownView {
Markdown = "# Title\n\nFirst paragraph.\n\nLast paragraph."
};
// Model-level selection setup; this probe does not exercise pointer input/layout.
view.Selection.Set(new TextPoint(0, 9, 0, 0), new TextPoint(0, 9, 0, 5));
Console.WriteLine(view.Selection.IsEmpty); // False
view.Markdown = "# Title\n\nFirst paragraph.\n\nChanged last paragraph.";
Console.WriteLine(view.Selection.IsEmpty); // TrueSource inspection confirms MarkdownView.OnSourceChanged() calls _presenter.Clear(), _state.Clear() and Selection.Clear(): MarkdownView.cs. The experiment proves selection reset; it does not establish a measured UI flicker/scroll regression.
Requested improvement
Offer an opt-in complete-document refresh path for editor previews that:
- keeps old content visible until a current replacement snapshot is ready;
- preserves/remaps unaffected selection, reading anchor, and per-block state where possible;
- discards stale asynchronous results when updates arrive quickly;
- defines fallback behavior when the selected/anchored content is deleted.
The host can provide a change range or a source-position mapping if needed. This can be a separate preview adapter/document type; it need not make StreamingDocument mutable or change its append-only contract.
Acceptance criteria
- Editing the last paragraph preserves a selection in the unchanged first paragraph.
- Insert/delete before the selected block remaps positions correctly; deleted anchors have a documented fallback.
- Rapid A → B → C updates never leave A/B rendered after C has been accepted.
- New-document assignment still supports explicit state reset.
- Existing streaming equivalence, threading and NativeAOT behavior remain intact.
中文
使用场景与当前行为
Vex 希望在源码编辑器旁使用 StreamMark 预览。普通编辑会修改任意位置,不能完全套用聊天 token 追加模式。
上面的 NuGet 实测代码显示:修改文末后,之前在未修改段落中设置的选区也被清空。源码还会清理呈现器和块状态。此次实测仅确认选区重置,并未测出界面闪烁或滚动性能问题。
建议
为编辑预览提供可选的全文刷新入口:新快照完成前保留旧画面,尽可能映射并保留未受影响的选区、阅读锚点与块状态;快速更新时丢弃过期结果;被删除内容的状态采用明确回退策略。
宿主可传入改动范围或位置映射。这可以通过独立适配层实现,不要求改变 StreamingDocument 的只追加约束。
验收
修改末段不清空首段选区;在前面插入/删除内容后坐标可正确映射;删除选中内容时行为明确;连续 A/B/C 更新不会回退到过期版本;切换到新文档仍可主动清空状态;保持流式一致性、线程规则与 NativeAOT 兼容性。
Activity
239573049 commentedon Oct 21, 2026
Implemented in #8 (released in
0.1.0-alpha.24).StreamingDocumentstays append-only; this is a separate entry point onMarkdownView.RefreshMarkdown(text)replaces the whole text without clearing the view. AssigningMarkdownstill means "a new document" and resets selection and block state (DocumentIdchanges).Limits:
MarkdownViewonly (notTranscriptView); it throws if the text comes fromDocumentorStream; the find highlights (view.Search) are not recomputed after a refresh. I did not add a host-supplied change range: content alignment already handles edits, and a range would not make the result more precise.已在 #8 中实现(已随
0.1.0-alpha.24发布)。StreamingDocument仍是只追加的,这是MarkdownView上独立的入口。RefreshMarkdown(text)整篇替换文本但不清空视图;直接给Markdown赋值仍表示换一个新文档,会清空选区与块状态(DocumentId变化)。局限:只做了
MarkdownView(没做TranscriptView);文本来自Document/Stream时调用会抛异常;刷新后查找高亮(view.Search)不会自动重算。没有加宿主传入的改动范围:按内容对齐已经能处理编辑,范围参数不会让结果更准。Merge pull request #8 from AtomUICommunity/release/0.1.0-alpha.24