Skip to content

Commit cfb1135

Browse files
committed
feat: add context menu for editable elements, enabling cut, copy, paste, and select all actions
1 parent 864c556 commit cfb1135

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/main.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,38 @@ app.on('web-contents-created', (_event, contents) => {
375375
}
376376
return { action: 'deny' }
377377
})
378+
379+
// Add context menu for editable elements (text inputs, textareas)
380+
contents.on('context-menu', (_e, params) => {
381+
// Only show context menu for editable elements
382+
if (!params.isEditable) return
383+
384+
const hasSelection = params.selectionText.length > 0
385+
386+
const contextMenu = Menu.buildFromTemplate([
387+
{
388+
label: '剪切',
389+
role: 'cut',
390+
enabled: hasSelection,
391+
},
392+
{
393+
label: '复制',
394+
role: 'copy',
395+
enabled: hasSelection,
396+
},
397+
{
398+
label: '粘贴',
399+
role: 'paste',
400+
},
401+
{ type: 'separator' },
402+
{
403+
label: '全选',
404+
role: 'selectAll',
405+
},
406+
])
407+
408+
contextMenu.popup()
409+
})
378410
})
379411

380412
// This method will be called when Electron has finished

0 commit comments

Comments
 (0)