Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 功能建议:增加快捷键以“复制首个翻译结果” #151

Closed
4 tasks done
rainzm opened this issue Aug 4, 2023 · 12 comments · Fixed by #155
Closed
4 tasks done

🚀 功能建议:增加快捷键以“复制首个翻译结果” #151

rainzm opened this issue Aug 4, 2023 · 12 comments · Fixed by #155
Assignees
Labels
enhancement New feature or request fixed in next release The issue will be closed once next release is available

Comments

@rainzm
Copy link
Contributor

rainzm commented Aug 4, 2023

请先确认以下事项

  • 已仔细阅读了 README
  • issues 页面搜索过(包括已关闭的 issue),未发现类似功能建议
  • Easydict 已升级到最新版本

功能描述

增加快捷键以“复制首个翻译结果”

使用场景(可选)

目前 Easydict 可以自动复制首个翻译结果,很多时候,比如选中翻译的结果通常不需要复制,否则会污染粘贴板。

但是我又需要 “快捷复制首个翻译结果” 这个功能,因为我使用 Easydict 的一大场景是在编程或者其他写作的时候,做英文编写的辅助。

这个过程中,我倾向于不使用鼠标,使用快捷键打开 Easydict 的翻译框,输入并回车,然后通过快捷键复制到结果,然后切换回写作。

实现方案(可选)

No response

是否愿意提交 PR 实现该功能

  • 我愿意提交 PR!
@rainzm rainzm added the enhancement New feature or request label Aug 4, 2023
@github-actions
Copy link

github-actions bot commented Aug 4, 2023

Hello rainzm, Thank you for your first issue contribution 🎉

@Jerry23011
Copy link
Collaborator

Hi @rainzm

看到你愿意提交 PR!如果没问题的话,我可以把这个 issue assign 给你吗😄

@rainzm
Copy link
Contributor Author

rainzm commented Aug 4, 2023

我蛮有兴趣的。不过我没写过object-c,所以能不能给我一些指导:

  1. object-c 是不是用 xcode 开发最方便呢?
  2. 目前已经有的功能“自动复制第一个翻译结果”的代码在哪个地方?
  3. 帮我指出一个现在已经有的快捷键的代码

我想会对我的参与有很大的帮助,谢谢。

@Jerry23011
Copy link
Collaborator

Jerry23011 commented Aug 4, 2023

我蛮有兴趣的。不过我没写过object-c,所以需要你的一些指导:

我不会 objc,这个还是需要找 @tisfeng

object-c 是不是用 xcode 开发最方便呢?

这个项目就是用 Xcode 搭建的

目前已经有的功能“自动复制第一个翻译结果”的代码在哪个地方?

这个应该在 EZBaseQueryViewController.m 中的最下面,那里有注释 /// Auto copy translated text.,具体的细节请问 @tisfeng

@tisfeng
Copy link
Owner

tisfeng commented Aug 4, 2023

@rainzm 你好,我想了一下,如果 “复制首个翻译结果” 是个高频操作,确实可以考虑添加一个快捷键。

另外,从你描述的应用场景来看,我觉得也可以在设置页添加一个类似 “自动复制除【自动划词翻译】外的第一个翻译结果” 的设置选项,这样似乎更方便?

我很少使用这样功能,你可以考虑测试一下,看看那个方案更好。

目前 Easydict 可以自动复制首个翻译结果,很多时候,比如选中翻译的结果通常不需要复制,否则会污染粘贴板。

但是我又需要 “快捷复制首个翻译结果” 这个功能,因为我使用 Easydict 的一大场景是在编程或者其他写作的时候,做英文编写的辅助。

image

@tisfeng
Copy link
Owner

tisfeng commented Aug 4, 2023

@rainzm 欢迎来 PR,objc 除了方法调用的语法有点怪外,其他和别的编程语言差不多,初步可以尝试借助 ChatGPT 来写 objc 代码。

补充了一点注释,自动复制的代码就在这里。

// 这个方法会在获取第一个翻译服务结果成功时调用。

/// Auto copy translated text.
- (void)autoCopyTranslatedTextOfService:(EZQueryService *)service {

    // 如果用户没有开启【自动复制第一个翻译结果】选项,清除回调 block,直接返回。
    if (![EZConfiguration.shared autoCopyFirstTranslatedText]) {
        service.autoCopyTranslatedTextBlock = nil;
        return;
    }

    [service setAutoCopyTranslatedTextBlock:^(EZQueryResult *result, NSError *error) {
        NSString *copyText = result.translatedText;

        // 将翻译结果 copyText 写到剪贴板。
        [copyText copyToPasteboard];
    }];
}

@rainzm
Copy link
Contributor Author

rainzm commented Aug 4, 2023

@tisfeng 谢谢~ 我刚才花费了一些时间编译了下代码,然后看了下代码,得益于良好的代码风格和变量名,我有了大致的想法:

  1. 模仿EZWindowManagercopyQuertText实现copyFirstTranslatedText,绑定到快捷键。
  2. EZBaseQueryViewController增加方法copyFirstTranslatedText供上者调用,其大致逻辑应该是:通过方法allShowingResults拿到所有的EZQueryResult然后将第一个的translatedText复制到粘贴板。

你认为如何?是否有什么特别注意的点呢?

我周六尝试实现一下。

@rainzm
Copy link
Contributor Author

rainzm commented Aug 4, 2023

另外,对于这个功能,我觉得提供快捷键把主动性给到用户更好。虽然多了一步操作,但也许能覆盖更多的场景,因为总有时候不需要或者不想要复制。

@tisfeng
Copy link
Owner

tisfeng commented Aug 4, 2023

@rainzm 很棒,思路没问题,只是有一点,获取第一个翻译结果,可以使用已有的 self.firstService 属性,这个值不一定是数组 allShowingResults 的第一个,因为第一个服务可能未启用查询,内容为空。

问题不大,尽量参考已有的功能代码,多调试就好了。

加油。

@rainzm
Copy link
Contributor Author

rainzm commented Aug 5, 2023

好的~ 所以self.firstService指的是第一个查询成功的翻译服务是嘛?

@tisfeng
Copy link
Owner

tisfeng commented Aug 5, 2023

是的,但要注意,只有当服务查询成功后,里面才会有翻译结果。

@tisfeng tisfeng reopened this Oct 6, 2023
@tisfeng tisfeng added the fixed in next release The issue will be closed once next release is available label Oct 6, 2023
@tisfeng
Copy link
Owner

tisfeng commented Oct 25, 2023

2.0.1 版本已添加。

@tisfeng tisfeng closed this as completed Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed in next release The issue will be closed once next release is available
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants