Skip to content

feat(macos): 添加编辑器按行号跳转对话框 - #351

Merged
1lck merged 8 commits into
1lck:previewfrom
Wz58luck:feat/editor-go-to-line-preview
Aug 30, 2026
Merged

feat(macos): 添加编辑器按行号跳转对话框#351
1lck merged 8 commits into
1lck:previewfrom
Wz58luck:feat/editor-go-to-line-preview

Conversation

@Wz58luck

@Wz58luckWz58luck commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Closes#341

概述

新增 "Go to Line:Column" 按行号跳转对话框——经典 IDE 风格的小型模态浮窗:单个 [Line] [:column]: 输入位,打开时预填当前光标的 1-based 位置并全选,附 Cancel / OK 按钮。

  • 三个鼠标可达入口(issue 明确要求):Navigate 菜单、编辑器右键菜单、状态栏的行:列指示(改为 plain 样式按钮,视觉保持不变)。无活动文档时禁用或为无操作。
  • Cmd+L 已注册进命令目录(go-to-line),可在 设置 → Keymap 中修改。
  • 输入:支持 120120:35,容忍空格;非法输入时 OK 按钮置灰,Return 不会跳转。越界行号收敛到最后一行,越界列号收敛到行尾(按 UTF-16 单元计),空文档只定位到文档开头。
  • 跳转行为:复用 navigateToEditorLocation——自动打开文档、进入导航历史(Cmd+[ 可回到跳转前的位置),并通过新增的 selectsWholeLine 标志整行选中目标行(默认 false,既有的符号/查找导航保持零长度光标不变)。
  • 主题:对话框应用与工作台窗口相同的 AppThemePreference 外观,在 system / light / dark 模式下都与编辑器保持一致。
  • 互斥:打开对话框会先关闭查找栏,反之亦然,逻辑收敛在 EditorChromeModel

测试

image

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.
@Wz58luck
Wz58luck requested a review from 1lck as a code ownerAugust 30, 2026 08:10
@1lck

1lck commented Aug 30, 2026

Copy link
Copy Markdown
Owner

有大量冲突

Wz58luckand others added 2 commits August 30, 2026 17:35
…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

Copy link
Copy Markdown
ContributorAuthor

已解决

@1lck1lck left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

整体分层和接入方式是合理的:入口统一经过 AppModel,解析逻辑独立,Keymap、导航历史、状态栏/菜单/右键菜单均已覆盖,相关 CI 也全部通过。不过当前有几个用户可见的问题,建议修复后再合并。

  1. [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 行为。

  2. [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 测试。

  3. [P2] AppKit 新界面没有真正使用本地化资源

    GoToLineDialog.swift:62-118 的窗口标题、标签、Cancel、OK,以及 CodeEditorView.swift:2877-2883 的右键菜单标题都直接使用英文字符串。AppKit 不会像 SwiftUI 字符串字面量一样自动查询 Localizable.strings,所以即使资源文件增加了翻译,简体中文环境仍会显示英文。

验证情况:本地 verify-service-boundaries.shgit 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

Copy link
Copy Markdown
ContributorAuthor

已解决

@Wz58luck
Wz58luck requested a review from 1lckAugust 30, 2026 13:20

@1lck1lck left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审通过。上一轮三项阻塞问题均已闭环:显式 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

Copy link
Copy Markdown
ContributorAuthor

ok

@1lck
1lck merged commit cdfc98d into 1lck:previewAug 30, 2026
15 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@Wz58luck@1lck