Compare commits
15 Commits
v1.4.2-loc
...
44fe93ec20
| Author | SHA1 | Date | |
|---|---|---|---|
| 44fe93ec20 | |||
| 8221eb5908 | |||
| c783a6dc56 | |||
| dfe38890e0 | |||
| 8d98b5e7a9 | |||
| d2b1630a35 | |||
| 301e042bec | |||
| d54b953094 | |||
| 618ac47b83 | |||
| 8644966b10 | |||
| dd4083fe80 | |||
| d90e47e606 | |||
| 809b7b0299 | |||
| abeb426a43 | |||
| 47e71cf692 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,6 +5,9 @@
|
||||
# 上游源码备份:本地保留,不入 git(用户决定)
|
||||
/backup/
|
||||
|
||||
# 本机草稿目录(不属于仓库)
|
||||
/test/
|
||||
|
||||
# 日志与临时文件
|
||||
*.log
|
||||
/agent/tmp/
|
||||
|
||||
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -1684,7 +1684,6 @@ dependencies = [
|
||||
"rfd",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sys-locale",
|
||||
"tao",
|
||||
"url",
|
||||
"winreg",
|
||||
@@ -2822,15 +2821,6 @@ dependencies = [
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sys-locale"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8eab9a99a024a169fe8a903cf9d4a3b3601109bcc13bd9e3c6fff259138626c4"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-deps"
|
||||
version = "6.2.2"
|
||||
|
||||
@@ -12,7 +12,6 @@ rfd = "0.15"
|
||||
notify = "7"
|
||||
open = "5"
|
||||
image = { version = "0.25", default-features = false, features = ["png", "ico"] }
|
||||
sys-locale = "0.3"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
url = "2"
|
||||
|
||||
45
README.md
45
README.md
@@ -12,8 +12,10 @@
|
||||
|
||||
- **双击即开**:单个 exe(约 5.5 MB),不用安装;可设为 `.md` 的默认打开方式。
|
||||
- **完全离线**:不联网、不检查更新、无遥测;外部链接交给系统浏览器打开。
|
||||
- **多标签 + 多窗口**:标签右键可在新窗口打开,也可以上下拖动标签直接移出;同一文件全局只开一次,重复打开只聚焦;不恢复上次标签,启动显示最近文件、缺失文件可重新定位。
|
||||
- **预览 / 编辑一体**:`Ctrl+E` 切换;编辑时 700ms 自动保存,`Ctrl+S` 立即保存。
|
||||
- **多标签 + 多窗口**:新标签页(New Tab)本身就是一个默认标签,标签栏的 `+` 新建一个 New Tab;在 New Tab 里打开文件会直接替换该标签(浏览器语义);关闭最后一个文件标签回到 New Tab,只剩 New Tab 时标签栏自动隐藏。标签右键可在新窗口打开,也可以上下拖动标签直接移出;同一文件全局只开一次,重复打开只聚焦;不恢复上次标签,启动显示最近文件、缺失文件可重新定位。
|
||||
- **英文界面**:界面文案统一为英文,不随系统语言切换,避免中英文混排。
|
||||
- **预览 / 编辑一体**:`Ctrl+E` 切换;编辑模式与滚动位置按标签记忆,切回时恢复;编辑时 700ms 自动保存,`Ctrl+S` 立即保存。
|
||||
- **编辑更顺手**:Tab 插入 2 个空格、Shift+Tab 反缩进,多行选区整体缩进;Enter 自动跟随上一行缩进;保留原生撤销。
|
||||
- **长文档友好**:
|
||||
- 鼠标移到标题左侧出现折角箭头,点击即可折叠到下一个同级标题(H1–H6);
|
||||
- `Ctrl+滚轮` 缩放正文,5% 一档、范围 50%–300%,并记住上次的缩放。
|
||||
@@ -24,8 +26,8 @@
|
||||
|
||||
## 下载与运行
|
||||
|
||||
1. 在 [Releases](https://git.wucl12.cn/wucl12/md-preview/releases) 页下载 `MD-Preview-windows-x64.exe`(当前发布版本 `v1.4.2-local.3`,2026-10-28);
|
||||
2. 放到一个固定目录(例如 `D:\Scripts\md-preview\`),不要随意改名/移动;
|
||||
1. 在 [Releases](https://git.wucl12.cn/wucl12/md-preview/releases) 页下载 `MD-Preview-windows-x64.exe`(当前发布版本 `v1.4.2-local.5`,2026-10-30);
|
||||
2. 放到一个固定目录(例如 `C:\Tools\md-preview\`),不要随意改名/移动;
|
||||
3. 双击运行,或在任意 `.md` 上右键 → 打开方式 → 选择该 exe 并设为默认;
|
||||
4. Windows 10/11 一般自带 WebView2 Runtime;若提示缺失,安装微软的 Evergreen Runtime 即可。
|
||||
|
||||
@@ -36,18 +38,22 @@
|
||||
|
||||
| 操作 | 方式 |
|
||||
|---|---|
|
||||
| 打开文件 | 双击 `.md`、拖进窗口、`Ctrl+O`、首页“最近文件” |
|
||||
| 新建文件 | `Ctrl+N` |
|
||||
| 关闭标签 | `Ctrl+W` 或标签上的 ×;非最后窗口关掉最后一个标签会关闭该窗口 |
|
||||
| 在新窗口打开 | 右键标签 → “在新窗口打开”,或按住标签上下拖动超过约 24px(至少两个标签时可用) |
|
||||
| 打开文件所在位置 | 右键标签 → “打开文件所在位置”(文件丢失时打开所在目录) |
|
||||
| 打开文件 | 双击 `.md`、拖进窗口、`Ctrl+O`、新标签页的“Open File / Recent” |
|
||||
| 新建文件 | `Ctrl+N` 或新标签页的“New File”按钮 |
|
||||
| 新建标签 | 标签栏 `+`(新开一个 New Tab) |
|
||||
| 返回新标签页 | 点击标签栏的“New Tab”标签;只剩 New Tab 时标签栏自动隐藏 |
|
||||
| 关闭标签 | `Ctrl+W` 或标签上的 ×;关闭最后一个文件标签会回到 New Tab;非最后窗口关掉最后一个标签会关闭该窗口 |
|
||||
| 在新窗口打开 | 右键标签 → “Open in New Window”,或按住标签上下拖动超过约 24px(至少两个标签时可用) |
|
||||
| 打开文件所在位置 | 右键标签 → “Show in Explorer”(文件丢失时打开所在目录) |
|
||||
| 预览 / 编辑切换 | `Ctrl+E` |
|
||||
| 保存 | 自动(停止输入 700ms)或 `Ctrl+S` |
|
||||
| 查找 | `Ctrl+F`(工具栏没有搜索按钮,快捷键随时可用) |
|
||||
| 查找 | `Ctrl+F`(工具栏没有搜索按钮,快捷键随时可用);阅读模式选中文字后会自动填入,打开时不滚动 |
|
||||
| 打印 | `Ctrl+P` |
|
||||
| 缩放 | `Ctrl+滚轮`、`Ctrl++`、`Ctrl+-`、`Ctrl+0` 复位 |
|
||||
| 折叠标题 | 鼠标移到标题左侧,点折角箭头 |
|
||||
|
||||
> New Tab 上打开文件会直接替换这个标签(和浏览器新标签页一样),不会额外留下空白标签;想同时保留新标签页,先按标签栏的 `+` 新建一个 New Tab。
|
||||
|
||||
设置与最近文件保存在 `%LOCALAPPDATA%\md-preview\`(`recent-files.txt`、`zoom.txt` 等);旧 `session.json` 不再读写。删除 exe 不会自动清掉这些记录。
|
||||
|
||||
## 和上游 1.4.2 的主要区别
|
||||
@@ -55,7 +61,7 @@
|
||||
| 方面 | 改动 |
|
||||
|---|---|
|
||||
| 联网 / 更新 | 移除 GitHub Releases 检查、自更新和 Update 按钮,彻底离线 |
|
||||
| 工具栏 | 移除 Open / Print / Find 按钮,只保留 编辑 / 缩放;快捷键和空状态入口保留 |
|
||||
| 工具栏 | 移除 Open / Print / Find 按钮,只保留 Edit / Zoom;快捷键和空状态入口保留 |
|
||||
| 缩放 | 支持 `Ctrl+滚轮`,步进 5%、范围 50%–300%,并跨重启记住 |
|
||||
| 代码配色 | GitHub 浅/深主题换成始终深色的 VS Dark,只换 CSS、不引新库 |
|
||||
| 换行 | 单个换行按换行显示(AI 输出常见),空行仍是段落分隔;有意的方言差异 |
|
||||
@@ -65,6 +71,8 @@
|
||||
| 路径处理 | 修复 Windows `\\?\` 前缀污染 Recent / base URL 的问题 |
|
||||
| 稳定性 | 关闭前落盘、外部修改热重载、单实例转发、缺失文件重定位 |
|
||||
| 多窗口 | 单进程多窗口;标签右键移出到新窗口;同一文件全局唯一;启动只保留最近文件,不恢复标签 |
|
||||
| 新标签页 / 英文界面 | New Tab 成为默认标签;`+` 新建 New Tab;新标签页新增 New File 按钮;只剩 New Tab 时标签栏隐藏;界面统一为英文 |
|
||||
| 编辑 / 查找 | Tab/Shift+Tab 两空格缩进、Enter 跟随缩进;阅读模式 Find 支持选区填入,从选区打开时不滚动 |
|
||||
|
||||
## 从源码构建
|
||||
|
||||
@@ -76,11 +84,12 @@
|
||||
- WebView2 Runtime
|
||||
|
||||
```powershell
|
||||
cargo test # 53 个测试
|
||||
.\agent\scripts\build.ps1 # release 构建 + 校验 + 复制到固定 exe 路径
|
||||
cargo test
|
||||
.\agent\scripts\build.ps1 # release 构建 + 校验(产物留在 target\release\)
|
||||
.\agent\scripts\publish.ps1 # 发布到 Nutstore(用户手动,普通 PowerShell)
|
||||
```
|
||||
|
||||
构建脚本会打印 exe 的 SHA256、检查已移除功能的字符串,并确认文件完整性级别为 Medium。
|
||||
构建脚本会打印 exe 的 SHA256、检查已移除功能的字符串,并报告完整性级别;开发构建是 Low,`publish.ps1` 会把它升到 Medium 并复制到 Nutstore。
|
||||
更细的维护说明(工具链、完整性级别坑、验收清单)见 [`agent/docs/HANDOFF.md`](agent/docs/HANDOFF.md)。
|
||||
|
||||
## 目录
|
||||
@@ -88,9 +97,10 @@ cargo test # 53 个测试
|
||||
```text
|
||||
src/ Rust 源码(main.rs 界面/渲染/事件循环,session.rs 会话,instance.rs 单实例)
|
||||
assets/ 全部内嵌资源:highlight.js、KaTeX、Mermaid、图标、暗色代码主题
|
||||
agent/ 维护者文档、构建/冒烟脚本、测试夹具
|
||||
docs/ HANDOFF、STATUS、roadmap、扫描记录
|
||||
scripts/build.ps1 release 构建与校验
|
||||
agent/ 维护者文档、构建/冒烟/发布脚本、测试夹具
|
||||
docs/ HANDOFF、STATUS、roadmap、migration、扫描记录
|
||||
scripts/build.ps1 开发构建(release + 校验)
|
||||
scripts/publish.ps1 发布到 Nutstore(用户手动)
|
||||
tests/ 冒烟脚本与 Markdown 样例
|
||||
backup/ 上游源码备份(本地保留,不入 git)
|
||||
```
|
||||
@@ -104,6 +114,7 @@ backup/ 上游源码备份(本地保留,不入 git)
|
||||
- 拖拽标签只用于移出到新窗口;不支持拖回、窗口合并或跨窗口同步编辑。
|
||||
- 单换行按换行显示;如果源文件是按固定列硬折行的长段落,预览会保留这些断点,不随窗口宽度重排。
|
||||
- 只读文件可以看、可以改,但保存会被拒绝(会明确提示,不会卡死)。
|
||||
- 只识别 Markdown 扩展名(`.md` / `.markdown` / `.mdown` / `.mkd`);`.txt` 不再作为文档打开。
|
||||
|
||||
## 许可
|
||||
|
||||
|
||||
@@ -4,49 +4,68 @@
|
||||
|
||||
## 0. 工作区边界(最重要)
|
||||
|
||||
1. **只在工作区 `D:\Scripts\md-preview` 内创建、修改、删除文件。**
|
||||
2. **任何工作区外的修改都必须先停下询问用户**,包括但不限于:
|
||||
1. **仓库根**:`D:\Scripts\md-preview\AgentLowWorking`(2026-11-02 迁移后)。只在这个目录内创建、修改、删除文件。
|
||||
- DSH 工作区是父目录 `D:\Scripts\md-preview`;代码仓库在其下的 `AgentLowWorking`。改代码/跑 git 前先 `cd AgentLowWorking`(或 `git -C AgentLowWorking`)。
|
||||
- 父目录只放用户指定的小文件(发布启动器、AGENTS 指针);不要放源码/构建产物。
|
||||
- 仓库内**新增文件不需要事先询问**:按职责拆模块、抽资源、加测试是正常的代码组织手段。
|
||||
2. **任何仓库外的修改都必须先停下询问用户**,包括但不限于:
|
||||
- `%TEMP%` / `%LOCALAPPDATA%` / 用户目录 / 其它磁盘;
|
||||
- 注册表、计划任务、服务、环境变量;
|
||||
- 删除或移动任何不是本次刚在工作区内生成的文件。
|
||||
- 删除或移动任何不是本次刚在仓库内生成的文件。
|
||||
询问时要给出:完整路径、要做的操作、原因、影响范围;得到明确同意后才执行。
|
||||
3. 不允许为了省事把构建/测试的临时文件写到工作区外。本仓库约定临时目录放在
|
||||
`target\test-tmp`、`target\tmp` 下(均被 `.gitignore` 忽略)。
|
||||
4. 每次收尾前自查:`git status` 是否只剩预期改动;本次是否在工作区外留下文件;
|
||||
3. 构建/测试的临时文件留在 `target\tmp`、`target\test-tmp`(已忽略),不写 `%TEMP%`。
|
||||
4. 每次收尾前自查:`git status` 是否只剩预期改动;本次是否在仓库外留下文件;
|
||||
若发现历史残留,只报告并询问,不擅自删除。
|
||||
5. DSH 当前以 **danger-full-access** 运行,没有文件系统护栏——这条规则是唯一防线,不得绕过。
|
||||
5. DSH 以 **workspace-write(Low 完整性)** 运行;仓库整棵树是 Low,因此可以正常改代码、编译、commit。**不要**把仓库改回 Medium,**不要**申请 danger-full-access 来改代码。
|
||||
6. 截图、录屏等二进制验证产物**不入库**:放 `agent/tmp/`(已忽略)或 `target/tmp/`,看完即删;`agent/reports/` 只保留文本记录。
|
||||
7. `test/` 是本机草稿目录,已 gitignore;不要提交,不要当作仓库内容。
|
||||
|
||||
## 1. 不变量
|
||||
|
||||
- 产物路径固定:`D:\Scripts\md-preview\MD-Preview-windows-x64.exe`,默认 `.md` 打开方式指向它,不改名、不移动。
|
||||
- **仓库根**:`D:\Scripts\md-preview\AgentLowWorking`。
|
||||
- **发布产物**:`C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe`(Medium);默认 `.md` 打开方式指向它。
|
||||
- 仓库内**不放成品 exe**;旧的 `D:\Scripts\md-preview\MD-Preview-windows-x64.exe` 已删除,不要再生成。
|
||||
- Agent 编译出的 `target\release\md-preview.exe` 是 **Low**,不能直接双击运行(会 os error 5);冒烟必须把 `MD_PREVIEW_CONFIG_DIR` 指到仓库内目录。
|
||||
- 离线:不引入联网、自动更新、遥测;外部链接交给系统浏览器。
|
||||
- 轻量:不为小功能引入新库;优先原生 JS/CSS 与已有依赖。
|
||||
- 轻量是硬约束:exe 体积以 `build.ps1` 输出为准(2026-11 约 5.5 MB)。不为小功能引入新库,优先原生 JS/CSS 与已有依赖;要 vendor 新的离线资源(>200 KB)先说明并确认。
|
||||
- 可读性优先:单文件按职责拆分,不为“少几个文件”把逻辑堆进 `main.rs`;模块边界以“改一个功能只需动一两个文件”为准。
|
||||
- 右键菜单保持禁用;缩放只用 Ctrl + 滚轮与工具栏/快捷键。
|
||||
- 工作区完整性级别是 **Medium**;不要把工作区改成 Low。
|
||||
|
||||
## 2. 改动流程
|
||||
|
||||
1. 一次只做一个功能;**加功能前先给方案,用户确认后再写代码**。
|
||||
2. 改动超出已确认范围(新增文件、改公共接口、动构建脚本、碰工作区外)时,立即停下询问。
|
||||
3. 写完先 `cargo test` 全绿,再部署验收;部署要替换固定 exe 并校验 SHA256/完整性级别。
|
||||
4. 每个功能一个 conventional commit,推送到 `origin main`。
|
||||
1. 一次只做一件事;**用户可感知的功能/行为变化先给方案,用户确认后再写代码**。
|
||||
2. bug 修复、纯重构、测试、文档、格式与静态检查可以直接处理:每项独立提交,`cargo test` 全绿,提交信息写清行为变化。
|
||||
3. 代码级决策(拆模块、新增文件、内部接口、命名)由 agent 自行决定,不需要逐项询问。
|
||||
4. 只有这些要先停下询问:仓库外的文件/注册表/环境变量;发布;新增第三方库或 >200 KB 的 vendored 资源;改变不变量(离线、轻量、右键禁用、只支持 Windows 等)。
|
||||
5. 写完先 `cargo test` 全绿(含新增测试);改动页面 JS 时额外做一次语法检查。
|
||||
6. 每个改动一个 conventional commit,推送到 `origin main`。
|
||||
7. **发布只能由用户手动执行**:用户在普通 PowerShell(Medium)运行 `agent\scripts\publish.ps1`。Agent 不运行发布脚本、不改注册表、不碰 Nutstore。
|
||||
|
||||
## 3. 构建与测试
|
||||
|
||||
- 测试时把临时目录指到工作区内,避免 `%TEMP%` 残留:
|
||||
- 测试/构建前把临时目录指到仓库内:
|
||||
|
||||
```powershell
|
||||
$env:TEMP = "$PWD\target\test-tmp"; $env:TMP = $env:TEMP
|
||||
~~~powershell
|
||||
$env:TEMP = "$PWD\target\tmp"; $env:TMP = $env:TEMP
|
||||
New-Item -ItemType Directory -Force $env:TEMP | Out-Null
|
||||
cargo test
|
||||
```
|
||||
~~~
|
||||
|
||||
- 正式构建用 `agent\scripts\build.ps1`(先关闭正在运行的 MD Preview)。
|
||||
- `git clean -xdf` 会删除被忽略的 `backup/` 与成品 exe,禁止使用。
|
||||
- 开发构建:`.\agent\scripts\build.ps1`(cargo test + build --release + 字符串校验;产物留在 `target\release\`)。
|
||||
- DSH 的 pwsh 执行策略可能阻止未签名脚本;先运行 `Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force`。
|
||||
- 开发冒烟:`$env:MD_PREVIEW_CONFIG_DIR="$PWD\target\smoke"; .\target\release\md-preview.exe <file>`。
|
||||
- 不要把 `target\release\md-preview.exe` 复制到任何固定路径,也不要覆盖 Nutstore。
|
||||
- `git clean -xdf` 会删除被忽略的 `backup/`,禁止使用。
|
||||
|
||||
## 4. 参考
|
||||
## 4. 发布(用户手动)
|
||||
|
||||
- `docs/HANDOFF.md`:工具链、构建、完整性级别坑、验收。
|
||||
- 用户在**普通 PowerShell**(Medium)运行 `agent\scripts\publish.ps1`。
|
||||
- 脚本流程:复制 `target\release\md-preview.exe` → Nutstore → 设 Medium → 校验 SHA256 → 刷新 `.md` 关联 → 删除旧 exe。
|
||||
- 发布前必须关闭正在运行的 MD Preview。
|
||||
- 仅 Nutstore 这一个仓库外目标;其他仓库外修改仍需先询问用户。
|
||||
|
||||
## 5. 参考
|
||||
|
||||
- `docs/HANDOFF.md`:工具链、构建、完整性级别、验收。
|
||||
- `docs/STATUS.md`:当前进度、已确认决策、下一步。
|
||||
- `docs/migration-2026-11-02.md`:Low 工作区迁移与目录移动步骤。
|
||||
- `docs/roadmap.md`:功能方案与验收标准。
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
# agent/ — MD Preview 维护者工作区
|
||||
|
||||
这里是本项目的“Agent 附属区”:文档、构建/冒烟脚本、测试夹具与验证记录。应用代码仍在 `src/`。
|
||||
这里是本项目的“Agent 附属区”:文档、构建/冒烟/发布脚本、测试夹具与验证记录。应用代码仍在 `src/`。
|
||||
|
||||
## 规则
|
||||
|
||||
维护本仓库前先读 [`AGENTS.md`](AGENTS.md):**最高优先级是工作区边界——任何工作区外的文件修改都必须先停下询问用户。**
|
||||
维护本仓库前先读 [`AGENTS.md`](AGENTS.md):**最高优先级是仓库边界——任何仓库外的文件修改都必须先停下询问用户。**
|
||||
|
||||
## 目录
|
||||
|
||||
| 路径 | 用途 |
|
||||
|---|---|
|
||||
| `AGENTS.md` | Agent 运行规则(工作区边界、改动流程) |
|
||||
| `docs/HANDOFF.md` | 主交接文档(工具链、构建、坑、验收) |
|
||||
| `AGENTS.md` | Agent 运行规则(仓库边界、改动流程) |
|
||||
| `docs/HANDOFF.md` | 主交接文档(工具链、构建、完整性级别、验收) |
|
||||
| `docs/migration-2026-11-02.md` | Low 工作区迁移与目录移动步骤 |
|
||||
| `docs/scan-2026-10-21.md` | 代码扫描:残留、bug、修复建议 |
|
||||
| `docs/roadmap.md` | 功能路线图与验收标准 |
|
||||
| `scripts/build.ps1` | release 构建 → 固定 exe 路径 → 校验 |
|
||||
| `scripts/build.ps1` | 开发构建(cargo test + build --release + 校验) |
|
||||
| `scripts/publish.ps1` | 用户手动发布到 Nutstore(Medium) |
|
||||
| `tests/smoke.ps1` | cargo test + 关联检查 + 可选隔离启动 |
|
||||
| `tests/fixtures/` | 手工/冒烟用 Markdown 样例 |
|
||||
| `reports/` | 验证记录(文本;截图放 `agent/tmp/`,不入库) |
|
||||
@@ -22,28 +24,31 @@
|
||||
|
||||
## 不变量
|
||||
|
||||
1. **产物路径固定**:`D:\Scripts\md-preview\MD-Preview-windows-x64.exe`。默认 `.md` 打开方式指向它,不要改名/移动。
|
||||
1. **仓库根**:`D:\Scripts\md-preview\AgentLowWorking`。默认 `.md` 打开方式指向 `C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe`。
|
||||
2. **离线**:不引入联网、自动更新、遥测;外部链接交给系统浏览器。
|
||||
3. **轻量**:不为小功能引入新库;优先原生 JS/CSS 与已有依赖。
|
||||
4. **测试**:`cargo test` 必须保持全绿;UI 行为用 `tests/fixtures` 做手工/冒烟回归。
|
||||
|
||||
## 常用命令
|
||||
|
||||
```powershell
|
||||
# 构建并校验(推荐)
|
||||
~~~powershell
|
||||
# 开发构建(DSH workspace-write 可运行)
|
||||
.\agent\scripts\build.ps1
|
||||
|
||||
# 只跑测试
|
||||
cargo test
|
||||
|
||||
# 冒烟(含注册表与可选启动)
|
||||
# 冒烟(发布后;含注册表与可选启动)
|
||||
.\agent\tests\smoke.ps1 -Launch
|
||||
```
|
||||
|
||||
# 发布(必须由用户在自己的普通 PowerShell 运行)
|
||||
.\agent\scripts\publish.ps1
|
||||
~~~
|
||||
|
||||
## 环境注意
|
||||
|
||||
工作区是 **Medium** 完整性级别。DSH 用 `workspace-write` 打开时进程是 **Low**,会写不动(EPERM / os error 5)。改代码、编译、替换 exe 需要 DSH 以 **danger-full-access** 运行,或在你自己的普通 PowerShell 里执行。详见 `docs/HANDOFF.md` 第 4 节。
|
||||
仓库整棵树是 **Low** 完整性级别,DSH 以 `workspace-write` 运行即可改代码/编译。构建产物 `target\release\md-preview.exe` 也是 Low,不能直接双击;开发冒烟用 `MD_PREVIEW_CONFIG_DIR` 指到仓库内目录。发布由用户手动运行 `publish.ps1` 升到 Medium 并复制到 Nutstore。详见 `docs/migration-2026-11-02.md`。
|
||||
|
||||
## Git
|
||||
|
||||
仓库由用户自行初始化(私有)。`backup/` 与成品 exe 不入库;`agent/` 全量入库。
|
||||
仓库由用户自行初始化(私有)。`backup/`、成品 exe、`test/` 不入库;`agent/` 全量入库(`agent/tmp/` 与日志/截图除外)。
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
# MD Preview 本地维护交接
|
||||
|
||||
> 最后更新:2026-10-21
|
||||
> 最后更新:2026-11-02
|
||||
> 维护范围:仅 Windows 本地构建,目标产物 `MD-Preview-windows-x64.exe`
|
||||
>
|
||||
> **Agent 必须先读 `agent/AGENTS.md`**:最高优先级是工作区边界,任何工作区外的文件修改都要先停下询问用户。
|
||||
|
||||
> **2026-11-02 迁移(重要)**:代码仓库移到 `D:\Scripts\md-preview\AgentLowWorking`;DSH 工作区仍是父目录 `D:\Scripts\md-preview`;
|
||||
> 仓库整棵树为 **Low**,DSH 用 **workspace-write** 即可改代码/编译;
|
||||
> 成品只发布到 `C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe`(Medium),仓库内不再放 exe。
|
||||
> 本文第 4 节等处的 “Medium / danger-full-access” 是旧模型;以 `agent/docs/migration-2026-11-02.md` 和 `AGENTS.md` 为准。
|
||||
|
||||
## 1. 当前状态
|
||||
|
||||
- 上游版本:`md-preview 1.4.2`(源码来自 `backup/md-preview-master.zip`)
|
||||
- 改造目标:**本地预览器,不联网、不自动更新**;预览/编辑/标签/会话等功能与上游一致
|
||||
- 源码规模:`src/main.rs` 4354 行、`src/session.rs` 281 行、`src/instance.rs` 207 行
|
||||
- 当前产物:`D:\Scripts\md-preview\MD-Preview-windows-x64.exe`
|
||||
- 大小 5,501,440 字节
|
||||
- SHA256 `F76BC3963BA13BBFC8259BC2B4E3D24468C34E3C9E26491D364D5D364BEDE96C`
|
||||
- 测试:`cargo test` → 43 passed, 0 failed
|
||||
- 源码规模:`src/main.rs` 5535 行、`src/session.rs` 488 行、`src/instance.rs` 207 行
|
||||
- 当前产物(2026-11-02 起):`C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe`
|
||||
- 当前发布版见 `STATUS.md` 第 2 节(v1.4.2-local.5,5,505,024 字节)
|
||||
- 仓库内不再放成品 exe;旧 `D:\Scripts\md-preview\MD-Preview-windows-x64.exe` 由 `publish.ps1` 删除
|
||||
- 测试:`cargo test` → 62 passed, 0 failed(2026-11-03)
|
||||
- 编译警告:1 个 `dead_code`(macOS 专用事件枚举,Windows 下未构造),可忽略
|
||||
- 2026-10-21 的全部功能需求已完成并部署,细节与实现要点见第 14 节。
|
||||
|
||||
@@ -36,62 +41,31 @@ DSH 的 pwsh 可能没有继承 PATH,构建时用完整路径:
|
||||
|
||||
## 3. 构建与运行
|
||||
|
||||
```powershell
|
||||
cd D:\Scripts\md-preview
|
||||
cargo build --release
|
||||
copy .\target\release\md-preview.exe .\MD-Preview-windows-x64.exe
|
||||
.\MD-Preview-windows-x64.exe
|
||||
```
|
||||
~~~powershell
|
||||
cd D:\Scripts\md-preview\AgentLowWorking
|
||||
.\agent\scripts\build.ps1 # 开发构建(cargo test + build --release)
|
||||
# 发布由用户在自己的普通 PowerShell 运行:
|
||||
.\agent\scripts\publish.ps1
|
||||
~~~
|
||||
|
||||
- 增量构建约 15 秒,清理后约 1–2 分钟(16 核,release 开启 LTO + opt-level=z)
|
||||
- 依赖锁定在 `Cargo.lock`(435 个包),**不要随手 `cargo update`**
|
||||
- 调试可 `cargo build`(debug,快),产物在 `target\debug\`
|
||||
|
||||
## 4. ⚠️ 必读:完整性级别与 os error 5
|
||||
## 4. ⚠️ 必读:Low 工作区与发布(2026-11-02 起)
|
||||
|
||||
这是本次维护踩过最大的坑,务必先读:
|
||||
- 仓库根 `D:\Scripts\md-preview\AgentLowWorking` 整棵树是 **Low** 完整性级别;DSH 以 **workspace-write** 运行即可改代码、编译、commit。
|
||||
- 从 Low 工作区编译出的 exe 也是 Low:启动后写 `%LOCALAPPDATA%\md-preview\instance.lock` 会被 no-write-up 拒绝(os error 5)。这不是应用 bug。
|
||||
- 开发冒烟不要双击 `target\release\md-preview.exe`,用隔离配置目录:
|
||||
|
||||
- DSH 的 **workspace-write** 模式会把子进程降为 **Low 完整性级别(Low IL)**,并期望工作区文件也是 Low。
|
||||
- 从被标成 Low 的目录编译出的 exe 会继承 Low 标签;启动后写 `%LOCALAPPDATA%\md-preview\instance.lock` 会被 Windows 的 no-write-up 拒绝,弹窗:
|
||||
~~~powershell
|
||||
$env:MD_PREVIEW_CONFIG_DIR="$PWD\target\smoke"
|
||||
.\target\release\md-preview.exe path\to\file.md
|
||||
~~~
|
||||
|
||||
```
|
||||
Could Not Open MD Preview
|
||||
拒绝访问 (os error 5)
|
||||
```
|
||||
|
||||
- 这不是应用 bug。同一个 exe 复制到 `D:\Installer\MD-Preview\` 就能正常运行(目标目录是 Medium)。
|
||||
|
||||
当前仓库状态:工作区已设为 **Medium**,DSH 必须以 **danger-full-access** 运行才能编辑/编译此目录。
|
||||
如果你用 workspace-write 打开本仓库,DSH 进程是 Low,会写不动 Medium 工作区(表现是编辑/编译全部 Access denied)。
|
||||
|
||||
### 如果 exe 又报 os error 5
|
||||
|
||||
```powershell
|
||||
# 方案 1:把工作区(含 target)改回 Medium 后重建
|
||||
icacls D:\Scripts\md-preview /setintegritylevel "(OI)(CI)Medium" /T /C
|
||||
cargo build --release
|
||||
|
||||
# 方案 2:不改标签,直接把 exe 复制到普通目录再运行
|
||||
copy .\target\release\md-preview.exe D:\Installer\MD-Preview\MD-Preview-windows-x64.exe
|
||||
```
|
||||
|
||||
检查标签:
|
||||
|
||||
```powershell
|
||||
icacls .\MD-Preview-windows-x64.exe # 应显示 Medium,不能是 Low
|
||||
```
|
||||
|
||||
### 若坚持用 workspace-write 沙箱
|
||||
|
||||
工作区必须保持 Low,DSH 才能写;构建输出必须放到工作区外(否则 exe 又是 Low):
|
||||
|
||||
1. `icacls D:\Scripts\md-preview /setintegritylevel "(OI)(CI)Low" /T /C`
|
||||
2. 项目内 `.cargo\config.toml`:
|
||||
```toml
|
||||
[build]
|
||||
target-dir = "D:/MD-Preview-build/target"
|
||||
```
|
||||
3. 在**自己的普通 PowerShell**里构建,再把 exe 复制到 `D:\Installer\MD-Preview\`
|
||||
- 发布:用户在**普通 PowerShell(Medium)**运行 `agent\scripts\publish.ps1`。脚本会复制到 Nutstore、设 Medium、校验 SHA256、刷新 `.md` 关联,最后删除旧 exe。
|
||||
- 如果发布后仍报 os error 5:`icacls <Nutstore exe> | Select-String 'Mandatory Label'` 应为 Medium;确认不是从 Low 目录直接启动。
|
||||
- 不要再把仓库改回 Medium,也不要为了改代码申请 danger-full-access。
|
||||
|
||||
## 5. 已删除的联网/更新功能(不要加回来)
|
||||
|
||||
@@ -114,8 +88,10 @@ python -c "d=open(r'MD-Preview-windows-x64.exe','rb').read(); print(d.count(b'ap
|
||||
|
||||
## 6. 保留的功能(回归时必须覆盖)
|
||||
|
||||
- 多标签、会话恢复、最近文件、缺失文件标签与重新定位
|
||||
- 多标签、最近文件、缺失文件标签与重新定位
|
||||
- 编辑模式与滚动位置按标签记忆:切回标签恢复离开时的模式与位置(2026-11-03)
|
||||
- Markdown 预览(GFM、表格、任务列表、front matter、GitHub Alerts、高亮)
|
||||
- 文档类型只认 `.md/.markdown/.mdown/.mkd`(2026-11-03 起不再打开 `.txt`)
|
||||
- 源码编辑 + 700ms 防抖自动保存,关闭前 flush
|
||||
- 查找(`Ctrl+F`;工具栏的 Find 按钮已移除)、打印、正文缩放 50%–300%(Ctrl+滚轮 / Ctrl± / Ctrl+0)、滚动进度保持
|
||||
- 标题 hover 折叠(H1–H6;点 H2 折到下一个 H2、点 H3 折到下一个 H3;查找自动展开;打印全展开;不持久化)
|
||||
@@ -129,30 +105,23 @@ python -c "d=open(r'MD-Preview-windows-x64.exe','rb').read(); print(d.count(b'ap
|
||||
|
||||
## 7. 目录结构
|
||||
|
||||
```
|
||||
D:\Scripts\md-preview
|
||||
├─ Cargo.toml / Cargo.lock / build.rs
|
||||
├─ src/main.rs 界面、页面模板、渲染、事件循环、Windows 集成(4354 行)
|
||||
├─ src/session.rs 标签会话持久化
|
||||
├─ src/instance.rs 单实例锁与本地端口转发
|
||||
├─ assets/ 8 个被 include_str!/include_bytes! 内嵌的资源
|
||||
│ ├─ icon.ico
|
||||
│ ├─ enhance/preview-enhance.js
|
||||
│ ├─ hljs/(highlight.min.js、delphi、vs-dark.css)
|
||||
│ ├─ katex/…
|
||||
│ └─ mermaid/mermaid.min.js
|
||||
├─ backup/md-preview-master.zip 上游源码备份(3.77 MB,本地保留,不入 git)
|
||||
├─ MD-Preview-windows-x64.exe 构建产物(不入 git;默认打开方式指向此路径)
|
||||
├─ target/ 编译缓存(不入 git,可删)
|
||||
├─ agent/ Agent 文档 / 脚本 / 测试夹具
|
||||
│ ├─ AGENTS.md Agent 运行规则(最高优先级)
|
||||
│ ├─ README.md
|
||||
│ ├─ docs/{HANDOFF.md, STATUS.md, scan-2026-10-21.md, roadmap.md}
|
||||
│ ├─ scripts/build.ps1
|
||||
│ └─ tests/{smoke.ps1, fixtures/}
|
||||
├─ README.md 入口,指向 agent/docs/HANDOFF.md
|
||||
├─ LICENSE / .gitignore / .gitattributes
|
||||
```
|
||||
~~~
|
||||
D:\Scripts\md-preview\
|
||||
├─ AgentLowWorking\ ← 仓库根(整棵树 Low)
|
||||
│ ├─ Cargo.toml / Cargo.lock / build.rs
|
||||
│ ├─ src/ 应用源码
|
||||
│ ├─ assets/ 内嵌资源
|
||||
│ ├─ backup/ 上游源码备份(不入 git)
|
||||
│ ├─ target/ 编译缓存(不入 git,可删)
|
||||
│ ├─ agent/ Agent 文档 / 脚本 / 测试夹具
|
||||
│ │ ├─ AGENTS.md
|
||||
│ │ ├─ docs/{HANDOFF.md, STATUS.md, migration-2026-11-02.md, ...}
|
||||
│ │ ├─ scripts/{build.ps1, publish.ps1}
|
||||
│ │ └─ tests/{smoke.ps1, fixtures/}
|
||||
│ ├─ README.md / LICENSE / .gitignore / .gitattributes
|
||||
│ └─ test/ 本机草稿(已忽略)
|
||||
└─ MD-Preview-windows-x64.exe 旧产物;publish.ps1 成功后删除
|
||||
~~~
|
||||
|
||||
Git 由用户自行初始化(私有仓库;`backup/` 与成品 exe 不入 git)。`.gitignore` 已忽略 `/target/`、`MD-Preview-windows-x64.exe`、`/backup/` 与临时日志。
|
||||
|
||||
@@ -160,7 +129,7 @@ Git 由用户自行初始化(私有仓库;`backup/` 与成品 exe 不入 git
|
||||
|
||||
`%LOCALAPPDATA%\md-preview\`:
|
||||
|
||||
- `session.json`:打开的标签与 active tab
|
||||
- 旧 `session.json`:已停用,不读不写(可手动删除)
|
||||
- `recent-files.txt`:最近文件(最多 8 个)
|
||||
- `window.geom` / `theme.txt` / `zoom.txt`(正文缩放,50–300)
|
||||
- `instance.lock` / `instance.json`:单实例
|
||||
@@ -183,21 +152,22 @@ Git 由用户自行初始化(私有仓库;`backup/` 与成品 exe 不入 git
|
||||
|
||||
## 11. 验收清单
|
||||
|
||||
```powershell
|
||||
cd D:\Scripts\md-preview
|
||||
cargo test # 43 passed
|
||||
cargo build --release # Finished
|
||||
.\MD-Preview-windows-x64.exe path\to\file.md
|
||||
```
|
||||
~~~powershell
|
||||
cd D:\Scripts\md-preview\AgentLowWorking
|
||||
cargo test
|
||||
.\agent\scripts\build.ps1
|
||||
# 发布由用户在自己的普通 PowerShell 运行:
|
||||
.\agent\scripts\publish.ps1
|
||||
~~~
|
||||
|
||||
手工检查:
|
||||
|
||||
- [ ] 窗口标题为 `文件名 — MD Preview`
|
||||
- [ ] 工具栏只有 编辑 / 缩放(无 Update / Open / Print / Find)
|
||||
- [ ] 多标签切换、关闭、会话恢复
|
||||
- [ ] 多标签切换、关闭;切回标签仍保持编辑模式和滚动位置
|
||||
- [ ] 编辑后 700ms 自动保存,关闭前落盘
|
||||
- [ ] 第二个实例打开文件时,第一个实例新增标签、第二个退出
|
||||
- [ ] `icacls MD-Preview-windows-x64.exe` 为 Medium
|
||||
- [ ] `icacls "C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe"` 为 Medium
|
||||
|
||||
## 12. 追加修复(2026-10-21 下午)
|
||||
|
||||
@@ -296,7 +266,7 @@ cargo build --release # Finished
|
||||
### 14.3 验证配方
|
||||
|
||||
```powershell
|
||||
cargo test # 43 passed
|
||||
cargo test # 62 passed
|
||||
.\agent\scripts\build.ps1 # 先关闭正在运行的实例;会打印 SHA256 并校验 Medium
|
||||
```
|
||||
|
||||
@@ -317,7 +287,7 @@ cargo test # 43 passed
|
||||
|
||||
- Gitea Release `v1.4.2-local.1`:https://git.wucl12.cn/wucl12/md-preview/releases/tag/v1.4.2-local.1
|
||||
- 附件 `MD-Preview-windows-x64.exe`(5,501,440 字节,SHA256 `F76BC396…BEDE96C`),发布说明见 `agent/docs/release-notes-v1.4.2-local.1.md`。
|
||||
- 发版流程:改版本 / 写 release notes → `build.ps1` → 推 tag 或用 Gitea API 建 release 并上传 exe。API 需要 `write:repository` scope 的 token,用完即删。
|
||||
- 发版流程:改版本 / 写 release notes → `build.ps1` → 用户在普通 PowerShell 运行 `publish.ps1` → 推 tag / 用 Gitea API 建 release 并上传 Nutstore 那份 exe。API 需要 `write:repository` scope 的 token,用完即删。
|
||||
|
||||
### 14.6 下一次开工检查
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
# 项目状态(滚动更新)
|
||||
|
||||
> 最后更新:2026-10-28
|
||||
> 最后更新:2026-11-03
|
||||
> 用途:上下文压缩/交接后快速恢复。详细背景见 AGENTS.md、HANDOFF.md、scan-2026-10-21.md、roadmap.md。
|
||||
>
|
||||
> **当前:单进程多窗口 + 标签拖拽/菜单/多显示器修复完成;固定 exe 已替换为 2026-10-28 本地 release(5,507,584 字节,SHA256 0BFF7302…);Gitea release v1.4.2-local.3 准备发布。53 个测试通过。**
|
||||
> **当前(2026-11-03):仓库根 `D:\Scripts\md-preview\AgentLowWorking`,整棵树 Low、DSH workspace-write 可编译;成品只发布到 Nutstore;仓库内 exe 已删除。功能基线 v1.4.2-local.5 + 本地未发布修复(62 tests)。**
|
||||
>
|
||||
> 2026-11-03 已做:编辑模式与滚动位置改为按标签记忆;不再把 `.txt` 当文档;clippy 清零、`cargo fmt` 通过;AGENTS 允许拆模块/新增文件。下一步是讨论中的“编辑区富文本样式”。
|
||||
|
||||
## 1. 仓库
|
||||
|
||||
@@ -32,21 +34,34 @@
|
||||
- `85b20ec` fix: 唯一标签时禁用“在新窗口打开”
|
||||
- `f9ccce0` fix: 处理独立评审发现的窗口归属、detach 回滚、聚焦 dirty、关闭语义、RecentChanged
|
||||
- `9ae2c13` fix: 新窗口留在源显示器、去掉多余 focus、标签拖拽、菜单路径/打开所在位置
|
||||
- 若干 docs 提交(状态/路线图/HANDOFF、local.3 release notes)
|
||||
- `809b7b0` feat: 新标签页(Home 作为无路径标签、`+` 新建标签、New File、单标签隐藏标签栏)
|
||||
- `d90e47e` feat: 界面统一为英文(移除语言检测/中文文案,标签名 New Tab)
|
||||
- `8644966` feat: 编辑 Tab/Shift+Tab 缩进 + 回车跟随缩进
|
||||
- `618ac47` feat: 阅读 Find 选区填入、选区锚点、零滚动打开
|
||||
- 若干 docs 提交(状态/路线图/HANDOFF、local.3/local.4/local.5 release notes)
|
||||
- `d2b1630` chore: switch to Low workspace and Nutstore-only publish
|
||||
- `8d98b5e` fix: add UTF-8 BOM to PowerShell scripts
|
||||
- `dfe3889` fix: remember edit mode and scroll position per tab
|
||||
- `c783a6d` fix: stop treating .txt as a supported document
|
||||
- `8221eb5` chore: clear clippy warnings and tighten the build guard
|
||||
- 忽略:`/target/`、`/MD-Preview-windows-x64.exe`、`/backup/`、`/agent/reports/*.png`
|
||||
- **不变量**:exe 固定为 `D:\Scripts\md-preview\MD-Preview-windows-x64.exe`,默认 .md 打开方式指向它,不要改名/移动。
|
||||
- **不变量(2026-11-02 起)**:仓库根 `D:\Scripts\md-preview\AgentLowWorking`;成品固定为 `C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe`(Medium),默认 .md 打开方式指向它;仓库内不再放 exe。
|
||||
|
||||
## 2. 当前构建/部署状态
|
||||
|
||||
- `cargo test`:53 passed / 0 failed(2026-10-28,标签/菜单修复后)。
|
||||
- 当前固定 exe(2026-10-28 部署):
|
||||
- 大小 5,507,584 字节;版本 1.4.2.0
|
||||
- SHA256 `0BFF730209CE835B18DC1447740A1F2770EA0645577A91EB969A6215B1C2372E`
|
||||
- `cargo test`:62 passed / 0 failed(2026-11-03,per-tab 状态 + 扩展名白名单 + base64 向量)。
|
||||
- `cargo clippy --all-targets`:0 warning;`cargo fmt -- --check`:通过(2026-11-03)。
|
||||
- 当前固定 exe(2026-10-30 部署):
|
||||
- 大小 5,505,024 字节;版本 1.4.2.0
|
||||
- SHA256 `A632EF0363D04CE6F72B9779BA742681868AC31D36A7FE57E4F6D44E7BEAD988`
|
||||
- 完整性级别 Medium - OK;禁用字符串检查全 0;PE subsystem=2(GUI,无双击 cmd)。
|
||||
- 构建脚本:`agent/scripts/build.ps1 -SkipTests`
|
||||
- 上一版部署(v1.4.2-local.2):5,505,024 字节;SHA256 `7C8A3A8A...99BD95`。
|
||||
- Nutstore 镜像:工作区外的 `C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe` **尚未更新**;按规则需用户确认后再覆盖。
|
||||
- CDP 复核:折叠按钮 30×30,位于内容左侧 `-34px`(H2 实测 left=14,heading left=48),垂直居中;hover `opacity .6`;两个 SVG 折角箭头按 `collapsed` 切换。
|
||||
- 构建方式:`cargo build --release`(build.ps1 已改为 Low 工作区版,不再复制到固定路径;cargo stderr 不会再触发 Stop)。
|
||||
- 上一版(v1.4.2-local.4):5,499,392 字节;SHA256 `7134BBC68423605BE220E19DAA1D6CB679AFBB9153C526E717F50388C1A0841D`。
|
||||
- 上一版部署(v1.4.2-local.3):5,507,584 字节;SHA256 `0BFF730209CE835B18DC1447740A1F2770EA0645577A91EB969A6215B1C2372E`。
|
||||
- Nutstore 镜像:工作区外的 `C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe` 已同步为 v1.4.2-local.5(5,505,024 字节,SHA256 `A632EF03…`)。
|
||||
- CDP 复核(2026-10-30):WIP 文档 8 个“为什么”逐个选区 Ctrl+F,滚动变化均为 0px,序号 1/8–8/8 正确;4/8 按 Enter 到 5/8 正常滚动;Tab/Shift+Tab/Enter/撤销均通过。
|
||||
- CDP 复核(2026-10-28,release):New Tab 标签名、Open File / New File 按钮、单 New Tab 隐藏标签栏、`+` 新建 New Tab、首页打开文件复用标签、关闭最后文件回 New Tab、脏内容先保存;界面无中文、无 JS 异常。
|
||||
- CDP 复核(旧):折叠按钮 30×30,位于内容左侧 `-34px`(H2 实测 left=14,heading left=48),垂直居中;hover `opacity .6`;两个 SVG 折角箭头按 `collapsed` 切换。
|
||||
|
||||
## 3. 功能进度
|
||||
|
||||
@@ -65,26 +80,34 @@
|
||||
| 11 | 单进程多窗口:阶段 4 取消 session 恢复 | 完成 `e24733a`;只保留 recent;51 tests |
|
||||
| 12 | 单进程多窗口:阶段 5 标签右键新窗口 | 完成 `5740274`;先保存后移动;源窗口空则关闭;52 tests |
|
||||
| 13 | 新窗口留在源显示器 + 标签拖拽 + 菜单路径/打开所在位置 | 完成 `9ae2c13`;53 tests;固定 exe 已更新 |
|
||||
| 14 | 新标签页(New Tab):默认标签、`+` 新建、New File、单标签隐藏标签栏 | 完成并发布 v1.4.2-local.4;59 tests |
|
||||
| 15 | 界面统一为英文(移除系统语言检测/中文文案,标签名 New Tab) | 完成并发布 v1.4.2-local.4;59 tests |
|
||||
| 16 | 编辑 Tab/Shift+Tab 缩进(2 空格)+ 回车跟随缩进 | 完成,`8644966`;原生撤销保留 |
|
||||
| 17 | 阅读 Find 选区填入、选区锚点、从选区打开不滚动、视口起点 | 完成,`618ac47`;CDP 8/8 零滚动 |
|
||||
|
||||
## 4. 已确认的产品决策
|
||||
|
||||
- 缩放:Ctrl + 滚轮,步进 5%,范围 50%–300%,90ms 节流,无鼠标锚点,预览/编辑都生效;持久化到 `config_dir()/zoom.txt`。
|
||||
- 代码块**始终深色**(Visual Studio Dark),不跟随应用主题;行内代码仍跟随主题。
|
||||
- 不加主题按钮/主题切换(Windows 版没有主题 UI),应用主题仍跟随系统。
|
||||
- 工具栏只剩 编辑 / 缩放;Find 按钮已删,`Ctrl+F` 与查找条保留。
|
||||
- 工具栏只剩 Edit / Zoom;Find 按钮已删,`Ctrl+F` 与查找条保留。
|
||||
- 标题折叠:三角按钮 hover 才显示;**固定尺寸**(30px 热区、折角箭头 13.5×20,约为原二级标题实心三角的 90%),所有级别一致;点 H2 折到下一个 H2、点 H3 折到下一个 H3(含子级);**不持久化**;不做“全部折叠/展开”UI;查找命中折叠区自动展开;打印强制展开并隐藏按钮。
|
||||
- 正文/编辑区左右 padding 48px。
|
||||
- **单换行按换行显示**(softbreak→`<br>`),空行仍是段落分隔;标题内不转换。这是本工具面向 AI 输出的有意方言,和严格 CommonMark 不同;硬折行的长段落会保留断点。
|
||||
- 开启 GFM 脚注与定义列表;UTF-8 BOM 在渲染前忽略。
|
||||
- 编辑模式保留 700ms 自动保存 + `Ctrl+S` 立即保存。
|
||||
- 多窗口:单进程、每窗口一个 WebView2/DocumentSession;标签右键“在新窗口打开”或上下拖动标签(>24px)为移动语义;同一文件只开一个;不恢复 session,只保留 recent;非最后窗口关闭最后一个标签会关闭窗口,最后窗口保留空窗口;Cmd+Q 仅 macOS。详见 `agent/docs/design-single-process-multi-window.md`。
|
||||
- 多窗口:单进程、每窗口一个 WebView2/DocumentSession;标签右键“在新窗口打开”或上下拖动标签(>24px)为移动语义;同一文件只开一个;不恢复 session,只保留 recent;非最后窗口关闭最后一个标签会关闭窗口,最后窗口关闭最后一个文件标签会回到 New Tab;Cmd+Q 仅 macOS。详见 `agent/docs/design-single-process-multi-window.md`。
|
||||
- 新标签页(New Tab,2026-10-28 确认):New Tab 是**无路径的普通标签**(可多个,浏览器新标签页语义);`+` 追加并激活 New Tab;新标签页上 Open File / Recent / New File / 拖入文件会复用当前 New Tab;关闭最后一个文件标签回到 New Tab;只有 New Tab 时隐藏标签栏(`HIDE_SINGLE_HOME_TAB = true`,一行可关);New Tab 不可拖出/不可新窗口打开、不监听文件、不参与查重;New File 按钮取代原 `+` 的建文件语义,`Ctrl+N` 仍新建文件。
|
||||
- 界面语言(2026-10-28 确认):**只提供英文界面**;移除 `Lang` / `detect_lang` 和中文 `Strings`,删除 `sys-locale` 依赖;标签名从“首页/Home”改为“New Tab”;不随系统语言切换。
|
||||
- 编辑缩进(2026-10-30 确认):Tab 固定插入 2 个空格,Shift+Tab 反缩进;多行选区整块处理;不插入字面 Tab;保留 textarea 原生撤销;输入法组合期间不拦截。回车复制当前行光标前前导空白,空行不继续叠加;列表续行暂不做。
|
||||
- 阅读 Find(2026-10-30 确认):有选区时 Ctrl+F 自动填入;多行取第一行非空内容;从选区打开时不滚动、不展开折叠,只高亮并显示序号;点下一个/上一个或按 Enter 才滚动;无选区的新查询从当前视口开始;下方无匹配时选上方最近匹配。编辑模式 Find 继续用 WebView2 原生查找,不统一。
|
||||
- 新窗口位置:源窗口当前显示器内 +28,+28 偏移并 clamp;不逐窗口恢复位置。
|
||||
- 标签右键菜单:顶部路径(中间省略,保留开头和文件名),第一项“打开文件所在位置”,第二项“在新窗口打开”;右键时临时移除标签 tooltip。
|
||||
- 标签右键菜单:顶部路径(中间省略,保留开头和文件名),第一项 Show in Explorer,第二项 Open in New Window;右键时临时移除标签 tooltip。
|
||||
|
||||
## 5. 保存失败(只读文件)处理
|
||||
|
||||
- 自动保存失败时:弹一次警告,调用 `window.__markSaveBlocked()` 暂停该文件的自动保存,标签保持 dirty,不再每 700ms 弹窗。
|
||||
- 关闭窗口失败时:弹一次 Ok/Cancel「无法保存,仍要关闭并丢弃修改?」,Ok 直接退出,Cancel 留在应用;不会再出现“关不掉”。
|
||||
- 关闭窗口失败时:弹一次 Ok/Cancel 对话框(标题 “Could Not Save”),Ok 直接退出,Cancel 留在应用;不会再出现“关不掉”。
|
||||
- 已进入 blocked 状态的标签,关闭/切换时用 `window.confirm` 确认是否丢弃修改(确认后发送不带内容的 tab-action)。
|
||||
- 文件本身**没有长期占用**:保存是 `fs::write` 打开-写入-关闭,watcher 只监听目录;只在保存瞬间需要写权限。
|
||||
|
||||
@@ -94,26 +117,26 @@
|
||||
- 阶段 2(`39deeac`):抽出 build_webview 工厂;共享 WebContext;内部 IPC `new-window` 可创建第二个空窗口;新窗口 +28,+28 偏移、焦点切换、主窗口几何保留、16 上限;关闭单个窗口不再退出整个进程。
|
||||
- 阶段 3(`e24733a`):`find_open_path` 跨窗口查重;双击/转发打开已在其他窗口的文件时,聚焦该窗口和标签,不再重复打开;若当前标签有未保存修改且目标不是当前标签,不强行切换,避免丢编辑。
|
||||
- 阶段 4(`e24733a`):启动不再读 `session.json`,不再写 session;只保留 recent-files.txt。旧 session.json 留在磁盘但不主动删除。删除了 session 往返测试,52→51。
|
||||
- 阶段 5(`5740274`):标签右键自定义菜单“在新窗口打开”;移动语义。active 且 dirty 时由 JS 附带内容、Rust 先写盘再移动;inactive 且 dirty 时拒绝移动并提示;inactive 且 clean 时先 activate 再移动;源窗口最后一个标签移出后关闭源窗口;新窗口只含被移动标签;失败保留源标签。
|
||||
- 阶段 5(`5740274`):标签右键自定义菜单 Open in New Window;移动语义。active 且 dirty 时由 JS 附带内容、Rust 先写盘再移动;inactive 且 dirty 时拒绝移动并提示;inactive 且 clean 时先 activate 再移动;源窗口最后一个标签移出后关闭源窗口;新窗口只含被移动标签;失败保留源标签。
|
||||
- 修复(`85b20ec`):只有 1 个标签时菜单项置灰禁用;2 个及以上才可点。
|
||||
- 标签/显示修复(`9ae2c13`):
|
||||
- 新窗口用源窗口 `current_monitor()` + 物理坐标,修复在第二屏 detach 却跳到主屏;
|
||||
- `OpenPaths` 查重前不再无条件 focus,重复打开只 focus 最终目标;
|
||||
- 标签上下拖动 >24px 新窗口;唯一标签禁止;拖动后抑制 click;
|
||||
- 菜单更紧凑,顶部显示中间省略路径;新增“打开文件所在位置”;
|
||||
- 菜单更紧凑,顶部显示中间省略路径;新增 Show in Explorer;
|
||||
- 菜单打开时临时移除标签 tooltip,关闭后恢复。
|
||||
- 评审修复(`f9ccce0`):
|
||||
- `OpenPaths` 携带目标 WindowId;拖放/导航/IPC/Ready 不再统一落到 active window;批次 target 固定;
|
||||
- detach 不再在创建新窗口前激活源 session;创建/移除失败不会改写源 active;
|
||||
- `focus_open_tab` 在源 active 或目标标签 dirty 时拒绝切换并提示,不再静默丢焦点;
|
||||
- 非最后窗口关闭最后一个标签会关闭该窗口;最后窗口保留空窗口;
|
||||
- 非最后窗口关闭最后一个标签会关闭该窗口;最后窗口关闭最后一个文件标签会回到 New Tab;
|
||||
- `RecentChanged` 不再清空有标签窗口;
|
||||
- 移除了不可达的内部 `new-window` 路径。
|
||||
- 用户可见变化:启动不再恢复上次标签;同文件重复打开聚焦已有窗口/标签;标签右键现在有“在新窗口打开”(中文界面为“在新窗口打开”),这是第一个普通用户可操作的多窗口入口。
|
||||
- 用户可见变化:启动不再恢复上次标签;同文件重复打开聚焦已有窗口/标签;标签右键现在有 Open in New Window,这是第一个普通用户可操作的多窗口入口。
|
||||
- 已验证:菜单显示;active dirty 保存后再移动;inactive clean 移动且源窗口保留;源窗口唯一标签移动后源窗口关闭;新窗口正常显示文件。
|
||||
- 独立评审报告:`agent/reports/multi-window-update-report-2026-10-28.md`;评审回应:`agent/reports/multi-window-review-response-2026-10-28.md`。
|
||||
- Release notes:`agent/docs/release-notes-v1.4.2-local.3.md`;固定 exe 已是该构建。
|
||||
- 阶段 6:README/状态/release notes 已更新;等待 push + Gitea release。
|
||||
- 阶段 6:README/状态/release notes 已更新,已 push 并发布 Gitea release v1.4.2-local.3。
|
||||
- 固定 exe 已是最新构建(53 tests),不再有旧版。
|
||||
|
||||
## 6. 已知问题 / 候选修复
|
||||
@@ -135,15 +158,17 @@
|
||||
|
||||
```powershell
|
||||
cargo test
|
||||
.\agent\scripts\build.ps1 # 需要先关闭正在运行的 MD Preview
|
||||
.\agent\tests\smoke.ps1 -Launch
|
||||
.\agent\scripts\build.ps1 # 开发构建;产物在 target\release\
|
||||
.\agent\tests\smoke.ps1 -Launch # 发布后冒烟(Nutstore exe)
|
||||
.\agent\scripts\publish.ps1 # 发布:用户在自己的普通 PowerShell 运行
|
||||
```
|
||||
|
||||
## 8. 环境与规则
|
||||
|
||||
- **最高优先级**:`agent/AGENTS.md` —— 只在工作区内改文件;工作区外的任何修改先停下询问用户。
|
||||
- 工作区是 Medium 完整性级别;DSH 需 danger-full-access 才能改/编译(workspace-write 会 EPERM / os error 5)。
|
||||
- 不要把工作区改成 Low。
|
||||
- **最高优先级**:`agent/AGENTS.md` —— 只在仓库内改文件;仓库外的任何修改先停下询问用户。
|
||||
- 仓库根 `D:\Scripts\md-preview\AgentLowWorking` 整棵树是 **Low**;DSH 用 **workspace-write** 即可改/编译。
|
||||
- 构建产物是 Low,不能直接双击;冒烟用 `MD_PREVIEW_CONFIG_DIR` 指到仓库内。
|
||||
- 发布由用户手动运行 `publish.ps1`(Medium);Agent 不运行发布脚本、不改注册表。
|
||||
- `git clean -xdf` 会删除被忽略的 backup 与 exe。
|
||||
- 截图/录屏等二进制验证产物**不入库**:放 `agent/tmp/` 或 `target/tmp/`,看完即删;`agent/reports/` 只留文本。
|
||||
- `%TEMP%` 历史测试残留已于 2026-10-21 16:38 经用户同意清理;之后的测试/构建把 TEMP/TMP 指向 `target\tmp` 与 `target\test-tmp`。
|
||||
@@ -151,12 +176,43 @@ cargo test
|
||||
## 9. 发布(Gitea)
|
||||
|
||||
- 实例 Gitea 24.5.4,仓库私有。
|
||||
- Release `v1.4.2-local.2`(最新):https://git.wucl12.cn/wucl12/md-preview/releases/tag/v1.4.2-local.2
|
||||
- Release `v1.4.2-local.5`(最新,2026-10-30):https://git.wucl12.cn/wucl12/md-preview/releases/tag/v1.4.2-local.5
|
||||
- 附件 `MD-Preview-windows-x64.exe`,5,505,024 字节
|
||||
- SHA256 `7C8A3A8AE1DF4D93714F080663641EC1D7C9CD4B44476D90D020A2640999BD95`(已下载复核一致)
|
||||
- 正文来源:`agent/docs/release-notes-v1.4.2-local.2.md`
|
||||
- SHA256 `A632EF0363D04CE6F72B9779BA742681868AC31D36A7FE57E4F6D44E7BEAD988`(已下载复核一致)
|
||||
- 正文来源:`agent/docs/release-notes-v1.4.2-local.5.md`
|
||||
- Release `v1.4.2-local.4`(上一版,2026-10-28):https://git.wucl12.cn/wucl12/md-preview/releases/tag/v1.4.2-local.4
|
||||
- 附件 5,499,392 字节;SHA256 `7134BBC68423605BE220E19DAA1D6CB679AFBB9153C526E717F50388C1A0841D`(已下载复核一致)
|
||||
- Release `v1.4.2-local.3`(上一版):https://git.wucl12.cn/wucl12/md-preview/releases/tag/v1.4.2-local.3
|
||||
- 附件 5,507,584 字节;SHA256 `0BFF7302...2372E`
|
||||
- 正文来源:`agent/docs/release-notes-v1.4.2-local.3.md`
|
||||
- Release `v1.4.2-local.2`(上一版):https://git.wucl12.cn/wucl12/md-preview/releases/tag/v1.4.2-local.2
|
||||
- 附件 5,505,024 字节;SHA256 `7C8A3A8A...99BD95`
|
||||
- Release `v1.4.2-local.1`(上一版):https://git.wucl12.cn/wucl12/md-preview/releases/tag/v1.4.2-local.1
|
||||
- 附件 5,501,440 字节;SHA256 `F76BC396...BEDE96C`
|
||||
- 仓库描述与 topics 已通过 API 设置(topics:windows, markdown, markdown-preview, rust, webview2, offline, desktop-app)。
|
||||
- **Gitea token 位置**:`C:\Users\wucl1\.gitea-token`(工作区外;保留,不要提交/删除;读取后不要打印内容)。
|
||||
- 工作区内的 `.gitea-token` 旧路径已 gitignore;以后优先使用上面的用户目录文件。
|
||||
|
||||
## 10. 2026-11-02 迁移(Low 工作区)
|
||||
|
||||
- 仓库根:`D:\Scripts\md-preview\AgentLowWorking`(整棵树 Low)。
|
||||
- DSH 工作区仍是父目录 `D:\Scripts\md-preview`;代码在子目录 `AgentLowWorking`。
|
||||
- DSH 以 `workspace-write` 运行;不再需要 danger-full-access。
|
||||
- 开发构建:`.\agent\scripts\build.ps1`(产物 `target\release\md-preview.exe` 是 Low)。
|
||||
- 开发冒烟:`$env:MD_PREVIEW_CONFIG_DIR="$PWD\target\smoke"; .\target\release\md-preview.exe <file>`。
|
||||
- 发布:用户在自己的普通 PowerShell(Medium)运行 `.\agent\scripts\publish.ps1`;脚本复制到 Nutstore、设 Medium、校验 SHA256、刷新 `.md` 关联、删除旧 exe。
|
||||
- 仓库内不再放成品 exe;默认打开指向 Nutstore。
|
||||
- 迁移步骤与回滚见 `agent/docs/migration-2026-11-02.md`。
|
||||
|
||||
## 11. 2026-11-03 维护与待决策
|
||||
|
||||
- 已确认并实现(未发布):
|
||||
- 编辑模式按标签记忆(原先属于窗口);切换标签恢复该标签离开时的编辑/阅读状态;detach 保留编辑状态。
|
||||
- 滚动位置按标签记忆(相对比例,抗缩放/回流);标签动作携带比例,滚动回报带标签 id,避免迟到回报落到新标签;编辑/阅读切换仍保持滚动。
|
||||
- `.txt` 不再作为文档类型:打开、重新定位、本地链接、命令行都只认 `md/markdown/mdown/mkd`。
|
||||
- 非 md 本地链接(pdf/png/html)仍无反应,仅记录,不处理。
|
||||
- 代码整理:`cargo fmt` 通过;clippy 7 条清零;保存写盘合并为 `save_active_file()`;`build.ps1` 的禁止字符串不再包含泛化的 `powershell`。
|
||||
- 规则调整(`agent/AGENTS.md`):仓库内新增文件/拆模块不需要事先询问;bug 修复、重构、测试、文档可直接做(每项独立提交);只有仓库外修改、发布、新第三方库(>200 KB vendored 资源)和不变量变化需要先问。
|
||||
- 下一步(讨论中,未动手):编辑区样式化——加粗、标题加粗加大、行内代码换字体。
|
||||
- 技术前提:`<textarea>` 不支持字符级样式;改字号会改变软换行与光标位置,透明叠加层只适合“同字号”样式。
|
||||
- 候选:A 透明 textarea + 样式层(只能同字号);B 自研 contenteditable 行编辑器;C 内嵌 CodeMirror 5(单文件、离线、约 +280 KB)。倾向 C,待用户确认体积与交互取舍。
|
||||
|
||||
101
agent/docs/migration-2026-11-02.md
Normal file
101
agent/docs/migration-2026-11-02.md
Normal file
@@ -0,0 +1,101 @@
|
||||
# 2026-11-02 迁移:Low 工作区 + Nutstore 单一发布
|
||||
|
||||
> 目标:DSH 以 **workspace-write(Low)** 运行就能改代码、编译、测试;成品只通过用户手动运行的 `publish.ps1` 发布到 Nutstore。
|
||||
> 执行前先读 `agent/AGENTS.md`。
|
||||
|
||||
## 1. 最终结构
|
||||
|
||||
~~~
|
||||
D:\Scripts\md-preview\
|
||||
├─ AgentLowWorking\ ← 仓库根(整棵树 Low,含 .git)
|
||||
│ ├─ src / assets / agent / target / Cargo.* / README.md ...
|
||||
│ └─ test\ 本机草稿(已 gitignore)
|
||||
└─ MD-Preview-windows-x64.exe 旧产物(Medium);publish.ps1 成功后删除
|
||||
~~~
|
||||
|
||||
- 仓库根:`D:\Scripts\md-preview\AgentLowWorking`
|
||||
- 发布产物:`C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe`(Medium)
|
||||
- 默认 `.md` 打开方式:由 `publish.ps1` 指向 Nutstore
|
||||
- 仓库内不再放 exe
|
||||
|
||||
## 2. 一次性移动(用户执行)
|
||||
|
||||
DSH 工作区保持在父目录 `D:\Scripts\md-preview`,所以**不需要关 DSH**;只要没有编辑器/进程占用仓库文件即可。如果 `Move-Item` 报“文件被占用”,再关掉 DSH/编辑器重试。
|
||||
|
||||
~~~powershell
|
||||
$old = 'D:\Scripts\md-preview'
|
||||
$new = Join-Path $old 'AgentLowWorking'
|
||||
|
||||
# 1) 创建新仓库根(继承 Low)
|
||||
New-Item -ItemType Directory -Path $new -Force | Out-Null
|
||||
|
||||
# 2) 移动除旧 exe 和新目录以外的全部内容(含 .git、target、backup、test)
|
||||
Get-ChildItem -LiteralPath $old -Force |
|
||||
Where-Object { $_.Name -notin @('AgentLowWorking', 'MD-Preview-windows-x64.exe') } |
|
||||
Move-Item -Destination $new -Force
|
||||
|
||||
# 3) 整棵树 relabel 成 Low(对目录用 /T,顶层文件也会覆盖)
|
||||
icacls $new /setintegritylevel "(OI)(CI)Low" /T /C
|
||||
|
||||
# 4) 校验:前三项 Low,最后一项 Medium
|
||||
icacls (Join-Path $new 'src\main.rs') | Select-String 'Mandatory Label'
|
||||
icacls (Join-Path $new 'Cargo.toml') | Select-String 'Mandatory Label'
|
||||
icacls (Join-Path $new '.git') | Select-String 'Mandatory Label'
|
||||
icacls (Join-Path $old 'MD-Preview-windows-x64.exe') | Select-String 'Mandatory Label'
|
||||
~~~
|
||||
|
||||
移动是同卷 rename,`.git` 一起走:历史、分支、远程都不受影响,**不需要任何 rename 提交**。
|
||||
|
||||
## 3. 移动后继续
|
||||
|
||||
不需要重开 DSH;在 DSH 里 `cd AgentLowWorking`(或所有命令用绝对路径)。验证:
|
||||
|
||||
~~~powershell
|
||||
# 在 DSH 的 pwsh 里应能写
|
||||
Set-Content "$PWD\target\tmp\probe.txt" 'ok'; Get-Content "$PWD\target\tmp\probe.txt"; Remove-Item "$PWD\target\tmp\probe.txt"
|
||||
cargo test
|
||||
~~~
|
||||
|
||||
## 4. 开发循环
|
||||
|
||||
~~~powershell
|
||||
.\agent\scripts\build.ps1
|
||||
# 产物 target\release\md-preview.exe 是 Low,不能直接双击
|
||||
$env:MD_PREVIEW_CONFIG_DIR="$PWD\target\smoke"
|
||||
.\target\release\md-preview.exe path\to\file.md
|
||||
~~~
|
||||
|
||||
## 5. 发布(用户手动,普通 PowerShell)
|
||||
|
||||
~~~powershell
|
||||
cd D:\Scripts\md-preview\AgentLowWorking
|
||||
.\agent\scripts\publish.ps1
|
||||
~~~
|
||||
|
||||
脚本会:检查 Medium 权限和进程占用 → 复制到 Nutstore → 设 Medium → 校验 SHA256 → 刷新 `.md` 关联 → 删除 `D:\Scripts\md-preview\MD-Preview-windows-x64.exe`。
|
||||
|
||||
## 6. 回滚
|
||||
|
||||
如果新模型不可用:
|
||||
|
||||
1. 关掉 DSH。
|
||||
2. 把 `AgentLowWorking` 里的内容移回 `D:\Scripts\md-preview`(同样排除 `AgentLowWorking`)。
|
||||
3. `icacls D:\Scripts\md-preview /setintegritylevel "(OI)(CI)Medium" /T /C`(旧模型)。
|
||||
4. 旧 exe 若已被删除,从 Nutstore 复制回来或重新发布。
|
||||
5. DSH 改回 danger-full-access。
|
||||
|
||||
## 7. 注意
|
||||
|
||||
- `publish.ps1` 只应在**普通 / Medium** PowerShell 里运行;DSH 的 Low shell 会被脚本拒绝。
|
||||
- 发布前关闭 MD Preview;Nutstore 同步也可能短暂锁文件。
|
||||
- 开发版写不了 HKCU,不会抢默认打开;不要用 Medium 的旧 exe 启动,否则关联会被改回旧路径。
|
||||
- `test/` 已 gitignore,移动后仍不提交。
|
||||
|
||||
## 8. 迁移后待办
|
||||
|
||||
- 在 DSH 里确认可写、`cargo test` 全绿。
|
||||
- 父目录可选:`publish.ps1` 启动器 + `AGENTS.md` 指针(让新会话在父目录也能找到仓库规则)。
|
||||
- 给 `.gitignore` 加 `/test/`(本机草稿目录)。
|
||||
- 更新根 `README.md` 的目录树/构建命令。
|
||||
- 提交:`git add -A && git commit -m "chore: move to Low workspace and Nutstore-only publish"`(不要提交 `test/`)。
|
||||
- 需要切换默认打开并删除旧 exe 时,运行 `publish.ps1`。
|
||||
53
agent/docs/release-notes-v1.4.2-local.4.md
Normal file
53
agent/docs/release-notes-v1.4.2-local.4.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# v1.4.2-local.4(2026-10-28)
|
||||
|
||||
Windows 本地 Markdown 预览器,基于上游 md-preview 1.4.2 的离线定制版。本次更新把首页改成真正的“新标签页(New Tab)”,并把界面统一为英文。
|
||||
|
||||
## 下载
|
||||
|
||||
- **MD-Preview-windows-x64.exe**
|
||||
- 大小:5,499,392 字节
|
||||
- SHA256:7134BBC68423605BE220E19DAA1D6CB679AFBB9153C526E717F50388C1A0841D
|
||||
- 系统要求:Windows 10/11 x64;WebView2 Runtime(一般随系统自带)。
|
||||
- 免安装:下载后放到固定目录直接运行;可在 .md 的“打开方式”里设为默认。
|
||||
|
||||
> exe 未签名,SmartScreen 可能提示未知发布者,选择“更多信息 → 仍要运行”。
|
||||
|
||||
## 本次更新
|
||||
|
||||
- **新标签页(New Tab)**:默认标签就是 New Tab;标签栏的 `+` 新建一个 New Tab,不再弹“新建文件”对话框。
|
||||
- **新标签页打开文件复用标签**:在 New Tab 里 Open File、点 Recent、拖入文件或 New File,会直接替换当前 New Tab(浏览器新标签页语义),不会额外留下一个空白标签。
|
||||
- **关闭回退**:关闭最后一个文件标签会回到 New Tab;只剩一个 New Tab 时标签栏自动隐藏,外观和原来的首页一致。
|
||||
- **New File 按钮**:New Tab 上 Open File 右侧新增 New File 按钮,接管原 `+` 的建文件功能;`Ctrl+N` 仍然可用。
|
||||
- **界面统一为英文**:移除系统语言检测和中文文案,标签名从“首页/Home”改为“New Tab”,避免中英文混排;macOS Finder 新建文件也改用 Untitled 默认名。
|
||||
- **编辑保护**:在 New Tab 上按 `Ctrl+E` 不再进入空白编辑器。
|
||||
- **保存保护**:在脏文件上点 `+` 会先保存再切到 New Tab;不会丢失未保存内容。
|
||||
- **布局修复**:New Tab 与标签栏同时出现时,标签栏不再被 .empty 样式挤窄。
|
||||
- **窗口标题 / 文件监听**:New Tab 显示 `MD Preview` 标题;切换到 New Tab 时会清空文件监听,避免误报外部修改。
|
||||
- **标签约束**:New Tab 不可拖出到新窗口,右键菜单里的 Show in Explorer / Open in New Window 会置灰。
|
||||
|
||||
## 包含上一版功能
|
||||
|
||||
- 单进程多窗口:每个窗口独立标签/编辑/查找/缩放状态,最多 16 个窗口。
|
||||
- 标签右键或上下拖动移出到新窗口;同一文件全局只开一次,重复打开只聚焦。
|
||||
- 完全离线,无联网检查、自动更新或遥测。
|
||||
- 工具栏只保留 Edit / Zoom;Open、Print、Find 按钮移除,快捷键保留。
|
||||
- Ctrl+滚轮缩放:步进 5%、范围 50%–300%,跨重启记住。
|
||||
- 代码块始终深色(Visual Studio Dark),行内代码跟随主题。
|
||||
- 标题 hover 折角箭头,按 H1–H6 层级折叠;查找命中自动展开,打印时全部展开。
|
||||
- 只读文件保存失败只提示一次并暂停自动保存,关闭时可确认丢弃修改。
|
||||
- AI 输出方言:单换行按换行显示、GFM 脚注、定义列表、UTF-8 BOM 容错。
|
||||
- 相对链接/图片、外部修改热重载、单实例转发、缺失文件重定位等。
|
||||
|
||||
## 已知限制
|
||||
|
||||
- 仅 Windows(源码中 macOS 分支未维护)。
|
||||
- 界面只有英文,不随系统语言切换。
|
||||
- 不自动更新;升级请手动替换 exe。
|
||||
- 不做标签拖回、窗口合并、跨窗口编辑同步;拖拽只用于“移出到新窗口”。
|
||||
- 多窗口下不恢复上次窗口位置;新窗口相对源窗口偏移,但不会逐窗口记忆。
|
||||
- 标签右键菜单无键盘入口。
|
||||
- 只读文件可以编辑,但保存会被拒绝并提示。
|
||||
|
||||
## 从上一版升级
|
||||
|
||||
直接退出旧程序,用新 exe 覆盖原文件即可。设置、最近文件和缩放记录保存在 %LOCALAPPDATA%\md-preview\;旧 session.json 不再使用。
|
||||
40
agent/docs/release-notes-v1.4.2-local.5.md
Normal file
40
agent/docs/release-notes-v1.4.2-local.5.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# v1.4.2-local.5(2026-10-30)
|
||||
|
||||
Windows 本地 Markdown 预览器,基于上游 md-preview 1.4.2 的离线定制版。本次更新集中在编辑与阅读查找体验:Tab/Shift+Tab 缩进、回车自动跟随缩进,以及阅读模式 Find 的选区填入与“不滚动”打开。
|
||||
|
||||
## 下载
|
||||
|
||||
- **MD-Preview-windows-x64.exe**
|
||||
- 大小:5,505,024 字节
|
||||
- SHA256:A632EF0363D04CE6F72B9779BA742681868AC31D36A7FE57E4F6D44E7BEAD988
|
||||
- 系统要求:Windows 10/11 x64;WebView2 Runtime(一般随系统自带)。
|
||||
- 免安装:下载后放到固定目录直接运行;可在 .md 的“打开方式”里设为默认。
|
||||
|
||||
> exe 未签名,SmartScreen 可能提示未知发布者,选择“更多信息 → 仍要运行”。
|
||||
|
||||
## 本次更新
|
||||
|
||||
- **Tab / Shift+Tab 缩进**:编辑模式下 Tab 插入 2 个空格,Shift+Tab 反缩进;多行选区会整块缩进/反缩进;保留 textarea 原生撤销,一次 Tab 可以一步 Ctrl+Z 撤回;输入法组合期间不拦截。
|
||||
- **回车自动跟随缩进**:按 Enter 复制当前行光标前的前导空白;空行不会继续叠加缩进。列表续行(`- `、`1. `、`> `)暂未加入,留作后续单独功能。
|
||||
- **Find 自动填入阅读选区**:阅读模式选中文字后 Ctrl+F,会自动填入 Find 框;多行选区取第一行非空内容。
|
||||
- **从选区打开 Find 时不滚动**:双击某个词再 Ctrl+F,页面保持原位,只高亮并显示当前序号(例如 4/8);点“下一个/上一个”或按 Enter 时才正常滚动到目标。
|
||||
- **查找起点跟随位置**:没有选区时输入新查询,会从当前视口附近开始找,而不是每次都从文档开头跳;如果下方没有匹配,选择上方最近的匹配,避免直接回到第 1 个。
|
||||
- **编辑模式 Find 保持原样**:仍使用 WebView2 自带查找;本次不统一两种 Find。
|
||||
|
||||
## 包含上一版功能
|
||||
|
||||
- 新标签页(New Tab):默认标签、`+` 新建、New File 按钮、关闭回退、单 New Tab 隐藏标签栏。
|
||||
- 全英文界面;移除语言检测和中文文案。
|
||||
- 单进程多窗口、标签右键/拖拽移出、同文件全局聚焦。
|
||||
- 标题折叠、Ctrl+滚轮缩放、始终深色代码块、自动保存、外部修改热重载、单实例转发。
|
||||
- GFM 脚注、定义列表、front matter、GitHub Alerts、`==高亮==`、KaTeX、Mermaid;单换行按换行显示。
|
||||
|
||||
## 已知限制
|
||||
|
||||
- 编辑模式仍是纯 textarea,没有语法高亮、列表续行或富文本渲染。
|
||||
- 编辑模式 Find 与阅读模式 Find 行为不同;阅读模式才使用应用的 findbar。
|
||||
- 仅 Windows;不自动更新;升级请手动替换 exe。
|
||||
|
||||
## 从上一版升级
|
||||
|
||||
直接退出旧程序,用新 exe 覆盖原文件即可。设置、最近文件和缩放记录保存在 `%LOCALAPPDATA%\md-preview\`;旧 session.json 不再使用。
|
||||
@@ -101,7 +101,7 @@
|
||||
|
||||
- [ ] 窗口标题 `文件名 — MD Preview`,脏状态显示 `•`
|
||||
- [ ] 工具栏无 Open / Print / Find
|
||||
- [ ] 多标签、关闭、会话恢复、缺失文件重定位
|
||||
- [ ] 多标签、关闭、缺失文件重定位;切回标签保持编辑模式与滚动位置
|
||||
- [ ] 编辑 700ms 自动保存;关闭前落盘
|
||||
- [ ] 外部修改提示与保护
|
||||
- [ ] 查找(含中文输入法组合输入)
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
#requires -Version 5.1
|
||||
<#
|
||||
MD Preview 发布构建脚本
|
||||
固定产物:D:\Scripts\md-preview\MD-Preview-windows-x64.exe
|
||||
|
||||
运行环境:普通 PowerShell(Medium),或 DSH 的 danger-full-access。
|
||||
workspace-write 是 Low 完整性级别,写不动本目录(EPERM / os error 5)。
|
||||
MD Preview 开发构建(DSH workspace-write / Low 完整性可运行)
|
||||
- cargo test + cargo build --release
|
||||
- 只做校验,不复制到任何固定 exe 路径
|
||||
- 产物:target\release\md-preview.exe(Low)
|
||||
- 发布:用户在自己的普通 PowerShell 里运行 agent\scripts\publish.ps1
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$OutputPath = 'D:\Scripts\md-preview\MD-Preview-windows-x64.exe',
|
||||
[switch]$SkipTests
|
||||
)
|
||||
|
||||
@@ -16,7 +15,7 @@ $ErrorActionPreference = 'Stop'
|
||||
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
|
||||
Set-Location $repoRoot
|
||||
|
||||
# 工作区规则(agent/AGENTS.md):构建/测试的临时文件也留在 target\ 下,不污染 %TEMP%。
|
||||
# 工作区规则(agent/AGENTS.md):临时文件留在 target\ 下,不污染 %TEMP%。
|
||||
$tmpRoot = Join-Path $repoRoot 'target\tmp'
|
||||
New-Item -ItemType Directory -Force $tmpRoot | Out-Null
|
||||
$env:TEMP = $tmpRoot
|
||||
@@ -29,53 +28,53 @@ if (-not (Test-Path $cargo)) {
|
||||
|
||||
function Step([string]$text) { Write-Host ('==> ' + $text) -ForegroundColor Cyan }
|
||||
|
||||
function Assert-TargetNotRunning([string]$path) {
|
||||
$ids = @()
|
||||
foreach ($p in (Get-Process -ErrorAction SilentlyContinue)) {
|
||||
$pPath = $null
|
||||
try { $pPath = $p.Path } catch { }
|
||||
if ($pPath -eq $path) { $ids += $p.Id }
|
||||
function Invoke-Cargo([string[]]$arguments) {
|
||||
$previous = $ErrorActionPreference
|
||||
$code = 0
|
||||
try {
|
||||
# cargo 把进度/警告写到 stderr;Stop 会把它们当成终止错误
|
||||
$ErrorActionPreference = 'Continue'
|
||||
& $cargo @arguments
|
||||
$code = $LASTEXITCODE
|
||||
} finally {
|
||||
$ErrorActionPreference = $previous
|
||||
}
|
||||
if ($ids.Count -gt 0) {
|
||||
throw ('MD Preview 正在运行(PID ' + ($ids -join ', ') + '),请先关闭窗口再构建。')
|
||||
if ($code -ne 0) {
|
||||
throw ('cargo ' + ($arguments -join ' ') + ' failed with exit code ' + $code)
|
||||
}
|
||||
}
|
||||
|
||||
Assert-TargetNotRunning $OutputPath
|
||||
$built = Join-Path $repoRoot 'target\release\md-preview.exe'
|
||||
|
||||
$running = @()
|
||||
foreach ($process in (Get-Process -ErrorAction SilentlyContinue)) {
|
||||
$path = $null
|
||||
try { $path = $process.Path } catch { }
|
||||
if ($path -eq $built) { $running += [string]$process.Id }
|
||||
}
|
||||
if ($running.Count -gt 0) {
|
||||
throw ('开发版 MD Preview 正在运行(PID ' + ($running -join ', ') + '),请先关闭。')
|
||||
}
|
||||
|
||||
if (-not $SkipTests) {
|
||||
Step 'cargo test'
|
||||
& $cargo test
|
||||
if ($LASTEXITCODE -ne 0) { throw 'cargo test failed' }
|
||||
Invoke-Cargo @('test')
|
||||
}
|
||||
|
||||
Step 'cargo build --release'
|
||||
& $cargo build --release
|
||||
if ($LASTEXITCODE -ne 0) { throw 'cargo build failed' }
|
||||
Invoke-Cargo @('build', '--release')
|
||||
|
||||
$built = Join-Path $repoRoot 'target\release\md-preview.exe'
|
||||
if (-not (Test-Path $built)) { throw ('missing build output: ' + $built) }
|
||||
|
||||
Step ('copy -> ' + $OutputPath)
|
||||
$outDir = Split-Path -Parent $OutputPath
|
||||
if (-not (Test-Path $outDir)) { New-Item -ItemType Directory -Path $outDir | Out-Null }
|
||||
Assert-TargetNotRunning $OutputPath
|
||||
try {
|
||||
Copy-Item $built $OutputPath -Force -ErrorAction Stop
|
||||
} catch {
|
||||
throw ('复制失败(目标可能被占用):' + $_.Exception.Message)
|
||||
}
|
||||
|
||||
$info = Get-Item $OutputPath
|
||||
$hash = (Get-FileHash $OutputPath -Algorithm SHA256).Hash
|
||||
Write-Host ('size : {0:N0} bytes' -f $info.Length)
|
||||
Write-Host ('sha256 : ' + $hash)
|
||||
Write-Host ('version : ' + $info.VersionInfo.FileVersion)
|
||||
$info = Get-Item $built
|
||||
$hash = (Get-FileHash $built -Algorithm SHA256).Hash
|
||||
|
||||
Step 'check removed update strings'
|
||||
$bytes = [IO.File]::ReadAllBytes($OutputPath)
|
||||
$bytes = [IO.File]::ReadAllBytes($built)
|
||||
$ascii = [Text.Encoding]::ASCII.GetString($bytes)
|
||||
$forbidden = @('api.github', 'btn-update', 'Check for Updates', 'powershell', 'update-check-result', 'open-url')
|
||||
# Guard the removed updater. 'powershell' used to be on this list, but that word
|
||||
# can legitimately show up in user-facing text; the updater itself needs these.
|
||||
$forbidden = @('api.github', 'btn-update', 'Check for Updates', 'Start-Process', 'Invoke-WebRequest', 'update-check-result', 'open-url')
|
||||
$bad = @()
|
||||
foreach ($needle in $forbidden) {
|
||||
$count = ([regex]::Matches($ascii, [regex]::Escape($needle), 'IgnoreCase')).Count
|
||||
@@ -84,13 +83,14 @@ foreach ($needle in $forbidden) {
|
||||
}
|
||||
if ($bad.Count -gt 0) { throw ('removed features still present: ' + ($bad -join ', ')) }
|
||||
|
||||
Step 'check integrity level'
|
||||
$acl = (icacls $OutputPath | Out-String)
|
||||
if ($acl -match 'Medium Mandatory Level') {
|
||||
Write-Host ' Medium - OK'
|
||||
} else {
|
||||
Write-Warning '不是 Medium:启动时可能报 os error 5,见 agent/docs/HANDOFF.md 第 4 节'
|
||||
}
|
||||
|
||||
Step 'report'
|
||||
$acl = (icacls $built | Out-String)
|
||||
$integrity = 'Unknown'
|
||||
if ($acl -match 'Mandatory Label\\(Low|Medium|High) Mandatory Level') { $integrity = $Matches[1] }
|
||||
Write-Host ('output : ' + $built)
|
||||
Write-Host ('size : {0:N0} bytes' -f $info.Length)
|
||||
Write-Host ('sha256 : ' + $hash)
|
||||
Write-Host ('version : ' + $info.VersionInfo.FileVersion)
|
||||
Write-Host ('integrity : ' + $integrity + ' (workspace-write builds are Low)')
|
||||
Write-Host ''
|
||||
Write-Host ('DONE ' + $OutputPath) -ForegroundColor Green
|
||||
Write-Host 'DONE (build only). Publish: .\agent\scripts\publish.ps1 (normal PowerShell, Medium)' -ForegroundColor Green
|
||||
|
||||
114
agent/scripts/publish.ps1
Normal file
114
agent/scripts/publish.ps1
Normal file
@@ -0,0 +1,114 @@
|
||||
#requires -Version 5.1
|
||||
<#
|
||||
MD Preview 发布(必须由用户在自己的普通 PowerShell / Medium 运行)
|
||||
- 源:target\release\md-preview.exe(Low)
|
||||
- 目标:C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe(Medium)
|
||||
- 校验 SHA256 + Medium,刷新 .md 关联,最后删除旧 exe
|
||||
- 不要从 DSH 的 workspace-write shell 运行
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$Source = '',
|
||||
[string]$NutstorePath = 'C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe',
|
||||
[string]$OldExe = 'D:\Scripts\md-preview\MD-Preview-windows-x64.exe',
|
||||
[switch]$KeepOldExe
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
|
||||
Set-Location $repoRoot
|
||||
if (-not $Source) { $Source = Join-Path $repoRoot 'target\release\md-preview.exe' }
|
||||
|
||||
function Step([string]$text) { Write-Host ('==> ' + $text) -ForegroundColor Cyan }
|
||||
|
||||
function Assert-Medium {
|
||||
$groups = (whoami /groups | Out-String)
|
||||
if ($groups -match 'Low Mandatory Level') {
|
||||
throw '当前是 Low 完整性(DSH 沙箱)。请在自己的普通 PowerShell(Medium)里运行本脚本。'
|
||||
}
|
||||
}
|
||||
|
||||
function Assert-NotRunning([string[]]$paths) {
|
||||
$running = @()
|
||||
foreach ($process in (Get-Process -ErrorAction SilentlyContinue)) {
|
||||
$path = $null
|
||||
try { $path = $process.Path } catch { }
|
||||
if ($path -and ($paths -contains $path)) {
|
||||
$running += ($process.ProcessName + ' (PID ' + $process.Id + '): ' + $path)
|
||||
}
|
||||
}
|
||||
if ($running.Count -gt 0) {
|
||||
throw ('请先关闭 MD Preview:' + [Environment]::NewLine + ($running -join [Environment]::NewLine))
|
||||
}
|
||||
}
|
||||
|
||||
function Get-Integrity([string]$path) {
|
||||
$out = (icacls $path | Out-String)
|
||||
if ($out -match 'Mandatory Label\\(Low|Medium|High) Mandatory Level') { return $Matches[1] }
|
||||
return 'Unknown'
|
||||
}
|
||||
|
||||
function Set-RegistryDefault([string]$path, [string]$value) {
|
||||
if (-not (Test-Path $path)) { New-Item -Path $path -Force | Out-Null }
|
||||
Set-ItemProperty -Path $path -Name '(default)' -Value $value
|
||||
}
|
||||
|
||||
Assert-Medium
|
||||
if (-not (Test-Path -LiteralPath $Source)) {
|
||||
throw ('找不到构建产物:' + $Source + ';先运行 agent\scripts\build.ps1')
|
||||
}
|
||||
|
||||
Assert-NotRunning @($Source, $NutstorePath, $OldExe)
|
||||
|
||||
$sourceHash = (Get-FileHash -LiteralPath $Source -Algorithm SHA256).Hash
|
||||
|
||||
Step ('copy -> ' + $NutstorePath)
|
||||
$nutstoreDir = Split-Path -Parent $NutstorePath
|
||||
if (-not (Test-Path $nutstoreDir)) { New-Item -ItemType Directory -Path $nutstoreDir -Force | Out-Null }
|
||||
Copy-Item -LiteralPath $Source -Destination $NutstorePath -Force -ErrorAction Stop
|
||||
|
||||
Step 'set Nutstore exe integrity -> Medium'
|
||||
$previous = $ErrorActionPreference
|
||||
$ErrorActionPreference = 'Continue'
|
||||
icacls $NutstorePath /setintegritylevel Medium | Out-Null
|
||||
$icaclsCode = $LASTEXITCODE
|
||||
$ErrorActionPreference = $previous
|
||||
if ($icaclsCode -ne 0) { throw ('icacls failed with exit code ' + $icaclsCode) }
|
||||
|
||||
$integrity = Get-Integrity $NutstorePath
|
||||
if ($integrity -ne 'Medium') { throw ('完整性级别不是 Medium:' + $integrity) }
|
||||
|
||||
$targetHash = (Get-FileHash -LiteralPath $NutstorePath -Algorithm SHA256).Hash
|
||||
if ($sourceHash -ne $targetHash) {
|
||||
throw ('SHA256 不一致:source=' + $sourceHash + ' target=' + $targetHash)
|
||||
}
|
||||
|
||||
Step 'refresh .md association -> Nutstore'
|
||||
$progid = 'MDPreview.md'
|
||||
$command = '"' + $NutstorePath + '" "%1"'
|
||||
Set-RegistryDefault ('HKCU:\Software\Classes\' + $progid + '\shell\open\command') $command
|
||||
Set-RegistryDefault ('HKCU:\Software\Classes\' + $progid + '\DefaultIcon') ('"' + $NutstorePath + '",0')
|
||||
Set-RegistryDefault ('HKCU:\Software\Classes\Applications\MD-Preview-windows-x64.exe\shell\open\command') $command
|
||||
|
||||
$actual = (Get-ItemProperty ('HKCU:\Software\Classes\' + $progid + '\shell\open\command')).'(default)'
|
||||
if ($actual -ne $command) { throw ('关联写入失败:' + $actual) }
|
||||
|
||||
$userChoiceKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.md\UserChoiceLatest\ProgId'
|
||||
$userChoice = $null
|
||||
if (Test-Path $userChoiceKey) { $userChoice = (Get-ItemProperty $userChoiceKey).ProgId }
|
||||
if ($userChoice -ne $progid) {
|
||||
Write-Warning ('.md 的 UserChoice ProgId 是 ' + $userChoice + ',不是 ' + $progid + ';请在 设置 -> 默认应用 里选择一次 MD Preview。')
|
||||
}
|
||||
|
||||
if (-not $KeepOldExe -and (Test-Path -LiteralPath $OldExe)) {
|
||||
Step ('delete old exe -> ' + $OldExe)
|
||||
Remove-Item -LiteralPath $OldExe -Force -ErrorAction Stop
|
||||
}
|
||||
|
||||
Write-Host ''
|
||||
Write-Host ('size : {0:N0} bytes' -f (Get-Item -LiteralPath $NutstorePath).Length)
|
||||
Write-Host ('sha256 : ' + $targetHash)
|
||||
Write-Host ('integrity : ' + $integrity)
|
||||
Write-Host ('default : ' + $actual)
|
||||
Write-Host ('old exe : ' + $OldExe)
|
||||
Write-Host 'DONE' -ForegroundColor Green
|
||||
@@ -2,25 +2,46 @@
|
||||
<#
|
||||
MD Preview 冒烟测试
|
||||
cargo test + 关联检查 + 可选隔离启动(不污染真实 %LOCALAPPDATA%)
|
||||
默认测试 Nutstore 发布版;-Dev 测试 target\release 开发版
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$Exe = 'D:\Scripts\md-preview\MD-Preview-windows-x64.exe',
|
||||
[switch]$Launch
|
||||
[string]$Exe = 'C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe',
|
||||
[switch]$Launch,
|
||||
[switch]$Dev
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
|
||||
Set-Location $repoRoot
|
||||
|
||||
$tmpRoot = Join-Path $repoRoot 'target\tmp'
|
||||
New-Item -ItemType Directory -Force $tmpRoot | Out-Null
|
||||
$env:TEMP = $tmpRoot
|
||||
$env:TMP = $tmpRoot
|
||||
|
||||
$cargo = Join-Path $env:USERPROFILE '.cargo\bin\cargo.exe'
|
||||
if (-not (Test-Path $cargo)) { $cargo = (Get-Command cargo -ErrorAction Stop).Source }
|
||||
|
||||
if (-not (Test-Path $Exe)) { throw ('missing exe: ' + $Exe + ' (先运行 agent/scripts/build.ps1)') }
|
||||
if ($Dev) {
|
||||
$Exe = Join-Path $repoRoot 'target\release\md-preview.exe'
|
||||
if (-not $env:MD_PREVIEW_CONFIG_DIR) {
|
||||
$env:MD_PREVIEW_CONFIG_DIR = Join-Path $repoRoot 'target\smoke'
|
||||
New-Item -ItemType Directory -Force $env:MD_PREVIEW_CONFIG_DIR | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
if (-not (Test-Path $Exe)) {
|
||||
throw ('missing exe: ' + $Exe + '(先运行 agent/scripts/build.ps1,或先发布)')
|
||||
}
|
||||
|
||||
Write-Host '==> cargo test' -ForegroundColor Cyan
|
||||
$previous = $ErrorActionPreference
|
||||
$ErrorActionPreference = 'Continue'
|
||||
& $cargo test
|
||||
if ($LASTEXITCODE -ne 0) { throw 'cargo test failed' }
|
||||
$code = $LASTEXITCODE
|
||||
$ErrorActionPreference = $previous
|
||||
if ($code -ne 0) { throw 'cargo test failed' }
|
||||
|
||||
Write-Host '==> --help' -ForegroundColor Cyan
|
||||
$help = (& $Exe --help 2>&1 | Out-String)
|
||||
@@ -30,20 +51,24 @@ if ($help -match 'MD Preview') {
|
||||
Write-Warning '--help 无输出(GUI 子系统在部分终端下不回显,可忽略)'
|
||||
}
|
||||
|
||||
Write-Host '==> registry association' -ForegroundColor Cyan
|
||||
$reg = Get-ItemProperty 'HKCU:\Software\Classes\MDPreview.md\shell\open\command' -ErrorAction SilentlyContinue
|
||||
$expected = '"' + $Exe + '" "%1"'
|
||||
if ($null -eq $reg) {
|
||||
Write-Warning 'ProgID 未注册(先运行一次 exe)'
|
||||
} elseif ($reg.'(default)' -ne $expected) {
|
||||
Write-Warning ('ProgID 指向不一致: ' + $reg.'(default)')
|
||||
if ($Dev) {
|
||||
Write-Host '==> registry association (skipped: Low build cannot write HKCU)' -ForegroundColor Cyan
|
||||
} else {
|
||||
Write-Host ' OK'
|
||||
Write-Host '==> registry association' -ForegroundColor Cyan
|
||||
$reg = Get-ItemProperty 'HKCU:\Software\Classes\MDPreview.md\shell\open\command' -ErrorAction SilentlyContinue
|
||||
$expected = '"' + $Exe + '" "%1"'
|
||||
if ($null -eq $reg) {
|
||||
Write-Warning 'ProgID 未注册(先运行一次 exe)'
|
||||
} elseif ($reg.'(default)' -ne $expected) {
|
||||
Write-Warning ('ProgID 指向不一致: ' + $reg.'(default)')
|
||||
} else {
|
||||
Write-Host ' OK'
|
||||
}
|
||||
}
|
||||
|
||||
if ($Launch) {
|
||||
Write-Host '==> launch with isolated config' -ForegroundColor Cyan
|
||||
$config = Join-Path $env:TEMP ('mdp-smoke-' + [guid]::NewGuid().ToString('N'))
|
||||
$config = Join-Path $tmpRoot ('mdp-smoke-' + [guid]::NewGuid().ToString('N'))
|
||||
New-Item -ItemType Directory -Path $config | Out-Null
|
||||
$fixture = Join-Path $PSScriptRoot 'fixtures\long-headings.md'
|
||||
$env:MD_PREVIEW_CONFIG_DIR = $config
|
||||
|
||||
926
src/main.rs
926
src/main.rs
File diff suppressed because it is too large
Load Diff
284
src/session.rs
284
src/session.rs
@@ -1,13 +1,29 @@
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct DocumentTab {
|
||||
pub id: u64,
|
||||
pub path: PathBuf,
|
||||
/// `None` marks the built-in Home tab; Home has no file on disk.
|
||||
pub path: Option<PathBuf>,
|
||||
pub dirty: bool,
|
||||
pub missing: bool,
|
||||
pub edit_on_open: bool,
|
||||
/// Edit mode belongs to the tab, so switching tabs restores the mode the
|
||||
/// tab was left in instead of carrying one global mode across documents.
|
||||
pub editing: bool,
|
||||
/// Viewport position as a 0.0 (top) ..= 1.0 (bottom) fraction. Stores a
|
||||
/// ratio rather than pixels so zoom and reflow do not move the reader.
|
||||
pub scroll_ratio: f32,
|
||||
}
|
||||
|
||||
impl DocumentTab {
|
||||
pub fn is_home(&self) -> bool {
|
||||
self.path.is_none()
|
||||
}
|
||||
|
||||
pub fn file_path(&self) -> Option<&Path> {
|
||||
self.path.as_deref()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
@@ -20,31 +36,98 @@ pub struct DocumentSession {
|
||||
impl DocumentSession {
|
||||
pub fn open(&mut self, path: PathBuf, edit_on_open: bool) -> u64 {
|
||||
let path = normalize_path(path);
|
||||
if let Some(tab) = self.tabs.iter_mut().find(|tab| tab.path == path) {
|
||||
tab.missing = !tab.path.exists();
|
||||
tab.edit_on_open |= edit_on_open;
|
||||
if let Some(tab) = self
|
||||
.tabs
|
||||
.iter_mut()
|
||||
.find(|tab| tab.path.as_deref() == Some(path.as_path()))
|
||||
{
|
||||
tab.missing = !path.exists();
|
||||
tab.editing |= edit_on_open;
|
||||
self.active_id = Some(tab.id);
|
||||
return tab.id;
|
||||
}
|
||||
|
||||
self.next_id += 1;
|
||||
let id = self.next_id;
|
||||
let missing = !path.exists();
|
||||
self.tabs.push(DocumentTab {
|
||||
id,
|
||||
missing: !path.exists(),
|
||||
path,
|
||||
path: Some(path),
|
||||
dirty: false,
|
||||
edit_on_open,
|
||||
missing,
|
||||
editing: edit_on_open,
|
||||
scroll_ratio: 0.0,
|
||||
});
|
||||
self.active_id = Some(id);
|
||||
id
|
||||
}
|
||||
|
||||
/// Append and activate a Home tab (the in-app "new tab page").
|
||||
pub fn open_home(&mut self) -> u64 {
|
||||
self.next_id += 1;
|
||||
let id = self.next_id;
|
||||
self.tabs.push(DocumentTab {
|
||||
id,
|
||||
path: None,
|
||||
dirty: false,
|
||||
missing: false,
|
||||
editing: false,
|
||||
scroll_ratio: 0.0,
|
||||
});
|
||||
self.active_id = Some(id);
|
||||
id
|
||||
}
|
||||
|
||||
/// Open `path`, turning the active Home tab into the document when possible
|
||||
/// (browser-style navigation). Falls back to appending a tab otherwise.
|
||||
pub fn open_reusing_home(&mut self, path: PathBuf, edit_on_open: bool) -> u64 {
|
||||
let Some(active_id) = self.active_id else {
|
||||
return self.open(path, edit_on_open);
|
||||
};
|
||||
if !self
|
||||
.tabs
|
||||
.iter()
|
||||
.any(|tab| tab.id == active_id && tab.is_home())
|
||||
{
|
||||
return self.open(path, edit_on_open);
|
||||
}
|
||||
|
||||
let path = normalize_path(path);
|
||||
if let Some(existing) = self
|
||||
.tabs
|
||||
.iter_mut()
|
||||
.find(|tab| tab.id != active_id && tab.path.as_deref() == Some(path.as_path()))
|
||||
{
|
||||
existing.missing = !path.exists();
|
||||
existing.editing |= edit_on_open;
|
||||
let existing_id = existing.id;
|
||||
// The blank tab did its job; drop it the way a browser would.
|
||||
self.tabs.retain(|tab| tab.id != active_id);
|
||||
self.active_id = Some(existing_id);
|
||||
return existing_id;
|
||||
}
|
||||
|
||||
let missing = !path.exists();
|
||||
let tab = self
|
||||
.tabs
|
||||
.iter_mut()
|
||||
.find(|tab| tab.id == active_id)
|
||||
.expect("active tab disappeared");
|
||||
tab.path = Some(path);
|
||||
tab.missing = missing;
|
||||
tab.dirty = false;
|
||||
tab.editing = edit_on_open;
|
||||
tab.scroll_ratio = 0.0;
|
||||
active_id
|
||||
}
|
||||
|
||||
pub fn activate(&mut self, id: u64) -> bool {
|
||||
let Some(tab) = self.tabs.iter_mut().find(|tab| tab.id == id) else {
|
||||
return false;
|
||||
};
|
||||
tab.missing = !tab.path.exists();
|
||||
if let Some(path) = tab.path.as_deref() {
|
||||
tab.missing = !path.exists();
|
||||
}
|
||||
self.active_id = Some(id);
|
||||
true
|
||||
}
|
||||
@@ -65,6 +148,17 @@ impl DocumentSession {
|
||||
true
|
||||
}
|
||||
|
||||
/// Close a tab and leave a fresh Home tab behind when it was the last one.
|
||||
pub fn close_with_home_fallback(&mut self, id: u64) -> bool {
|
||||
if !self.close(id) {
|
||||
return false;
|
||||
}
|
||||
if self.tabs.is_empty() {
|
||||
self.open_home();
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub fn with_tab(tab: DocumentTab) -> Self {
|
||||
let id = tab.id;
|
||||
Self {
|
||||
@@ -76,6 +170,9 @@ impl DocumentSession {
|
||||
|
||||
pub fn detach(&mut self, id: u64) -> Option<DocumentTab> {
|
||||
let index = self.tabs.iter().position(|tab| tab.id == id)?;
|
||||
if self.tabs[index].is_home() {
|
||||
return None;
|
||||
}
|
||||
let was_active = self.active_id == Some(id);
|
||||
let tab = self.tabs.remove(index);
|
||||
if was_active {
|
||||
@@ -98,20 +195,63 @@ impl DocumentSession {
|
||||
self.tabs.iter_mut().find(|tab| tab.id == id)
|
||||
}
|
||||
|
||||
pub fn active_path(&self) -> Option<&Path> {
|
||||
self.active().and_then(DocumentTab::file_path)
|
||||
}
|
||||
|
||||
pub fn active_is_home(&self) -> bool {
|
||||
self.active().is_some_and(DocumentTab::is_home)
|
||||
}
|
||||
|
||||
/// Remember the viewport of the active tab (0.0 top .. 1.0 bottom).
|
||||
pub fn set_active_scroll_ratio(&mut self, ratio: f32) {
|
||||
if !ratio.is_finite() {
|
||||
return;
|
||||
}
|
||||
if let Some(tab) = self.active_mut() {
|
||||
tab.scroll_ratio = ratio.clamp(0.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// Store the viewport by tab id; late scroll reports must not land on a tab
|
||||
/// that was activated in the meantime.
|
||||
pub fn set_tab_scroll_ratio(&mut self, id: u64, ratio: f32) {
|
||||
if !ratio.is_finite() {
|
||||
return;
|
||||
}
|
||||
if let Some(tab) = self.get_mut(id) {
|
||||
tab.scroll_ratio = ratio.clamp(0.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_tab_editing(&mut self, id: u64, editing: bool) {
|
||||
if let Some(tab) = self.get_mut(id) {
|
||||
tab.editing = editing;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, id: u64) -> Option<&mut DocumentTab> {
|
||||
self.tabs.iter_mut().find(|tab| tab.id == id)
|
||||
}
|
||||
|
||||
pub fn relocate(&mut self, id: u64, path: PathBuf) -> bool {
|
||||
let path = normalize_path(path);
|
||||
if self.tabs.iter().any(|tab| tab.id != id && tab.path == path) {
|
||||
if self
|
||||
.tabs
|
||||
.iter()
|
||||
.any(|tab| tab.id != id && tab.path.as_deref() == Some(path.as_path()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let missing = !path.exists();
|
||||
let Some(tab) = self.get_mut(id) else {
|
||||
return false;
|
||||
};
|
||||
tab.path = path;
|
||||
tab.missing = !tab.path.exists();
|
||||
if tab.is_home() {
|
||||
return false;
|
||||
}
|
||||
tab.path = Some(path);
|
||||
tab.missing = missing;
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -180,7 +320,7 @@ mod tests {
|
||||
assert_eq!(first, second);
|
||||
assert_eq!(session.tabs.len(), 1);
|
||||
assert_eq!(session.active_id, Some(first));
|
||||
assert!(session.tabs[0].edit_on_open);
|
||||
assert!(session.tabs[0].editing);
|
||||
let _ = fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
@@ -222,6 +362,107 @@ mod tests {
|
||||
let _ = fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn home_tab_is_a_tab_without_a_file_path() {
|
||||
let mut session = DocumentSession::default();
|
||||
|
||||
let home = session.open_home();
|
||||
|
||||
assert_eq!(session.active_id, Some(home));
|
||||
assert_eq!(session.tabs.len(), 1);
|
||||
assert!(session.tabs[0].is_home());
|
||||
assert_eq!(session.active_path(), None);
|
||||
assert!(session.active_is_home());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opening_a_file_from_home_reuses_the_home_tab() {
|
||||
let dir = temp_dir("home-reuse");
|
||||
let file = dir.join("note.md");
|
||||
fs::write(&file, "# Note").unwrap();
|
||||
let mut session = DocumentSession::default();
|
||||
let home = session.open_home();
|
||||
|
||||
let opened = session.open_reusing_home(file.clone(), true);
|
||||
|
||||
assert_eq!(opened, home);
|
||||
assert_eq!(session.tabs.len(), 1);
|
||||
assert!(!session.tabs[0].is_home());
|
||||
assert_eq!(session.tabs[0].file_path(), Some(file.as_path()));
|
||||
assert!(session.tabs[0].editing);
|
||||
let _ = fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opening_an_already_open_file_from_home_drops_the_blank_tab() {
|
||||
let dir = temp_dir("home-dedupe");
|
||||
let first = dir.join("one.md");
|
||||
fs::write(&first, "one").unwrap();
|
||||
let mut session = DocumentSession::default();
|
||||
let first_id = session.open(first.clone(), false);
|
||||
let home = session.open_home();
|
||||
|
||||
let opened = session.open_reusing_home(first, false);
|
||||
|
||||
assert_eq!(opened, first_id);
|
||||
assert_eq!(session.tabs.len(), 1);
|
||||
assert_eq!(session.active_id, Some(first_id));
|
||||
assert!(!session.tabs.iter().any(|tab| tab.id == home));
|
||||
let _ = fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn home_tab_cannot_be_detached_or_relocated() {
|
||||
let dir = temp_dir("home-guard");
|
||||
let mut session = DocumentSession::default();
|
||||
let home = session.open_home();
|
||||
|
||||
assert!(session.detach(home).is_none());
|
||||
assert!(!session.relocate(home, dir.join("note.md")));
|
||||
assert_eq!(session.tabs.len(), 1);
|
||||
let _ = fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_the_last_file_leaves_a_home_tab() {
|
||||
let dir = temp_dir("close-home");
|
||||
let file = dir.join("note.md");
|
||||
fs::write(&file, "").unwrap();
|
||||
let mut session = DocumentSession::default();
|
||||
let file_id = session.open(file, false);
|
||||
|
||||
assert!(session.close_with_home_fallback(file_id));
|
||||
|
||||
assert_eq!(session.tabs.len(), 1);
|
||||
assert!(session.active().unwrap().is_home());
|
||||
assert_eq!(session.active_id, Some(session.tabs[0].id));
|
||||
let _ = fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edit_mode_and_scroll_position_are_remembered_per_tab() {
|
||||
let dir = temp_dir("per-tab-view");
|
||||
let mut session = DocumentSession::default();
|
||||
let first = session.open(dir.join("one.md"), true);
|
||||
session.set_active_scroll_ratio(0.75);
|
||||
let second = session.open(dir.join("two.md"), false);
|
||||
|
||||
assert_ne!(first, second);
|
||||
assert!(!session.active().unwrap().editing);
|
||||
assert_eq!(session.active().unwrap().scroll_ratio, 0.0);
|
||||
|
||||
assert!(session.activate(first));
|
||||
assert!(session.active().unwrap().editing);
|
||||
assert_eq!(session.active().unwrap().scroll_ratio, 0.75);
|
||||
|
||||
// Late reports address the tab by id, not by whichever tab is active.
|
||||
session.set_tab_scroll_ratio(second, 0.4);
|
||||
assert!(session.activate(second));
|
||||
assert_eq!(session.active().unwrap().scroll_ratio, 0.4);
|
||||
assert!(!session.active().unwrap().editing);
|
||||
let _ = fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[test]
|
||||
fn opened_paths_drop_windows_verbatim_prefix() {
|
||||
@@ -232,9 +473,16 @@ mod tests {
|
||||
|
||||
session.open(file.clone(), false);
|
||||
|
||||
let stored = session.tabs[0].path.to_string_lossy().to_string();
|
||||
assert!(!stored.starts_with(r"\\?\"), "verbatim prefix leaked: {stored}");
|
||||
assert!(session.tabs[0].path.ends_with("note.md"));
|
||||
let stored = session.tabs[0]
|
||||
.file_path()
|
||||
.unwrap()
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
assert!(
|
||||
!stored.starts_with(r"\\?\"),
|
||||
"verbatim prefix leaked: {stored}"
|
||||
);
|
||||
assert!(session.tabs[0].file_path().unwrap().ends_with("note.md"));
|
||||
let _ = fs::remove_dir_all(dir);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user