feat(macos): 添加编辑器按行号跳转对话框 - #351
Conversation
Add three mouse-reachable entries for jumping to a line: the Navigate menu, the editor context menu, and the status bar caret label, all opening a shared go-to-line bar styled after the find bar. Input accepts 1-based line or line:column, converges out-of-range values against the live document, selects the target line through the existing editorNavigationTarget pathway (now carrying selectsWholeLine), and records navigation history so Cmd+[ returns to the departure position. The bar and the find bar are mutually exclusive; Cmd+L is registered in the command catalog and remappable in Keymap settings.
Swap the in-editor go-to-line bar for a small modal "Go to Line:Column" window: a single [Line] [:column]: input prefilled with the caret's 1-based position and fully selected, with Cancel/OK buttons. Return and OK jump through the same parser and navigation pathway, invalid input disables OK, and Esc, Cancel, or the close button dismiss without side effects. Every entry point (Navigate menu, editor context menu, status bar caret label, Cmd+L) funnels through the chrome visibility flag via a shared presenter, so the workbench and standalone editor windows both stay covered. Also unify all go-to-line comments to English to match the surrounding files.
The dialog panel fell back to the system appearance and rendered light inside a dark-themed editor. Apply the same AppThemePreference window appearance the workbench windows use, so the dialog matches the editor theme in system, light, and dark modes. Widen the private AppThemePreference.windowAppearance helper for reuse.
…og count The Simplified Chinese localization test requires every command catalog entry to carry translated title and subtitle strings, and the keyboard shortcut test pins the catalog size. Cover the new go-to-line command and bump the expected count to 33.
1lck
commented
Aug 30, 2026
有大量冲突 |
…o-line-preview # Conflicts: # macos/Resources/zh-Hans.lproj/Localizable.strings # macos/Sources/Lithe/Models/AppModel/AppModel+FeatureState.swift # macos/Sources/Lithe/Models/Keymap/LitheCommandCatalog.swift # macos/Sources/Lithe/Models/LitheAction.swift # macos/Tests/LitheTests/EditorChromeModelTests.swift
Wz58luck
commented
Aug 30, 2026
已解决 |
There was a problem hiding this comment.
整体分层和接入方式是合理的:入口统一经过 AppModel,解析逻辑独立,Keymap、导航历史、状态栏/菜单/右键菜单均已覆盖,相关 CI 也全部通过。不过当前有几个用户可见的问题,建议修复后再合并。
[P1]
line:column的列号在最终编辑器状态中被丢弃macos/Sources/Lithe/Views/Editor/CodeEditorView.swift:1330-1344虽然计算了目标列location,但selectsWholeLine == true时最终始终从lineStart开始整行选择。因此输入120:35后,编辑器实际状态会落在第 120 行第 1 列;导航历史前进时也无法恢复第 35 列。建议保留“是否显式输入列号”的信息:只有未输入列号时才考虑整行选择;输入了列号时应将 caret 放到该列。也可以直接取消整行选择,遵循常见的 Go to Line/Column 行为。
[P2] 换行符处理与编辑器自己的行索引规则不一致
macos/Sources/Lithe/Models/Editor/GoToLineInput.swift:31-40仅按\n分行,而编辑器的TextLineIndex同时识别 LF、CRLF 和 CR(CodeEditorView.swift:1424-1436)。这会导致 CR-only 文件的目标行错误,CRLF 文件的列上限多算一个\r。此外CodeEditorView.swift:1334-1337只剔除 LF,CRLF 的整行选择会把 CR 一并选中。建议复用或提取统一的 UTF-16 行索引/行范围实现,并补充 CRLF、CR 测试。
[P2] AppKit 新界面没有真正使用本地化资源
GoToLineDialog.swift:62-118的窗口标题、标签、Cancel、OK,以及CodeEditorView.swift:2877-2883的右键菜单标题都直接使用英文字符串。AppKit 不会像 SwiftUI 字符串字面量一样自动查询Localizable.strings,所以即使资源文件增加了翻译,简体中文环境仍会显示英文。
验证情况:本地 verify-service-boundaries.sh 和 git diff --check 通过;GoToLine、EditorChrome、NavigationHistory、KeyboardShortcut 相关 39 个测试通过。现有测试主要覆盖解析和状态,没有覆盖“输入 line:column 后编辑器最终 caret/selection”的完整行为,建议为此补一组回归测试。
Address review feedback on the go-to-line PR: - Line-only jumps keep selecting the whole target line, but an explicitly entered column now places the caret at that column via a hasExplicitColumn flag threaded through GoToLineInput and the navigation target, so "120:35" no longer lands at column one. - GoToLineInput.clamped and the new GoToLineSelection helper share the editor's line-index rules (LF, CRLF, CR), so CR-only files jump to the right line and CRLF whole-line selections no longer include the carriage return. applyNavigationTargetIfNeeded now delegates to the helper, giving the final caret/selection a unit-tested pure implementation with CRLF, CR, and edge-case regression coverage. - The AppKit dialog strings (title, label, Cancel, OK) and the context menu item now resolve through Localizable.strings instead of literal English, with new Simplified Chinese entries.
The regression test called clamped without forwarding the parsed hasExplicitColumn flag, unlike the production goToLine path, so the preservation assertion failed. Mirror the production call and also assert the converged target.
Wz58luck
commented
Aug 30, 2026
已解决 |
1lck
left a comment
There was a problem hiding this comment.
复审通过。上一轮三项阻塞问题均已闭环:显式 line:column 现在保留列号并落到零长度 caret;LF、CRLF、CR 的行索引与整行选区使用一致的 UTF-16 规则且排除行终止符;AppKit 对话框与右键菜单字符串已显式本地化。新增的 GoToLineSelection 将最终 NSTextView range 计算提取为可测试逻辑,覆盖显式列号、越界、空文档、尾随换行、CRLF 与 CR-only 场景。\n\n本地验证:verify-service-boundaries.sh 通过;GoToLineInput 16 tests、GoToLineSelection 9 tests,以及 EditorChrome/NavigationHistory/Keyboard 相关 23 tests 通过;git diff --check 通过。GitHub CI 全部通过。
Wz58luck
commented
Aug 30, 2026
ok |
Uh oh!
There was an error while loading. Please reload this page.
Closes#341
概述
新增 "Go to Line:Column" 按行号跳转对话框——经典 IDE 风格的小型模态浮窗:单个
[Line] [:column]:输入位,打开时预填当前光标的 1-based 位置并全选,附 Cancel / OK 按钮。go-to-line),可在 设置 → Keymap 中修改。120或120:35,容忍空格;非法输入时 OK 按钮置灰,Return 不会跳转。越界行号收敛到最后一行,越界列号收敛到行尾(按 UTF-16 单元计),空文档只定位到文档开头。navigateToEditorLocation——自动打开文档、进入导航历史(Cmd+[ 可回到跳转前的位置),并通过新增的selectsWholeLine标志整行选中目标行(默认false,既有的符号/查找导航保持零长度光标不变)。AppThemePreference外观,在 system / light / dark 模式下都与编辑器保持一致。EditorChromeModel。测试