diff --git a/.agents/notes/implemented/feature/2026-11-20-cli-and-standalone-editor.md b/.agents/notes/implemented/feature/2026-11-20-cli-and-standalone-editor.md index a518ac208..6e4230a9b 100644 --- a/.agents/notes/implemented/feature/2026-11-20-cli-and-standalone-editor.md +++ b/.agents/notes/implemented/feature/2026-11-20-cli-and-standalone-editor.md @@ -13,7 +13,7 @@ Lithe 默认不向用户的命令行环境注册命令。用户在设置的“ ## 决策 - Core(共享 Rust 规则层)解析启动参数、根据原生文件类型选择模式,并给出单文件模式允许的命令。桌面端只做路径观察、进程启动和界面呈现。单文件窗口借用既有文档与标签生命周期,不调用项目打开流程;父目录只是文件位置,不进行项目恢复、信任确认、递归搜索或插件上下文绑定。 -- 单文件模式保留内置语法高亮、文本编辑、查找替换、保存、编码与换行选择和单个文档的外部变更观察。项目侧栏、Git、运行、调试、测试及预览网页不呈现。终端默认关闭,由用户点击后才创建,使用当前文件所在目录,复用现有终端标签、分隔条及进程清理;隐藏面板保留会话,关闭标签或窗口释放 shell。单文件窗口不恢复或改写项目面板布局。双 Shift 和查找动作只列出允许的动作,不读取父目录。关闭全部文件后仍保持单文件空态。 +- 单文件模式保留内置语法高亮、文本编辑、查找替换、保存、编码与换行选择和单个文档的外部变更观察。Markdown 文件与项目窗口一样显示渲染页(编辑 / 编辑与预览 / 预览切换和目录按钮,#2324):渲染页只读当前文档文本和它引用的图片,链接在本窗口打开文件,不需要项目服务。项目侧栏、Git、运行、调试、测试不呈现;SVG、HTML 文件只显示源码,图片、PDF 等查看器也不打开。终端默认关闭,由用户点击后才创建,使用当前文件所在目录,复用现有终端标签、分隔条及进程清理;隐藏面板保留会话,关闭标签或窗口释放 shell。单文件窗口不恢复或改写项目面板布局。双 Shift 和查找动作只列出允许的动作,不读取父目录。关闭全部文件后仍保持单文件空态。 - 顶栏显示当前文件名与“单文件模式”,通过 ⓘ 解释边界。“以项目打开所在文件夹”使用当前选中文件的父目录,在另一窗口进入正常的项目信任和插件流程,保留原编辑窗口。 - CLI 卡片直接读取默认 shell 配置与启动器内容。macOS zsh 使用 `.zshrc`(尊重 `ZDOTDIR`),bash 使用实际登录配置,fish 使用自身配置;Windows 编辑当前用户注册表 PATH,保留其原生字符串类型,并有界广播环境变更。已有终端需重新打开。 - 打开页面只读,注册、修复和移除都来自明确按钮。Unix 来源使用带标记的配置块,Windows 只编辑匹配目录项;保留其他内容。写入前核对文件内容、来源目录和符号链接目标;读取后被外部改写则拒绝覆盖。Windows 注册表核对与单值写入间仍受外部进程竞争限制,不宣称跨进程事务。 @@ -30,7 +30,7 @@ Lithe 默认不向用户的命令行环境注册命令。用户在设置的“ ## 后果 -临时文件不再启动项目服务;命令可移除、可回读,并能发现外部改动。单文件模式也因此没有插件语言智能和项目预览;需要这些功能时必须明确打开所在文件夹。每次 CLI 调用会短暂启动一个只处理参数和路径的父进程,再脱离终端创建 GUI(图形界面)子进程,不保留 shell 管道或后台 shell。 +临时文件不再启动项目服务;命令可移除、可回读,并能发现外部改动。单文件模式也因此没有插件语言智能,也没有 SVG、HTML 和图片、PDF 预览;需要这些功能时必须明确打开所在文件夹。Markdown 渲染页在有系统网页引擎时会在打开文件时创建一个网页视图,常驻内存与项目窗口打开同一文件相同;切到“编辑”只隐藏它,关闭标签或窗口才释放。每次 CLI 调用会短暂启动一个只处理参数和路径的父进程,再脱离终端创建 GUI(图形界面)子进程,不保留 shell 管道或后台 shell。 ## 验证 diff --git a/desktop/internal/workbench/editor_view.go b/desktop/internal/workbench/editor_view.go index 0868a1e3c..4f104ee72 100644 --- a/desktop/internal/workbench/editor_view.go +++ b/desktop/internal/workbench/editor_view.go @@ -63,7 +63,7 @@ func (a *App) editorNode(c ui.C, n *splitNode) ui.Box { // the selected file or terminal. The group is recorded for the drag, which aims at the strip // and the body. A group that shows an open file ends its strip with the soft wrap switch, after // the Contents button and the switch of a Markdown file's view, or the switch of an SVG or an -// HTML file's view where its picture or page can be shown. +// HTML file's view where its picture or page can be shown and the window is a project's. func (a *App) editorGroup(c ui.C, id string) ui.Box { u := &a.term place := newGroupPlace(id) @@ -80,7 +80,7 @@ func (a *App) editorGroup(c ui.C, id string) ui.Box { // The tabs fill the strip and give up their room before the buttons do, so they // stay at the end of the strip's first row however many files are open. a.tabBar(c, place, layout, func() { - if !p.standalone && isMarkdownDocument(doc) { + if isMarkdownDocument(doc) { a.markdownContentsButton(c, p, doc) a.pageModeSwitch(c, doc) } else if !p.standalone && ((isSVGDocument(doc) && a.previewWeb()) || a.htmlPreviewable(doc)) { @@ -108,16 +108,17 @@ func (a *App) editorGroup(c ui.C, id string) ui.Box { // groupBody declares the body of group id: the control of the file it shows (a Markdown file // with its rendered page, an SVG file with its picture, an HTML file with its page), of the Diff -// tab, of the viewer tab, the LSP Logs tab or the terminal. +// tab, of the viewer tab, the LSP Logs tab or the terminal. A single-file window shows a +// Markdown file's page too, but an SVG or an HTML file as text. func (a *App) groupBody(c ui.C, id string, doc *document) { - if a.project.standalone && doc != nil { - a.documentView(c, id, doc) - return - } if isMarkdownDocument(doc) { a.markdownDocument(c, a.project, id, doc) return } + if a.project.standalone && doc != nil { + a.documentView(c, id, doc) + return + } if isSVGDocument(doc) && a.previewWeb() { a.svgDocument(c, a.project, id, doc) return diff --git a/desktop/internal/workbench/standalone_test.go b/desktop/internal/workbench/standalone_test.go index 93edc3485..0be7063c8 100644 --- a/desktop/internal/workbench/standalone_test.go +++ b/desktop/internal/workbench/standalone_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/store" ) @@ -75,6 +76,77 @@ func TestStandaloneEditsWithBundledSyntaxWithoutProjectServices(t *testing.T) { } } +// TestStandaloneMarkdownShowsItsPage: a Markdown file opened alone has the page, the view +// switch and the Contents button it has in a project (#2324), still without project services. +// The page loads an image beside the file, but not one outside the file's folder. +func TestStandaloneMarkdownShowsItsPage(t *testing.T) { + parent := t.TempDir() + root := filepath.Join(parent, "notes") + if err := os.MkdirAll(filepath.Join(root, "img"), 0700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(root, "img", "local.png"), pngOf(t, 4, 5), 0600); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(parent, "outside.png"), pngOf(t, 2, 2), 0600); err != nil { + t.Fatal(err) + } + path := filepath.Join(root, "notes.md") + source := "# Title\n\nSome **bold** text.\n\n![local](img/local.png)\n\n![escape](../outside.png)\n\n## Second part\n\nmore\n" + if err := os.WriteFile(path, []byte(source), 0600); err != nil { + t.Fatal(err) + } + prefs := store.At(t.TempDir()) + if err := prefs.Save(settingsFile, map[string]string{"theme": "dark"}); err != nil { + t.Fatal(err) + } + options := DesktopOptions(core.NewClient(), prefs, "test") + options.Languages, options.OpenFile = []string{"en-US"}, path + options.PluginRoot = filepath.Join(root, "unread-plugins") + h := newHarnessWithOptions(t, options) + h.app.openStandaloneFile(path) + h.await("standalone Markdown file", func() bool { return h.app.project != nil && h.app.project.docs.byPath(path) != nil }) + h.settle() + p := h.app.project + d := p.docs.byPath(path) + language := h.app.language() + text := func(id string) string { return i18n.Shared(language, id) } + for _, id := range []string{"editor.markdownSourceView", "editor.markdownSplitView", "editor.markdownPreviewView", "desktop.markdown.contents"} { + if !controlShown(h, text(id)) { + t.Fatalf("the strip of a Markdown file opened alone has no %q", text(id)) + } + } + page := text("desktop.markdown.preview") + if !controlShown(h, page) || editorRect(h, d).Width == 0 { + t.Fatal("a Markdown file opened alone does not show its source beside its page") + } + s := d.markdown + awaitStateWithin(t, h, 10*time.Second, "the page's images", func() bool { + if len(s.images) != 2 { + return false + } + for _, image := range s.images { + if image.loading { + return false + } + } + return true + }) + if local := s.images["img/local.png"]; local == nil || local.failed || local.bitmap.Width != 4 { + t.Fatalf("the image beside the file is %+v", local) + } + if escape := s.images["../outside.png"]; escape == nil || !escape.failed { + t.Fatalf("the image outside the file's folder is %+v, want failed", escape) + } + h.click(center(h.hitLabeled(text("editor.markdownPreviewView")))) + if editorRect(h, d).Width != 0 || !controlShown(h, page) { + t.Fatal("Preview did not show the page alone") + } + if h.app.plugins != nil || p.search.watch != nil || p.git.isRepository() { + t.Fatal("showing the page started project services") + } +} + func TestStandaloneTerminalStartsOnDemandInSelectedFileFolder(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("native /bin/sh PTY workflow; Windows needs its local guest") diff --git a/desktop/internal/workbench/standalone_visual_test.go b/desktop/internal/workbench/standalone_visual_test.go index 9b9833aaa..30073895b 100644 --- a/desktop/internal/workbench/standalone_visual_test.go +++ b/desktop/internal/workbench/standalone_visual_test.go @@ -80,3 +80,50 @@ func TestVisualStandalone(t *testing.T) { } } } + +// TestVisualStandaloneMarkdown captures a Markdown file opened alone, its source beside the page +// with the view switch and the Contents button in the tab strip (#2324). +func TestVisualStandaloneMarkdown(t *testing.T) { + out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") + if out == "" { + t.Skip("set LITHE_VISUAL_OUTPUT_DIR") + } + if err := os.MkdirAll(out, 0755); err != nil { + t.Fatal(err) + } + text := "# Notes\n\nA file opened **alone**, its page beside the source.\n\n## List\n\n- one\n- two\n\n## Code\n\n```go\nfmt.Println(\"Hello, Lithe!\")\n```\n\n> A quote.\n" + for _, theme := range []string{"dark", "light"} { + for _, language := range []string{"en-US", "zh-Hans"} { + t.Run(theme+"-"+language, func(t *testing.T) { + root := t.TempDir() + path := filepath.Join(root, "notes.md") + if err := os.WriteFile(path, []byte(text), 0600); err != nil { + t.Fatal(err) + } + prefs := store.At(t.TempDir()) + if err := prefs.Save(settingsFile, map[string]string{"theme": theme}); err != nil { + t.Fatal(err) + } + options := DesktopOptions(core.NewClient(), prefs, "test") + options.Languages = []string{language} + options.OpenFile = path + var session *headless.Session + h := newHarnessWithDriver(t, options, func(config app.Config) (*app.Driver, func(), error) { + config.Width, config.Height = 1000, 640 + var err error + session, err = headless.Open(config, nil, headless.Options{}) + if err != nil { + return nil, nil, err + } + return session.Driver(), session.Close, nil + }) + h.app.openStandaloneFile(path) + h.await("standalone Markdown file", func() bool { return h.app.project != nil && h.app.project.docs.byPath(path) != nil }) + h.settle() + if err := session.Screenshot(filepath.Join(out, "single-file-markdown-"+theme+"-"+language+".png")); err != nil { + t.Fatal(err) + } + }) + } + } +} diff --git a/docs/assets/single-file-markdown/after-single-file-markdown-dark-en-US.png b/docs/assets/single-file-markdown/after-single-file-markdown-dark-en-US.png new file mode 100644 index 000000000..a8f59109f Binary files /dev/null and b/docs/assets/single-file-markdown/after-single-file-markdown-dark-en-US.png differ diff --git a/docs/assets/single-file-markdown/after-single-file-markdown-dark-zh-Hans.png b/docs/assets/single-file-markdown/after-single-file-markdown-dark-zh-Hans.png new file mode 100644 index 000000000..7667a4f65 Binary files /dev/null and b/docs/assets/single-file-markdown/after-single-file-markdown-dark-zh-Hans.png differ diff --git a/docs/assets/single-file-markdown/after-single-file-markdown-light-en-US.png b/docs/assets/single-file-markdown/after-single-file-markdown-light-en-US.png new file mode 100644 index 000000000..02333e155 Binary files /dev/null and b/docs/assets/single-file-markdown/after-single-file-markdown-light-en-US.png differ diff --git a/docs/assets/single-file-markdown/after-single-file-markdown-light-zh-Hans.png b/docs/assets/single-file-markdown/after-single-file-markdown-light-zh-Hans.png new file mode 100644 index 000000000..da25a7416 Binary files /dev/null and b/docs/assets/single-file-markdown/after-single-file-markdown-light-zh-Hans.png differ diff --git a/docs/assets/single-file-markdown/before-single-file-markdown-dark-zh-Hans.png b/docs/assets/single-file-markdown/before-single-file-markdown-dark-zh-Hans.png new file mode 100644 index 000000000..1cbfd8047 Binary files /dev/null and b/docs/assets/single-file-markdown/before-single-file-markdown-dark-zh-Hans.png differ diff --git a/docs/assets/single-file-markdown/before-single-file-markdown-light-en-US.png b/docs/assets/single-file-markdown/before-single-file-markdown-light-en-US.png new file mode 100644 index 000000000..a120a0148 Binary files /dev/null and b/docs/assets/single-file-markdown/before-single-file-markdown-light-en-US.png differ diff --git a/shared/platform-feature-matrix/features/cli-single-file-mode.json b/shared/platform-feature-matrix/features/cli-single-file-mode.json index db6dede9e..39de5e0e3 100644 --- a/shared/platform-feature-matrix/features/cli-single-file-mode.json +++ b/shared/platform-feature-matrix/features/cli-single-file-mode.json @@ -4,8 +4,8 @@ "group": "CLI", "capability": "可选注册 lithe 命令,按文件夹/单文件分别打开项目与轻量编辑器", "owner": "Desktop", - "verification": "macOS:打开通用 > CLI 时不写来源;点击注册后新终端能使用 lithe,分别传入带空格/中文文件、文件夹和 -- 保护的路径;单文件只使用内置高亮,能编辑保存,默认不创建终端,无插件、项目树、Git、运行/调试/测试或父目录索引,查找动作不搜索工作区。点击终端后使用当前文件目录,真实命令输出可见,隐藏后重开复用会话,关闭窗口清理 shell。以项目打开所在文件夹在新窗口走正常信任和插件流程。修复应用移动后的启动器;移除注册保留无关 shell 内容。Windows:检查 HKCU Environment Path 类型与无关项保留、外部修改冲突、环境广播、新 cmd/PowerShell 中调用及移除,原生运行待验收。", - "notes": "已在 macOS 执行真实临时配置注册、修复、移除和冲突保护测试,并验证单文件真实编辑保存、真实 PTY 命令及中英/明暗无头截图。尚未通过真实系统终端完成注册到 GUI 的端到端验收。Windows 无本地来宾,规则测试及 Windows 目标编译通过,不代表原生验收完成。", + "verification": "macOS:打开通用 > CLI 时不写来源;点击注册后新终端能使用 lithe,分别传入带空格/中文文件、文件夹和 -- 保护的路径;单文件只使用内置高亮,能编辑保存,默认不创建终端,无插件、项目树、Git、运行/调试/测试或父目录索引,查找动作不搜索工作区;打开 Markdown 文件时标签栏有编辑 / 编辑与预览 / 预览切换和目录按钮,渲染页跟随编辑并显示相对路径图片,SVG、HTML 仍只显示源码。点击终端后使用当前文件目录,真实命令输出可见,隐藏后重开复用会话,关闭窗口清理 shell。以项目打开所在文件夹在新窗口走正常信任和插件流程。修复应用移动后的启动器;移除注册保留无关 shell 内容。Windows:检查 HKCU Environment Path 类型与无关项保留、外部修改冲突、环境广播、新 cmd/PowerShell 中调用及移除,原生运行待验收。", + "notes": "已在 macOS 执行真实临时配置注册、修复、移除和冲突保护测试,并验证单文件真实编辑保存、真实 PTY 命令及中英/明暗无头截图;Markdown 渲染页与视图切换(#2324)有无头回归和截图,原生网页引擎下的渲染页待两端验收。尚未通过真实系统终端完成注册到 GUI 的端到端验收。Windows 无本地来宾,规则测试及 Windows 目标编译通过,不代表原生验收完成。", "macos": { "implementationStatus": "implemented", "verificationStatus": "pending", @@ -14,6 +14,7 @@ "desktop/internal/cli/registration.go", "desktop/internal/core/cli.go", "desktop/internal/workbench/standalone.go", + "desktop/internal/workbench/editor_view.go", "desktop/internal/settingswindow/cli_view.go", "desktop/internal/workbench/standalone_test.go", "desktop/internal/core/cli_test.go", @@ -32,6 +33,7 @@ "desktop/internal/cli/registration.go", "desktop/internal/core/cli.go", "desktop/internal/workbench/standalone.go", + "desktop/internal/workbench/editor_view.go", "desktop/internal/settingswindow/cli_view.go", "desktop/internal/workbench/standalone_test.go", "desktop/internal/core/cli_test.go",