Skip to content

Support for Look Up "<word>" popup menu #1191

Closed

Description

A clear and concise description of what is hard to do
In Apple's builtin applications and in the non-MacVim third party applications I use, force-clicking on a word shows a popup menu with information about the word (a dictionary definition and so on). One can also view this popup menu by right-clicking on the word and selecting Look Up "word". See the image below. I use this when writing to quickly look up words in the dictionary without having to open another window or application.

Describe the solution you'd like
Implement a way to bind the opening of this popup window to a key (or keys) or mouse action. This way we can customise how to open this menu and we can add this to the MacVim gui popup via the builtin :menu command. It would likely be a good idea to set the default settings to emulate MacOS behaviour.

Describe alternatives you've considered
I have looked into opening this window with apple script, but I could not find a way. One alternative is to write a function that takes the word under the cursor and executes :!open dict://word. This will show the word in the builtin Dictionary.app. This opens up another application, however, and shows a lot more information than just a simple definition. The Look Up window allows you to open the word in Dictionary.app anyway.

Screenshot 2021-04-21 at 13 57 03

Activity

  1. added this to the Backlog milestone on Apr 22, 2021
  2. ychin commented on Apr 22, 2021

    @ychin
    Member

    Thanks for filing this. It's been on my to-do after we refactored to the new renderer. There are really a couple things we should do on this:

    1. Support native lookup (Force Touch, three-finger tap, or Cmd-Ctrl-D). This requires hooking up to Apple's text input client API so macOS knows what the text under the cursors are, but the API is not terribly well documented so I kind of punted on that work. After we do that you will be able to just use the regular Cmd-Ctrl-D to look up the text under the cursor.
      • Also, currently force touch is hijacked by MacVim to allow for mapping it using <ForceClick>. Probably need to do something there to allow the user to choose what to do.
      • I believe this will also allows us to hook up the macOS built-in spellchecker for Touch Bar.
    2. Support lookup as a Vim function, so you can do :call mvim_lookup("http://www.google.com") or something like that (macOS's lookups support web URLs as well as dictionary). This is easier to do but I want to figure out how to do (1) first.
  3. eirnym commented on Apr 22, 2021

    @eirnym
    Contributor

    I also prefer to have a switch in vimrc to turn this off

  4. ychin commented on Apr 23, 2021

    @ychin
    Member

    @eirnym can you explain why you would like a switch to turn this off? Lookup requires active user action to activate. It's not a passive feature, and most editors / GUI applications support it and there are system-wide settings that allow you to configure how to activate it in the OS.

  5. eirnym commented on Apr 23, 2021

    @eirnym
    Contributor

    This is the least used by me macOS feature. Problem there's no good dictionaries for Polish and many other languages and no way to install your own from open source dictionaries

  6. ychin commented on Apr 23, 2021

    @ychin
    Member

    Right but that’s not what I’m asking about. My point is if you don’t actively use this feature you can just not use it. No reason to include a preference to turn it off. It’s not like the program will randomly pop up the dictionary for you.

    Also, lookup supports other things like Wikipedia and URL previews. It’s not just for dictionary.

  7. eirnym commented on Apr 24, 2021

    @eirnym
    Contributor

    With macOS apps I can turn this feature off in preferences (and I do). Why this feature must be turned on in MacVim while it's turned off in macOS?

  8. modified the milestones: Backlog, Release 175 on Sep 30, 2022
  9. added 2 commits that reference this issue on Oct 11, 2022
    d6fc1d1
    c8ccd4e
  10. ychin commented on Oct 11, 2022

    @ychin
    Member

    #1312 will add support for this! This turned out to be a much larger task than I imagined because the degree to which you want to support this really depends on how much time you want to spend on it (e.g. supporting lookups for selected texts, data detection for URLs), and I feel like there are a lot of more ways to extend this such as custom API support. I made an epic #1311 to track the work for this so it's easier to see them in one place as they are related to each other. Annoyingly Apple uses private APIs for their implementation for native text views and WebKit/Safari, which is why third-party apps' implementation can never work as well as the native ones (e.g. Firefox or Chrome). For example, if you have a flight number (e.g. "AS 123") or package number Safari or TextEdit can natively understand how to show them, but other apps won't (unless they specifically implemented something for that). Just one of those builtin limitations.

    After the initial PR though you should already be able to use Ctrl-Cmd-D or trackpad to show definition under work.

    With macOS apps I can turn this feature off in preferences (and I do). Why this feature must be turned on in MacVim while it's turned off in macOS?

    There isn't a way to turn this feature off completely. You can tell the OS to not do this with the trackpad which MacVim will respect of course, but you cannot disable Ctrl-Cmd-D as far as I can tell. I don't really think it will be a big deal in practice. You have to intentionally trigger this for it to show up.

  11. added 2 commits that reference this issue on Oct 11, 2022
    2928f77
    83e925e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions