Skip to content

TextFlow 交互优化:浮窗主链路、剪贴板回退与 OCR 打磨 - #1

Merged
BA7IEE merged 12 commits into
mainfrom
claude/textflow-interaction-optimization-eaed07
Aug 13, 2026
Merged

TextFlow 交互优化:浮窗主链路、剪贴板回退与 OCR 打磨#1
BA7IEE merged 12 commits into
mainfrom
claude/textflow-interaction-optimization-eaed07

Conversation

@BA7IEE

@BA7IEE BA7IEE commented Aug 13, 2026

Copy link
Copy Markdown
Owner

把「编辑原文 → 重新翻译」的主链路修顺,补齐错误状态的恢复入口,并让几个高频操作少一次往返。共 18 项,按四批提交。

第一批:浮窗主链路(21ad0b1)

  • 原文框换成 AppKit 实现的 OriginalTextEditor,回车即翻译;正在翻译时回车会取消当前请求并用当前原文重翻。
  • 输入法组字期间(hasMarkedText())回车交给输入法,Shift/Option + 回车 插入换行。判断逻辑抽成 OriginalTextSubmitPolicy,可单测。
  • 原文操作行新增「翻译」按钮,作为回车的鼠标等价入口。
  • 翻译失败的错误行新增「重试」;未配置翻译模型时新增「打开设置」。

第二批:剪贴板相关(d195188)

  • Accessibility 与 ⌘C 兜底都失败时,若剪贴板有文本,则填入原文框、注明来源,并提供「翻译剪贴板内容」与「开始 OCR」。默认不自动翻译。
  • 新增通用设置:无选中文字时自动翻译剪贴板(默认关)、OCR 完成后自动复制识别文字(默认开)、翻译完成后自动复制译文(默认关)。
  • 面板 view model 支持注入 NSPasteboard,复制相关单测不再污染开发机剪贴板。

第三批:浮窗行为(bf3595b)

  • 「更多」菜单选中日/韩/繁后显示当前语言名并呈现选中态。
  • 已固定且已显示的浮窗不再被拖回鼠标位置,只刷新内容。
  • 流式译文自动滚动到底部;用户手动上滚后本次翻译停止跟随。
  • 浮窗内手动切过目标语言后,浮窗可见期间的后续 ⌥D/⌥Q 不再被自动检测覆盖,关闭后恢复。
  • 浮窗头部新增会话级预设菜单,切换即重翻,不修改设置里的默认预设。

第四批:OCR 细节与打磨(db5cb29)

  • OCR 结果新增「重新框选」,等价于再走一遍 ⌥Q。
  • 框选覆盖层在开始拖拽前显示「拖拽框选文字 · Esc 取消」。
  • 取词中 / 识别中原文框只读。
  • accessory 应用没有主菜单,borderless 浮窗自己把 ⌘A/⌘C/⌘V/⌘X/⌘Z 分发给第一响应者;⌘⇧C 复制译文,并写进复制按钮的 help。
  • 新增通用设置:翻译完成后自动朗读译文(默认关)。

文档(0292805、e66f9a1)

同步 01_PRD_v0.1.md:§3.1C 剪贴板兜底分支、§3.1F 重新翻译入口与目标语言粘性、§3.1G 浮窗预设切换、§3.1I 面板结构图与新行为、§3.1K 四个新通用设置及默认值。

隐私与红线

不保存任何历史(剪贴板兜底只读当前内容);取词失败不会自动开始 OCR 或屏幕捕获;OCR 仍在本地 Vision;未新增第三方依赖;诊断日志只记长度与开关状态,不记内容。

验证

  • xcodebuild -project TextFlow.xcodeproj -scheme TextFlow -configuration Debug -derivedDataPath DerivedData CODE_SIGNING_ALLOWED=NO test → Executed 117 tests, 0 failures(新增 26 个)。
  • ./scripts/build-debug.sh → BUILD SUCCEEDED。
  • 通过一次性渲染测试检查了面板三种状态(OCR 结果、剪贴板提示、未配置错误)的真实布局。
  • ⌥D、⌥Q、回车翻译、剪贴板回退四条路径由维护者在本地安装构建(./scripts/install-local.sh)中人工验证通过。

BA7IEE added 12 commits August 2, 2026 00:51
- Replace the SwiftUI TextEditor with an AppKit-backed original text
  editor so Enter re-translates the current text, while marked text
  (IME composition) and Shift/Option+Enter keep default behavior.
- Add an explicit 翻译 button as the mouse equivalent of Enter.
- Offer 重试 on failed translations and 打开设置 when no translation
  profile is configured.

Tests: xcodebuild -project TextFlow.xcodeproj -scheme TextFlow \
  -configuration Debug -derivedDataPath DerivedData \
  CODE_SIGNING_ALLOWED=NO test -> Executed 90 tests, 0 failures
- When accessibility and the ⌘C fallback both fail, offer the text that
  is already on the clipboard: it is filled into the original field with
  a source note and a 翻译剪贴板内容 action, next to 开始 OCR. Nothing is
  translated automatically unless the new setting says so.
- New general settings: 无选中文字时自动翻译剪贴板 (off),
  OCR 完成后自动复制识别文字 (on), 翻译完成后自动复制译文 (off).
- The panel view model now takes an injectable pasteboard so copy tests
  no longer touch the developer's clipboard.

Tests: xcodebuild ... test -> Executed 97 tests, 0 failures
- The 更多 menu now shows the active language and marks it as selected
  instead of always reading 更多.
- A pinned, already visible panel no longer jumps back to the mouse when
  a new task shows content; it only refreshes in place.
- Streaming translations scroll to the bottom, and stop following once
  the user scrolls up during that run.
- A target language picked inside the panel sticks for later ⌥D/⌥Q while
  the panel stays open, and returns to auto detection after it closes.
- Added an in-panel preset menu that re-translates immediately and only
  affects the current panel session.

Tests: xcodebuild ... test -> Executed 110 tests, 0 failures
- OCR results offer 重新框选, which re-runs the full ⌥Q flow.
- The selection overlay shows 拖拽框选文字 · Esc 取消 until the drag starts.
- The original field is read-only while text is being captured or
  recognized, so results cannot overwrite what the user is typing.
- The borderless panel now dispatches ⌘A/⌘C/⌘V/⌘X/⌘Z to its first
  responder (an accessory app has no main menu to do it) and handles
  ⌘⇧C as copy translation, which the copy button's help text mentions.
- New general setting 翻译完成后自动朗读译文 (off).

Tests: xcodebuild ... test -> Executed 117 tests, 0 failures
Build: ./scripts/build-debug.sh -> BUILD SUCCEEDED
- §3.1G: the panel now offers a session-scoped preset switch that
  re-translates immediately and never changes the default preset.
- §3.1I: auto copy and auto speak are settings-driven; only
  OCR 完成后自动复制识别文字 defaults to on.
- §3.1K: list the four new general settings with their defaults.

Docs only; no behavior change.
- §3.1C: describe the clipboard fallback branch and its setting, and
  state that no clipboard history is kept.
- §3.1F: list every re-translate entry (Enter with its IME and newline
  rules, 翻译 button, current language, 重试) and the 更多 menu title plus
  the session-scoped target language.
- §3.1I: refresh the panel sketch and add pinned positioning, the
  keyboard shortcuts, the read-only capture states, and stream
  auto-scroll.

Docs only; no behavior change.
@BA7IEE
BA7IEE merged commit 558f261 into main Aug 13, 2026
1 check passed
@BA7IEE
BA7IEE deleted the claude/textflow-interaction-optimization-eaed07 branch August 13, 2026 06:50
Sign up for free to 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.

1 participant