所有文本框支持右键剪切、复制、粘贴。

This commit is contained in:
unknown 2024-09-22 22:13:15 +08:00
parent 78cf39bec7
commit a2ccd8670b
5 changed files with 57 additions and 1 deletions

View File

@ -77,10 +77,12 @@ let simplifiedChinese = {
controlPanel: "控制面板",
convertAbsolutePath: "转为绝对路径",
convertRelativePath: "转为相对路径",
copy: "复制",
copyFullPath: "复制完整路径",
copyTo: "复制到",
createShortcut: "创建快捷方式",
ctrlNumberKey: "Ctrl + 数字键",
cut: "剪切",
default: "默认",
defaultIcon: "默认图标",
delayDisplay: "延迟显示",
@ -206,6 +208,7 @@ let simplifiedChinese = {
parameters: "参数",
password: "密码",
pasteIcon: "粘贴图标",
paste: "粘贴",
path: "路径",
powerOptions: "电源选项",
powerShell: "PowerShell",
@ -384,10 +387,12 @@ let traditionalChinese = {
controlPanel: "控製面板",
convertAbsolutePath: "轉為絕對路徑",
convertRelativePath: "轉為相對路徑",
copy: "復製",
copyFullPath: "復製完整路徑",
copyTo: "復製到",
createShortcut: "創建快捷方式",
ctrlNumberKey: "Ctrl + 數字鍵",
cut: "剪切",
default: "默認",
defaultIcon: "默認圖標",
delayDisplay: "延遲顯示",
@ -513,6 +518,7 @@ let traditionalChinese = {
parameters: "參數",
password: "密碼",
pasteIcon: "粘貼圖標",
paste: "粘貼",
path: "路徑",
powerOptions: "電源選項",
powerShell: "PowerShell",
@ -699,10 +705,12 @@ let english = {
controlPanel: "Control Panel",
convertAbsolutePath: "Convert to Absolute Path",
convertRelativePath: "Convert to Relative Path",
copy: "Copy",
copyFullPath: "Copy Full Path",
copyTo: "Copy to",
createShortcut: "Create Shortcut",
ctrlNumberKey: "Ctrl + Number Key",
cut: "Cut",
default: "Default",
defaultIcon: "Default Icon",
delayDisplay: "Delay Display",
@ -830,6 +838,7 @@ let english = {
parameters: "Parameters",
password: "Password",
pasteIcon: "Paste Icon",
paste: "Paste",
path: "Path",
powerOptions: "Power Options",
powerShell: "PowerShell",

View File

@ -1,4 +1,4 @@
import { app, ipcMain, OpenDialogSyncOptions, shell } from "electron";
import { app, ipcMain, Menu, OpenDialogSyncOptions, shell } from "electron";
import { getFileIcon } from "../../commons/utils";
import mime from "mime";
import { ShortcutInfo } from "../../../types/common";
@ -164,4 +164,24 @@ export default function () {
app.getPath("home")
);
});
// 文本框菜单
ipcMain.on("textRightMenu", (event, args) => {
// 菜单
let menu = Menu.buildFromTemplate([
{
role: "cut",
label: global.language.cut,
},
{
role: "copy",
label: global.language.copy,
},
{
role: "paste",
label: global.language.paste,
},
]);
// 显示
menu.popup();
});
}

View File

@ -114,6 +114,10 @@ contextBridge.exposeInMainWorld("api", {
) => {
ipcRenderer.send("run", { operation, target, params, startLocation });
},
// 文本框菜单
textRightMenu: () => {
ipcRenderer.send("textRightMenu");
},
});
contextBridge.exposeInMainWorld("main", {

View File

@ -305,6 +305,24 @@ function keydown(e: any) {
}
}
}
//
function contextmenu(e: MouseEvent) {
let target = e.target as HTMLInputElement;
if (target) {
if (
(target.nodeName != null &&
target.nodeName.toLowerCase() == "input" &&
target.type != null &&
target.type.toLowerCase() == "text") ||
(target.nodeName != null && target.nodeName.toLowerCase() == "textarea")
) {
window.api.textRightMenu();
e.preventDefault();
e.stopPropagation();
return;
}
}
}
//
let onUpdateSettingUnListen: Function | null = null;
// mounted
@ -313,6 +331,8 @@ onMounted(() => {
createStyle();
//
window.addEventListener("keydown", keydown, true);
//
window.addEventListener("contextmenu", contextmenu, true);
//
onUpdateSettingUnListen = window.setting.onUpdate((data) => {
store.setting = data;
@ -322,6 +342,8 @@ onMounted(() => {
onUnmounted(() => {
//
window.removeEventListener("keydown", keydown, true);
//
window.removeEventListener("contextmenu", contextmenu, true);
//
if (onUpdateSettingUnListen) {
onUpdateSettingUnListen();

1
src/index.d.ts vendored
View File

@ -37,6 +37,7 @@ declare global {
params: string | null,
startLocation: string | null
) => void;
textRightMenu: () => void;
};
main: {
showWindow: (blurHide: boolean, autoHide: boolean) => void;