Skip to content

Fix duplicated characters when typing after Spotlight is dismissed - #329

Open
Quocker22 wants to merge 1 commit into
tuyenvm:masterfrom
Quocker22:fix/spotlight-duplicate-chars
Open

Fix duplicated characters when typing after Spotlight is dismissed#329
Quocker22 wants to merge 1 commit into
tuyenvm:masterfrom
Quocker22:fix/spotlight-duplicate-chars

Conversation

@Quocker22

Copy link
Copy Markdown

Sửa lỗi đúp chữ khi gõ tiếng Việt ở app khác ngay sau khi vừa dùng Spotlight.

Vấn đề (Problem)

isSpotlightVisible() trả về true bất cứ khi nào có một cửa sổ do process "Spotlight" sở hữu tồn tại trong danh sách cửa sổ on-screen. Tuy nhiên, khi Spotlight vừa bị đóng (hoặc đang fade-out), cửa sổ đó vẫn còn sót lại trong danh sách một lúc. Hệ quả: OpenKey vẫn dùng nhánh selection-replacement (Shift+Left rồi gõ đè) trong khi người dùng đã chuyển sang gõ ở app khác. Ở những app không hợp tác với cơ chế này, ký tự gõ đè bị chèn thêm thay vì thay thế → sinh ra ký tự lặp (đúp chữ).

isSpotlightVisible() previously returned true whenever a window owned by "Spotlight" existed anywhere in the on-screen window list. A dismissed/fading Spotlight window lingers there, so OpenKey kept using the selection-replacement path while the user was already typing in another app, producing duplicated characters.

Cách sửa (Fix)

Siết chặt điều kiện: chỉ coi Spotlight là đang hoạt động khi cửa sổ của nó thực sự đang được vẽ (kCGWindowAlpha > 0) và nổi trên các cửa sổ app thường (kCGWindowLayer > 0), qua đó loại bỏ các cửa sổ Spotlight sót lại / đang fade.

Only count Spotlight as active when its window is actually drawn (alpha > 0) and floats above normal app windows (layer > 0), excluding stale/fading leftover windows.

Không thay đổi logic gõ tiếng Việt; chỉ chỉnh đúng một hàm nhận diện Spotlight.

Kiểm chứng (Testing)

Tái hiện và xác nhận đã hết lỗi trên macOS (Apple Silicon), cấu hình Telex + Unicode + bật "Sửa lỗi gợi ý (trình duyệt, Excel...)":

  1. Mở Spotlight (Cmd+Space), gõ tiếng Việt.
  2. Đóng Spotlight.
  3. Gõ tiếng Việt ngay ở app khác (Notes / trình duyệt / Messages).

Trước fix: ký tự bị đúp. Sau fix: gõ bình thường.

isSpotlightVisible() previously returned true whenever a window owned by
"Spotlight" existed anywhere in the on-screen window list. A dismissed or
fading Spotlight window can linger in that list, so OpenKey wrongly kept
using the selection-replacement path (Shift+Left + overwrite) while the
user was already typing in another app. On apps that don't cooperate with
that path, the overwrite is appended instead of replacing, producing
duplicated characters.

Tighten the check to only count Spotlight as active when its window is
actually being drawn (alpha > 0) and floats above normal app windows
(window layer > 0), which excludes stale/fading leftover windows.

Reproduced and verified fixed on macOS (Apple Silicon) with Telex +
Unicode and "Fix browser/Excel suggestions" enabled: open Spotlight, type
Vietnamese, dismiss, then type in another app.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Ro8o88gTWKFHDPaXwCvzR
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