Skip to content

Commit

Permalink
Add 'Select All' menu item (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
hns258 committed Aug 8, 2022
1 parent 066b11f commit 01c7c09
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fixtures/fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ contextMenu({
copy: 'Configured Copy',
paste: 'Configured Paste',
save: 'Configured Save Image',
selectAll: 'Configured Select All',
saveImageAs: 'Configured Save Image As…',
copyLink: 'Configured Copy Link',
saveLinkAs: 'Configured Save Link As…',
Expand Down Expand Up @@ -39,7 +40,8 @@ contextMenu({
showCopyImageAddress: true,
showSaveImageAs: true,
showInspectElement: false,
showSaveLinkAs: true
showSaveLinkAs: true,
showSelectAll: true
});

(async () => {
Expand Down
13 changes: 13 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ declare namespace contextMenu {
*/
readonly paste?: string;

/**
@default 'Select All'
*/
readonly selectAll?: string;

/**
@default 'Save Image'
*/
Expand Down Expand Up @@ -98,6 +103,7 @@ declare namespace contextMenu {
readonly cut: (options: ActionOptions) => MenuItemConstructorOptions;
readonly copy: (options: ActionOptions) => MenuItemConstructorOptions;
readonly paste: (options: ActionOptions) => MenuItemConstructorOptions;
readonly selectAll: (options: ActionOptions) => MenuItemConstructorOptions;
readonly saveImage: (options: ActionOptions) => MenuItemConstructorOptions;
readonly saveImageAs: (options: ActionOptions) => MenuItemConstructorOptions;
readonly copyLink: (options: ActionOptions) => MenuItemConstructorOptions;
Expand Down Expand Up @@ -210,6 +216,13 @@ declare namespace contextMenu {
*/
readonly showServices?: boolean;

/**
Force display/hide the `Select All` menu-item when right-clicking in a window
@default false for macOS and true for all other OSes
*/
readonly showSelectAll?: boolean;

/**
Override labels for the default menu items. Useful for i18n.
Expand Down
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ const create = (win, options) => {
}
}
}),
selectAll: decorateMenuItem({
id: 'selectAll',
label: 'Select &All',
click() {
webContents(win).selectAll();
}
}),
saveImage: decorateMenuItem({
id: 'saveImage',
label: 'Save I&mage',
Expand Down Expand Up @@ -200,6 +207,7 @@ const create = (win, options) => {
};

const shouldShowInspectElement = typeof options.showInspectElement === 'boolean' ? options.showInspectElement : isDev;
const shouldShowSelectAll = options.showSelectAll || (options.showSelectAll !== false && process.platform !== 'darwin');

function word(suggestion) {
return {
Expand Down Expand Up @@ -240,6 +248,7 @@ const create = (win, options) => {
defaultActions.cut(),
defaultActions.copy(),
defaultActions.paste(),
shouldShowSelectAll && defaultActions.selectAll(),
defaultActions.separator(),
options.showSaveImage && defaultActions.saveImage(),
options.showSaveImageAs && defaultActions.saveImageAs(),
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ Show the system `Services` submenu when right-clicking text on macOS.

Note: Due to [a bug in the Electron implementation](https://github.com/electron/electron/issues/18476), this menu is not identical to the "Services" submenu in the context menus of native apps. Instead, it looks the same as the "Services" menu in the main App Menu. For this reason, it is currently disabled by default.

#### showSelectAll

Type: `boolean`\
Default: `false` for macOS and `true` for all other OSes

Force display/hide the `Select All` menu-item when right-clicking in a window.

#### labels

Type: `object`\
Expand Down Expand Up @@ -256,6 +263,7 @@ The following options are ignored when `menu` is used:
- `showInspectElement`
- `showServices`
- `showSearchWithGoogle`
- `showSelectAll`

Default actions:

Expand All @@ -267,6 +275,7 @@ Default actions:
- `cut`
- `copy`
- `paste`
- `selectAll`
- `saveImage`
- `saveImageAs`
- `copyImage`
Expand Down

0 comments on commit 01c7c09

Please sign in to comment.