fix(selection-polish): 選區潤色預覽確認按鈕偶發無反應 - #1045
Draft
leonoxo wants to merge 1 commit into
Draft
Conversation
圈選潤色的「確認並替換」偶爾沒反應,根因鏈有四個,分別處理: 1. 预览窗 show 抢焦点:show_selection_polish_preview 走 window.show() + set_focus()(tao 层 makeKeyAndOrderFront + NSApp.activate),把 OpenLess 推成 frontmost;原 app 丢前台后编辑器的选区被清,之后 confirm 的 reactivate/validate 就「有时」失败。预览窗改成与胶囊/QA 同手法的 Nonactivating NSPanel(to_panel + styleMask 先读再 OR NonactivatingPanel 位——set_style_mask 是全量替换;level 3 + FullScreenAuxiliary/CanJoinAllSpaces 叠全屏 app),show 走主线程 orderFrontRegardless,不 makeKey、不激活 app。 2. 失败即杀 session:confirm 任何 Err 都 fail_if_active → Failed + 隐藏预览, 用户刚编辑的内容直接丢,只剩「点确认没反应」。分流:session 失效 (Cancelled/InvalidState/InvalidArgument/Busy)才结算失败并隐藏; 瞬时平台错误(焦点恢复/目标复核抖动)回退 Preview 保持可重试。 fail_if_active 加相位保护:只结算 Capturing/Preview/Applying,已 Completed 的不再被误标 Failed(complete 与 fail 之间的窄窗口)。 3. reactivate 固定 120ms:部分 app(Electron、自绘窗口)恢复 key window 需要更久,固定 sleep 一次就核 pid 会偶发误判「恢复失败」。改成 80ms x 4 轮询,每轮补一次 activate(幂等),pid 稳定立刻返回。 4. 前端 busy 卡死:预览窗复用(hide 不卸载组件),上一轮 confirm/cancel 后 busy 停留 true,下一轮两个按钮全 disabled。「shown」事件到达时 复位 busy/error。 验证:cargo check/test openless-core(含契约测试 transient_platform_failure_keeps_the_preview_retryable)全绿; src-tauri 本机因缺 Metal 工具链(qwen3-asr-rs 需要完整 Xcode)无法整树 check,新窗口代码已用同版本依赖(tauri 2.11.5 / tauri-nspanel v2 / objc2 0.5.2)的独立 crate 编译验证通过;前端 tsc + 71 个前端测试全绿。 macOS 实机行为(预览不抢焦点、confirm 重试)需要 CI(submodules: recursive) 或本机装完整 Xcode 后验证。
Collaborator
|
抱歉,我们写得很清楚:目前正在进行 2.0 的优化,所以暂不接受任何 PR。如果你希望 PR 能继续推进并成功完成,可能需要等我们完全迁移到 2.0 的新后端、新前端之后,再针对这个问题进行解决。 |
Collaborator
我先合你的,再合ta的,就这么简单 |
leonoxo
marked this pull request as draft
September 10, 2026 06:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要
圈選潤色(選區潤色)在 macOS 上「確認並替換」偶爾沒反應:點了按鈕後沒有貼上、窗口也没動靜,再點就完全無效。排查後是四個問題疊加,本 PR 針對選區潤色 apply 路徑逐一處理(不碰 dictation 全域 insert、不加 AX WRITE、不做貼上後自動驗證)。
根因
show_selection_polish_preview走window.show()+set_focus()(tao 層makeKeyAndOrderFront+NSApp.activate,已核對 tao 源碼),把 OpenLess 推成 frontmost;原 app 丟前台後,不少編輯器的選區直接被清,之後 confirm 的 reactivate/validate 就「有時」失敗。Err都fail_if_active→Failed+ 隱藏預覽,用戶剛編輯的內容直接丟掉,表象就是「點確認沒反應」。busy停留 true,下一輪兩個按鈕全 disabled——即使後端恢復正常,按鈕也點不動。修復
to_panel()後 styleMask 先讀再 OR NonactivatingPanel 位(set_style_mask是全量替換,直接 set 會丟掉 titled/resizable),set_level(3)+FullScreenAuxiliary | CanJoinAllSpaces可疊全屏 app;show 改主線程orderFrontRegardless,不 makeKey、不激活 app;hide 也統一派發回主線程(NSPanel 不可從 worker 線程操作)。Cancelled/InvalidState/InvalidArgument/Busy)才結算失敗並隱藏;瞬時平台錯誤(焦點恢復/目標複核抖動)回退Preview保持可重試,編輯內容不丟。fail_if_active加相位保護:只結算Capturing/Preview/Applying,已Completed的不再被誤標Failed(complete 與 fail 判斷之間的窄窗口 race)。activate_app_by_pid(幂等),pid 一穩定立刻返回;仍未恢復則明確失敗,不向偶然持有焦點的 app 盲寫。selection-polish-preview:shown事件到達時復位busy/error再載入資料。驗證
cargo check/test -p openless-core:全綠(含契約測試改名transient_platform_failure_keeps_the_preview_retryable,斷言瞬時失敗後 session 保持可重試、不 cancel 不隱藏)。src-tauri整樹本地無法 check(qwen3-asr-rs的 MLX/Metal 需要完整 Xcode,CI 用submodules: recursive可編過),此 PR 不觸及該路徑。tsc+ 71 個前端測試全綠。相容
insert()、AX 唯讀策略均未改動。show()/set_focus()路徑不變。