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

feat: support use selection for find on macOS #39629

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/api/menu-item.md
Expand Up @@ -14,7 +14,7 @@ See [`Menu`](menu.md) for examples.
* `menuItem` MenuItem
* `browserWindow` [BrowserWindow](browser-window.md) | undefined - This will not be defined if no window is open.
* `event` [KeyboardEvent](structures/keyboard-event.md)
* `role` string (optional) - Can be `undo`, `redo`, `cut`, `copy`, `paste`, `pasteAndMatchStyle`, `delete`, `selectAll`, `reload`, `forceReload`, `toggleDevTools`, `resetZoom`, `zoomIn`, `zoomOut`, `toggleSpellChecker`, `togglefullscreen`, `window`, `minimize`, `close`, `help`, `about`, `services`, `hide`, `hideOthers`, `unhide`, `quit`, `showSubstitutions`, `toggleSmartQuotes`, `toggleSmartDashes`, `toggleTextReplacement`, `startSpeaking`, `stopSpeaking`, `zoom`, `front`, `appMenu`, `fileMenu`, `editMenu`, `viewMenu`, `shareMenu`, `recentDocuments`, `toggleTabBar`, `selectNextTab`, `selectPreviousTab`, `showAllTabs`, `mergeAllWindows`, `clearRecentDocuments`, `moveTabToNewWindow` or `windowMenu` - Define the action of the menu item, when specified the
* `role` string (optional) - Can be `undo`, `redo`, `cut`, `copy`, `paste`, `pasteAndMatchStyle`, `delete`, `selectAll`, `reload`, `forceReload`, `toggleDevTools`, `resetZoom`, `zoomIn`, `zoomOut`, `toggleSpellChecker`, `togglefullscreen`, `window`, `minimize`, `close`, `help`, `about`, `services`, `hide`, `hideOthers`, `unhide`, `quit`, `showSubstitutions`, `toggleSmartQuotes`, `toggleSmartDashes`, `toggleTextReplacement`, `startSpeaking`, `stopSpeaking`, `zoom`, `front`, `appMenu`, `fileMenu`, `editMenu`, `viewMenu`, `shareMenu`, `recentDocuments`, `toggleTabBar`, `selectNextTab`, `selectPreviousTab`, `showAllTabs`, `mergeAllWindows`, `clearRecentDocuments`, `moveTabToNewWindow`, `useSelectionForFind` or `windowMenu` - Define the action of the menu item, when specified the
`click` property will be ignored. See [roles](#roles).
* `type` string (optional) - Can be `normal`, `separator`, `submenu`, `checkbox` or
`radio`.
Expand Down Expand Up @@ -120,6 +120,7 @@ The following additional roles are available on _macOS_:
* `recentDocuments` - The submenu is an "Open Recent" menu.
* `clearRecentDocuments` - Map to the `clearRecentDocuments` action.
* `shareMenu` - The submenu is [share menu][ShareMenu]. The `sharingItem` property must also be set to indicate the item to share.
* `useSelectionForFind` - Map to the `copyToFindPboard` action.

When specifying a `role` on macOS, `label` and `accelerator` are the only
options that will affect the menu item. All other options will be ignored.
Expand Down Expand Up @@ -160,7 +161,7 @@ A `string` indicating the type of the item. Can be `normal`, `separator`, `subme

#### `menuItem.role`

A `string` (optional) indicating the item's role, if set. Can be `undo`, `redo`, `cut`, `copy`, `paste`, `pasteAndMatchStyle`, `delete`, `selectAll`, `reload`, `forceReload`, `toggleDevTools`, `resetZoom`, `zoomIn`, `zoomOut`, `toggleSpellChecker`, `togglefullscreen`, `window`, `minimize`, `close`, `help`, `about`, `services`, `hide`, `hideOthers`, `unhide`, `quit`, `startSpeaking`, `stopSpeaking`, `zoom`, `front`, `appMenu`, `fileMenu`, `editMenu`, `viewMenu`, `shareMenu`, `recentDocuments`, `toggleTabBar`, `selectNextTab`, `selectPreviousTab`, `showAllTabs`, `mergeAllWindows`, `clearRecentDocuments`, `moveTabToNewWindow` or `windowMenu`
A `string` (optional) indicating the item's role, if set. Can be `undo`, `redo`, `cut`, `copy`, `paste`, `pasteAndMatchStyle`, `delete`, `selectAll`, `reload`, `forceReload`, `toggleDevTools`, `resetZoom`, `zoomIn`, `zoomOut`, `toggleSpellChecker`, `togglefullscreen`, `window`, `minimize`, `close`, `help`, `about`, `services`, `hide`, `hideOthers`, `unhide`, `quit`, `startSpeaking`, `stopSpeaking`, `zoom`, `front`, `appMenu`, `fileMenu`, `editMenu`, `viewMenu`, `shareMenu`, `recentDocuments`, `toggleTabBar`, `selectNextTab`, `selectPreviousTab`, `showAllTabs`, `mergeAllWindows`, `clearRecentDocuments`, `moveTabToNewWindow`, `useSelectionForFind` or `windowMenu`

#### `menuItem.accelerator`

Expand Down
9 changes: 7 additions & 2 deletions lib/browser/api/menu-item-roles.ts
Expand Up @@ -8,7 +8,7 @@ type RoleId = 'about' | 'close' | 'copy' | 'cut' | 'delete' | 'forcereload' | 'f
'paste' | 'pasteandmatchstyle' | 'quit' | 'redo' | 'reload' | 'resetzoom' | 'selectall' | 'services' | 'recentdocuments' | 'clearrecentdocuments' |
'showsubstitutions' | 'togglesmartquotes' | 'togglesmartdashes' | 'toggletextreplacement' | 'startspeaking' | 'stopspeaking' |
'toggledevtools' | 'togglefullscreen' | 'undo' | 'unhide' | 'window' | 'zoom' | 'zoomin' | 'zoomout' | 'togglespellchecker' |
'appmenu' | 'filemenu' | 'editmenu' | 'viewmenu' | 'windowmenu' | 'sharemenu'
'appmenu' | 'filemenu' | 'editmenu' | 'viewmenu' | 'windowmenu' | 'sharemenu' | 'useselectionforfind'
interface Role {
label: string;
accelerator?: string;
Expand Down Expand Up @@ -211,6 +211,10 @@ export const roleList: Record<RoleId, Role> = {
ses.spellCheckerEnabled = !ses.spellCheckerEnabled;
}
},
useselectionforfind: {
label: 'Use Selection for Find',
accelerator: 'Command+E'
},
// App submenu should be used for Mac only
appmenu: {
get label () {
Expand Down Expand Up @@ -266,7 +270,8 @@ export const roleList: Record<RoleId, Role> = {
{ role: 'startSpeaking' },
{ role: 'stopSpeaking' }
]
}
},
{ role: 'useSelectionForFind' }
] as MenuItemConstructorOptions[] : [
{ role: 'delete' },
{ type: 'separator' },
Expand Down
1 change: 1 addition & 0 deletions shell/browser/ui/cocoa/electron_menu_controller.mm
Expand Up @@ -70,6 +70,7 @@
{@selector(mergeAllWindows:), "mergeallwindows"},
{@selector(moveTabToNewWindow:), "movetabtonewwindow"},
{@selector(clearRecentDocuments:), "clearrecentdocuments"},
{@selector(copyToFindPboard:), "useselectionforfind"},
};

// Called when adding a submenu to the menu and checks if the submenu, via its
Expand Down
1 change: 1 addition & 0 deletions spec/api-menu-item-spec.ts
Expand Up @@ -359,6 +359,7 @@ describe('MenuItems', () => {
expect(item.submenu!.items[11].label).to.equal('Speech');
expect(item.submenu!.items[11].submenu!.items[0].role).to.equal('startspeaking');
expect(item.submenu!.items[11].submenu!.items[1].role).to.equal('stopspeaking');
expect(item.submenu!.items[12].role).to.equal('useselectionforfind');
} else {
expect(item.submenu!.items[6].role).to.equal('delete');
expect(item.submenu!.items[7].type).to.equal('separator');
Expand Down
3 changes: 2 additions & 1 deletion spec/ts-smoke/electron/main.ts
Expand Up @@ -834,7 +834,8 @@ Menu.buildFromTemplate([
{ role: 'showAllTabs' },
{ role: 'mergeAllWindows' },
{ role: 'clearRecentDocuments' },
{ role: 'moveTabToNewWindow' }
{ role: 'moveTabToNewWindow' },
{ role: 'useSelectionForFind' }
]);

// net
Expand Down