Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 6, 2025

When pasting text (Cmd+V) after switching apps with alt-tab, the pasted text gets auto-selected by many applications. EasyDict's auto-select feature then detects this selection and shows the pop button window at kCGScreenSaverWindowLevel, briefly stealing focus and causing flickering.

Changes

  • Event detection: Track Cmd+V keydown events and record timestamp using NSProcessInfo.processInfo.systemUptime
  • Auto-select suppression: Skip auto-select if paste occurred within last 500ms
  • Code cleanup: Extract common Cmd+Key detection logic into shared helper method
// Suppress auto-select briefly after paste to avoid focus stealing
NSTimeInterval currentTime = NSProcessInfo.processInfo.systemUptime;
NSTimeInterval timeSinceLastPaste = currentTime - self.lastPasteTime;
if (self.lastPasteTime > 0 && timeSinceLastPaste < kSuppressAutoSelectAfterPasteInterval) {
    return;  // Skip auto-select
}

Impact

  • Auto-select remains functional for manual selections (double-click, triple-click, shift-click, drag)
  • No behavioral changes outside the 500ms post-paste window
Original prompt

This section details on the original issue you should resolve

<issue_title>🐞 反馈问题:复制文本后,使用 Alt-tab 切换到特定应用粘贴时会出现闪切</issue_title>
<issue_description>### 请先确认以下事项:

  • 请务必查看 常见问题
  • 已仔细阅读了 README
  • issues 页面搜索过问题(包括已关闭的 issue),但未能找到解决方法
  • Easydict 已升级到 最新版本
  • 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

问题描述

从网页上复制一段文本后,使用 alt-tab 切换到特定应用(Ghostty) 后,粘贴文本会出现闪切,失焦。
通过退出 EasyDict 后,这个问题不会再出现

该问题是否可以稳定重现?

可重现

重现步骤

一些相关App:Edge 、alt-tab、Ghostty
复现操作同问题描述

截图

PixPin_2025-12-04_16-48-38.mp4
Image Image Image

运行日志(zip 文件)

若有需要,可以联系我上传

期望结果

粘贴文本后,焦点保持在切换后的App窗口上

解决方案(可选)

No response

设备型号 && 系统版本

M4 macOS Tahoe 26.1

是否愿意提交 PR 解决该问题?

  • 我愿意提交 PR 来解决该问题</issue_description>

<agent_instructions>帮我仔细调查这个问题</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits December 6, 2025 03:57
…Cmd+V

When user pastes text (Cmd+V) in an application and the pasted text gets automatically selected, EasyDict's auto-select feature would detect this selection and show the pop button window, causing focus to briefly shift to EasyDict and then back, creating a flickering effect.

This fix:
- Detects Cmd+V paste operations in the event monitor
- Tracks the timestamp of the last paste operation
- Suppresses auto-select text feature for 0.5 seconds after a paste to prevent the pop button from appearing
- This allows the user to paste text without interruption while maintaining auto-select functionality for manual text selection

Fixes: https://github.com/tisfeng/Easydict/issues/xxx

Co-authored-by: tisfeng <25194972+tisfeng@users.noreply.github.com>
Address code review feedback:
- Use NSProcessInfo.processInfo.systemUptime consistently for time tracking instead of mixing event.timestamp and NSDate.timeIntervalSinceReferenceDate
- Only detect NSEventTypeKeyDown for paste events to avoid double detection
- Add check for lastPasteTime > 0 to ensure valid comparison on first run

Co-authored-by: tisfeng <25194972+tisfeng@users.noreply.github.com>
While kVK_ANSI_C was already working without explicit import (likely through transitive includes), adding explicit Carbon.h import ensures kVK_ANSI_V and other virtual key code constants are always available.

Co-authored-by: tisfeng <25194972+tisfeng@users.noreply.github.com>
Extract common logic for detecting Cmd+Key combinations into a shared helper method `isCmdKeyEvent:withKeyCode:` to improve maintainability and reduce duplication between isCmdCEvent and isCmdVEvent.

Co-authored-by: tisfeng <25194972+tisfeng@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix paste glitch when switching apps using Alt-tab Suppress auto-select for 500ms after Cmd+V to prevent focus stealing on paste Dec 6, 2025
Copilot AI requested a review from tisfeng December 6, 2025 04:07
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.

🐞 反馈问题:复制文本后,使用 Alt-tab 切换到特定应用粘贴时会出现闪切

2 participants