Repository navigation
MarkdownAura v1.5.1
MarkdownAura 1.5.1
ctrl S 不再闪一下、不再把光标弄丢。 在源码编辑模式下保存后,编辑栏会短暂切回只读再切回,光标随之消失。
两个原因叠加,都不是"刷新了错的窗口"这么简单:
- 本工具自己的写入被当成了外部改动。 保存走 temp + rename(原子替换),文件监视器把这一串报告成普通的
变动事件,而应用只按"文件变了"处理——于是一次保存触发两轮完整重绘:保存路径自己那一次,以及约
120 ms 后监视器那一次。现在save_doc记下自己写入后的 mtime,监视器丢弃仍带这个 mtime 的事件:盘上就是
屏幕上已有的东西,没有可重载的。外部改动照旧即时重载(这条规则只认"还是我们刚写的那份文件")。 - 编辑栏的存亡取决于"手上有没有文本"。 重读期间文本会短暂缺失,而应用把"没有文本"读成了"这一栏不是
编辑器",于是把光标所在的那一层隐藏、把只读层换回来——焦点随之丢失,光标不再绘制。现在这一栏的身份由
模式决定,文本缺失时不下发:光标、选区、撤销历史都不会被动到。
顺带修好一个同源的边角:编辑中的文件被删掉时,重载读到的是空串(不是空文档),过去会把缓冲区抹成空;现在
不下发,缓冲区留着,保存仍按 SPEC §12 拒绝写入已消失的文件。
验证(真机,不是读代码):CDP 时间线上,修复前保存后 211 ms 出现 #editor-split 被隐藏、.pane-src
去掉 editing、只读层显示,269 ms 起第二轮重绘,结束时 document.activeElement 是 body;修复后只有一轮
重绘、无翻转、focusedAfter: true、.cm-cursor 在。cargo test 91 通过(新增 2 条),tsc --noEmit
干净,异地改动仍即时重载。小文档不会复现这个缺陷(预览重绘短于监视器的 120 ms 去抖窗口),所以它看起来
"偶尔才闪一次"。
没有渲染器改动、没有新设置、没有存储格式变化。
ctrl S no longer flashes the pane or drops the caret. Saving in the source-editing mode briefly swapped the
editable pane back to the read-only sheet and back, and the caret disappeared with it. Two causes, and neither
is just "the wrong pane was refreshed":
- The app's own write came back as an external change. Saving replaces the file through a temp file plus a
rename, which the file watcher reports like any other change — and the app treated every one of them as
somebody else's edit. One save therefore repainted the whole document twice, about 120 ms apart.save_doc
now records the mtime it left behind and the watcher drops an event for a file that still carries it: the disk
already holds what is on screen, so there is nothing to reload. An external write still reloads at once. - The pane's existence depended on having the text in hand. During a re-read the text is briefly absent, and
the app read "no text" as "this is not an editor" — hiding the very element the caret was in and putting the
read-only layer back. Focus went with it, so the caret stopped being drawn. The mode now decides which pane
this is; a text that has not arrived is simply not pushed, which leaves the caret, the selection and the undo
history alone.
One related corner is fixed with it: when the file being edited is deleted, the reload reads an empty string (not
an empty document) and used to wipe the buffer. It is no longer pushed, and saving still refuses to write into a
file that is gone (SPEC §12).
Verified on a real build (CDP timings, not by reading the code): before the fix, 211 ms after a save
#editor-split was hidden, .pane-src lost editing, the read-only layer was shown, a second repaint started at
269 ms and document.activeElement ended up as body; after it, one repaint, no flips, focusedAfter: true, the
cursor element present. cargo test 91 passed (two new), tsc --noEmit clean, external edits still reload live.
A small document never reproduced this (its preview repaint is shorter than the watcher's 120 ms debounce), which
is why it looked like an occasional flash.
No renderer change, no new setting, no storage change.