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

Improve lookUpSelection implementation #76

Merged
merged 7 commits into from Jun 30, 2019
Merged

Improve lookUpSelection implementation #76

merged 7 commits into from Jun 30, 2019

Conversation

caesar
Copy link
Contributor

@caesar caesar commented May 31, 2019

Further to #71, and per discussion there and in #73 (comment):

  • Change the order of menu actions in code to match the default menu order.
    Note, as well as lookUpSelection I have moved inspect, which was also in the wrong place in the order.

  • Add lookUpSelection to Labels interface in index.d.ts, with note on usage (specifically, that if a static label is set, it will no longer be dynamic).
    Also add a similar but more detailed note to readme.md.

  • [update] Implement {selection} placeholder for menu titles to enable full localisation of the Look Up “{selection}” item.

This commit will probably conflict with #73; if so, I will fix that one once this is committed.

index.d.ts Outdated Show resolved Hide resolved
@caesar caesar changed the title Reorder menu actions in code, and add lookUpSelection to Labels interface with note on usage Improve lookUpWord implementation May 31, 2019
@caesar caesar changed the title Improve lookUpWord implementation Improve lookUpSelection implementation May 31, 2019
readme.md Show resolved Hide resolved
@sindresorhus
Copy link
Owner

I've made it so the {selection} placeholder can be used in any menu title, as it could easily be useful in other places. (Besides, the code's cleaner without any special-casing.)

What other places? I don't really like making things flexible if it has no purpose.

index.js Outdated Show resolved Hide resolved
@caesar
Copy link
Contributor Author

caesar commented Jun 3, 2019

What other places?

Well, for example, to implement a "Search Google for {selection}" menu item, or if someone wanted to say change the "Copy" menu item to "Copy {selection}".

I don't really like making things flexible if it has no purpose.

In principle, I agree. However, in this case, the "generic" implementation is simpler and more maintainable than a "special-case" implementation would be, in my opinion.

A special-case implementation would still have to be implemented at the same point in the code (after applying custom titles), so while looping through the menu items it would have to check each one to see if it had the appropriate id before applying the replacement. I don't see the point.

* master:
  Add Services submenu on macOS (#73)

# Conflicts:
#	index.d.ts
#	index.js
@sindresorhus
Copy link
Owner

Well, for example, to implement a "Search Google for {selection}" menu item, or if someone wanted to say change the "Copy" menu item to "Copy {selection}".

Good point. You should include that in the docs to make it clearer what the user could use it for.

readme.md Outdated
Overwrite labels for the default menu items. Useful for i18n.
Override labels for the default menu items. Useful for i18n.

The placehlder `{selection}` may be used in any label, and will be replaced by the currently selected text.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be more comprehensive. It needs to mention what the user has to check for and how to guard against selection not being available (like we do in the built-in menu. Maybe show an example of a custom menu using {selection}?

Suggested change
The placehlder `{selection}` may be used in any label, and will be replaced by the currently selected text.
The placeholder `{selection}` may be used in any label, and will be replaced by the currently selected text.

@sindresorhus
Copy link
Owner

@caesar Would you be able to finish this so we can get out a new release? :)

@caesar
Copy link
Contributor Author

caesar commented Jun 23, 2019

Hey Sindre, sorry for not getting back onto this, I've been really busy.

I'm going to be offline for a couple of days, but I'll see if I can take a look at this right now to get it finished before I leave so you can merge.

I think we're only talking about documentation improvements now, right?

@sindresorhus
Copy link
Owner

Correct

@caesar
Copy link
Contributor Author

caesar commented Jun 23, 2019

I think that's quite comprehensive, what do you think?

@sindresorhus sindresorhus merged commit 12d60d9 into sindresorhus:master Jun 30, 2019
@sindresorhus
Copy link
Owner

Looks great 👌

@caesar
Copy link
Contributor Author

caesar commented Jun 30, 2019

Thanks Sindre 👍

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.

None yet

2 participants