Skip to content

Commit

Permalink
Fix empty context menu in HTML viewer
Browse files Browse the repository at this point in the history
- don't disply HTML mail viewer context menu if it's empty
- hide unnecessary separators
- resolves #4053
  • Loading branch information
maxphilippov committed Aug 2, 2024
1 parent 1aa842e commit 30ed8c8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 53 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
- fix missing remove button in AddMemberChip #393
- fix composite emoji in text avatar #4038
- fix "Password and Account" dialog not indicating invalid credentials, making it seem that you can change password like this #4032
- fix empty context menu and unneccessary separators in HTML mail view #4053

<a id="1_46_1"></a>

Expand Down
111 changes: 58 additions & 53 deletions src/main/windows/html_email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import electron, {
BrowserWindow,
dialog,
Menu,
MenuItem,
MenuItemConstructorOptions,
nativeTheme,
session,
Expand Down Expand Up @@ -518,61 +519,65 @@ const createContextMenu = (win: BrowserWindow, webContents: WebContents) => {
const { editFlags } = props
const hasText = props.selectionText.trim().length > 0

const defaultActions: {
[key: string]: () => MenuItemConstructorOptions
} = {
separator: () => ({ type: 'separator' }),
copy: () => ({
id: 'copy',
label: tx('global_menu_edit_copy_desktop'),
enabled: editFlags.canCopy && hasText,
visible: props.isEditable || hasText,
click() {
if (webContents) {
webContents.copy()
} else {
electron.clipboard.writeText(props.selectionText)
}
},
}),
paste: () => ({
id: 'paste',
label: tx('global_menu_edit_paste_desktop'),
enabled: editFlags.canPaste,
visible: props.isEditable,
click() {
webContents.paste()
},
}),
copyLink: () => ({
id: 'copyLink',
label: tx('menu_copy_link_to_clipboard'),
visible: props.linkURL.length !== 0 && props.mediaType === 'none',
click() {
electron.clipboard.write({
bookmark: props.linkText,
text: props.linkURL,
})
},
}),
copyImage: () => ({
id: 'copyImage',
label: tx('menu_copy_image_to_clipboard'),
visible: props.mediaType === 'image',
click() {
webContents.copyImageAt(props.x, props.y)
},
}),
const menuItems = []

if (props.isEditable || hasText) {
menuItems.push(
new MenuItem({
id: 'copy',
label: tx('global_menu_edit_copy_desktop'),
enabled: editFlags.canCopy && hasText,
click() {
if (webContents) {
webContents.copy()
} else {
electron.clipboard.writeText(props.selectionText)
}
},
})
)
}

const menu = electron.Menu.buildFromTemplate([
defaultActions.copy(),
defaultActions.separator(),
defaultActions.copyImage(),
defaultActions.separator(),
defaultActions.copyLink(),
])
menu.popup({ window: win })
if (props.mediaType === 'image') {
if (menuItems.length) {
menuItems.push(new MenuItem({ type: 'separator' }))
}

menuItems.push(
new MenuItem({
id: 'copyImage',
label: tx('menu_copy_image_to_clipboard'),
click() {
webContents.copyImageAt(props.x, props.y)
},
})
)
}

if (props.linkURL.length !== 0 && props.mediaType === 'none') {
if (menuItems.length) {
menuItems.push(new MenuItem({ type: 'separator' }))
}

menuItems.push(
new MenuItem({
id: 'copyLink',
label: tx('menu_copy_link_to_clipboard'),
click() {
electron.clipboard.write({
bookmark: props.linkText,
text: props.linkURL,
})
},
})
)
}

if (menuItems.length) {
const menu = electron.Menu.buildFromTemplate(menuItems)

menu.popup({ window: win })
}
}
webContents.on('context-menu', handleContextMenu)
return () => {
Expand Down

0 comments on commit 30ed8c8

Please sign in to comment.