2023-06-26 01:29:50 -08:00
|
|
|
import type {BrowserWindow, MenuItemConstructorOptions} from 'electron';
|
2019-12-20 08:55:03 -09:00
|
|
|
|
2023-07-25 08:11:02 -08:00
|
|
|
const editMenu = (
|
2019-12-20 08:55:03 -09:00
|
|
|
commandKeys: Record<string, string>,
|
|
|
|
|
execCommand: (command: string, focusedWindow?: BrowserWindow) => void
|
|
|
|
|
) => {
|
|
|
|
|
const submenu: MenuItemConstructorOptions[] = [
|
2017-05-25 22:59:02 -08:00
|
|
|
{
|
2017-11-08 12:24:56 -09:00
|
|
|
label: 'Undo',
|
|
|
|
|
accelerator: commandKeys['editor:undo'],
|
|
|
|
|
enabled: false
|
2017-05-25 22:59:02 -08:00
|
|
|
},
|
|
|
|
|
{
|
2017-11-08 12:24:56 -09:00
|
|
|
label: 'Redo',
|
|
|
|
|
accelerator: commandKeys['editor:redo'],
|
|
|
|
|
enabled: false
|
2017-05-25 22:59:02 -08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'separator'
|
|
|
|
|
},
|
|
|
|
|
{
|
2017-11-08 12:24:56 -09:00
|
|
|
label: 'Cut',
|
|
|
|
|
accelerator: commandKeys['editor:cut'],
|
|
|
|
|
enabled: false
|
2017-05-25 22:59:02 -08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
role: 'copy',
|
2017-11-02 18:51:18 -08:00
|
|
|
command: 'editor:copy',
|
2019-02-04 17:28:20 -09:00
|
|
|
accelerator: commandKeys['editor:copy'],
|
|
|
|
|
registerAccelerator: true
|
2019-12-20 08:55:03 -09:00
|
|
|
} as any,
|
2017-05-25 22:59:02 -08:00
|
|
|
{
|
|
|
|
|
role: 'paste',
|
2022-09-09 22:40:18 -08:00
|
|
|
accelerator: commandKeys['editor:paste'],
|
|
|
|
|
registerAccelerator: true
|
2017-05-25 22:59:02 -08:00
|
|
|
},
|
|
|
|
|
{
|
2018-01-21 02:21:16 -09:00
|
|
|
label: 'Select All',
|
|
|
|
|
accelerator: commandKeys['editor:selectAll'],
|
|
|
|
|
click(item, focusedWindow) {
|
2025-04-21 20:45:07 -08:00
|
|
|
execCommand('editor:selectAll', focusedWindow as BrowserWindow | undefined);
|
2018-01-21 02:21:16 -09:00
|
|
|
}
|
2017-05-25 22:59:02 -08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'separator'
|
|
|
|
|
},
|
2017-11-06 11:27:25 -09:00
|
|
|
{
|
|
|
|
|
label: 'Move to...',
|
|
|
|
|
submenu: [
|
|
|
|
|
{
|
|
|
|
|
label: 'Previous word',
|
|
|
|
|
accelerator: commandKeys['editor:movePreviousWord'],
|
|
|
|
|
click(item, focusedWindow) {
|
2025-04-21 20:45:07 -08:00
|
|
|
execCommand('editor:movePreviousWord', focusedWindow as BrowserWindow | undefined);
|
2017-11-06 11:27:25 -09:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Next word',
|
|
|
|
|
accelerator: commandKeys['editor:moveNextWord'],
|
|
|
|
|
click(item, focusedWindow) {
|
2025-04-21 20:45:07 -08:00
|
|
|
execCommand('editor:moveNextWord', focusedWindow as BrowserWindow | undefined);
|
2017-11-06 11:27:25 -09:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Line beginning',
|
|
|
|
|
accelerator: commandKeys['editor:moveBeginningLine'],
|
|
|
|
|
click(item, focusedWindow) {
|
2025-04-21 20:45:07 -08:00
|
|
|
execCommand('editor:moveBeginningLine', focusedWindow as BrowserWindow | undefined);
|
2017-11-06 11:27:25 -09:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Line end',
|
|
|
|
|
accelerator: commandKeys['editor:moveEndLine'],
|
|
|
|
|
click(item, focusedWindow) {
|
2025-04-21 20:45:07 -08:00
|
|
|
execCommand('editor:moveEndLine', focusedWindow as BrowserWindow | undefined);
|
2017-11-06 11:27:25 -09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Delete...',
|
|
|
|
|
submenu: [
|
|
|
|
|
{
|
|
|
|
|
label: 'Previous word',
|
|
|
|
|
accelerator: commandKeys['editor:deletePreviousWord'],
|
|
|
|
|
click(item, focusedWindow) {
|
2025-04-21 20:45:07 -08:00
|
|
|
execCommand('editor:deletePreviousWord', focusedWindow as BrowserWindow | undefined);
|
2017-11-06 11:27:25 -09:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Next word',
|
|
|
|
|
accelerator: commandKeys['editor:deleteNextWord'],
|
|
|
|
|
click(item, focusedWindow) {
|
2025-04-21 20:45:07 -08:00
|
|
|
execCommand('editor:deleteNextWord', focusedWindow as BrowserWindow | undefined);
|
2017-11-06 11:27:25 -09:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Line beginning',
|
|
|
|
|
accelerator: commandKeys['editor:deleteBeginningLine'],
|
|
|
|
|
click(item, focusedWindow) {
|
2025-04-21 20:45:07 -08:00
|
|
|
execCommand('editor:deleteBeginningLine', focusedWindow as BrowserWindow | undefined);
|
2017-11-06 11:27:25 -09:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Line end',
|
|
|
|
|
accelerator: commandKeys['editor:deleteEndLine'],
|
|
|
|
|
click(item, focusedWindow) {
|
2025-04-21 20:45:07 -08:00
|
|
|
execCommand('editor:deleteEndLine', focusedWindow as BrowserWindow | undefined);
|
2017-11-06 11:27:25 -09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'separator'
|
|
|
|
|
},
|
2017-05-25 22:59:02 -08:00
|
|
|
{
|
|
|
|
|
label: 'Clear Buffer',
|
2017-11-02 18:51:18 -08:00
|
|
|
accelerator: commandKeys['editor:clearBuffer'],
|
2017-05-25 22:59:02 -08:00
|
|
|
click(item, focusedWindow) {
|
2025-04-21 20:45:07 -08:00
|
|
|
execCommand('editor:clearBuffer', focusedWindow as BrowserWindow | undefined);
|
2017-05-25 22:59:02 -08:00
|
|
|
}
|
2019-09-23 09:37:22 -08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Search',
|
|
|
|
|
accelerator: commandKeys['editor:search'],
|
|
|
|
|
click(item, focusedWindow) {
|
2025-04-21 20:45:07 -08:00
|
|
|
execCommand('editor:search', focusedWindow as BrowserWindow | undefined);
|
2019-09-23 09:37:22 -08:00
|
|
|
}
|
2017-05-25 22:59:02 -08:00
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
|
submenu.push(
|
|
|
|
|
{type: 'separator'},
|
|
|
|
|
{
|
|
|
|
|
label: 'Preferences...',
|
2017-11-03 13:06:48 -08:00
|
|
|
accelerator: commandKeys['window:preferences'],
|
|
|
|
|
click() {
|
|
|
|
|
execCommand('window:preferences');
|
|
|
|
|
}
|
2017-05-25 22:59:02 -08:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
label: 'Edit',
|
|
|
|
|
submenu
|
|
|
|
|
};
|
|
|
|
|
};
|
2023-07-25 08:11:02 -08:00
|
|
|
|
|
|
|
|
export default editMenu;
|