Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 16, 2025

Cmd+V in iTerm2 pastes clipboard content twice when Easydict is running. Root cause: stopCGEventTap() created a new CFRunLoopSourceRef instead of removing the original, leaving the event tap active after "stopping".

Changes

  • Store CFRunLoopSourceRef in eventTapRunLoopSource property for proper lifecycle management
  • Remove premature CFRelease() in monitorCGEventTap() to keep source alive
  • Fix stopCGEventTap() to remove and release the stored source
// Before: created new source, never removed original
CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(..., self.eventTap, 0);
CFRunLoopRemoveSource(..., runLoopSource, ...);  // Wrong source!

// After: remove the actual source we added
if (self.eventTapRunLoopSource) {
    CFRunLoopRemoveSource(..., self.eventTapRunLoopSource, ...);
    CFRelease(self.eventTapRunLoopSource);
    self.eventTapRunLoopSource = NULL;
}

Impact

  • Fixes duplicate paste in iTerm2 (and potentially other terminal emulators)
  • Prevents CGEventTap resource leak
  • No functional changes to event monitoring behavior
Original prompt

This section details on the original issue you should resolve

<issue_title>🐞 反馈问题:iTerm2中,⌘ + v会粘贴两次</issue_title>
<issue_description>### 请先确认以下事项:

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

问题描述

Easydict使用最新版本,iTerm2使用3.6.1版本

打开了Easydict后,在iTerm2中使用⌘+C复制后,在iTerm2中使用⌘+v粘贴会粘贴两次。

退出Easydict后,在iTerm2中使用⌘+C复制后,在iTerm2中使用⌘+v粘贴恢复正常。

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

可重现

重现步骤

打开了Easydict后,在iTerm2中使用⌘+C复制后,在iTerm2中使用⌘+v粘贴。

截图

Image

运行日志(zip 文件)

no

期望结果

no

解决方案(可选)

No response

设备型号 && 系统版本

MacOS 26

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

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

<agent_instructions>帮我仔细调查这个问题,并修复。</agent_instructions>

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

@tisfeng > 打开了Easydict后,在iTerm2中使用⌘+C复制后,在iTerm2中使用⌘+v粘贴会粘贴两次。

你好,我这边测试,没有发现这个问题。我 iTerm2 是 3.6.2 版本。</comment_new>
<comment_new>@tisfeng
请提供运行日志 zip 文件

请提供运行日志 zip 文件,方便开发者排查:菜单图标 -> 帮助 -> 导出日志。(日志目录:~/Library/Caches/com.izual.Easydict/MMLogs)

@tisfeng 我来看看。 @tisfeng 试了一下,还真是,很奇怪的问题。。。

稍后我来查一下。</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Fixed a bug in stopCGEventTap() that was creating a new CFRunLoopSourceRef instead of properly removing the original one. This could cause the event tap to not be properly cleaned up, leading to duplicate key events in iTerm2.

Co-authored-by: tisfeng <25194972+tisfeng@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with double paste in iTerm2 Fix CGEventTap run loop source leak causing duplicate paste in iTerm2 Nov 16, 2025
Copilot AI requested a review from tisfeng November 16, 2025 17:35
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.

🐞 反馈问题:iTerm2中,⌘ + v会粘贴两次

2 participants