Skip to content

Commit c59c603

Browse files
CodFrmcyfung1031
andauthored
✨ 编辑器添加编辑菜单(查找、替换、撤销等) (#1303)
* ✨ 编辑器工具菜单添加查找和替换入口 * ✨ 编辑器添加编辑菜单(撤销/重做/剪切/复制/粘贴/查找/替换/全选) * `"divider" in menuItem` -> `divider?: never;` * `divider_${i}` * 去掉 `.toString()` --------- Co-authored-by: cyfung1031 <44498510+cyfung1031@users.noreply.github.com>
1 parent d4ab8ba commit c59c603

9 files changed

Lines changed: 152 additions & 12 deletions

File tree

src/locales/ach-UG/translation.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"subscribe": "crwdns7918:0crwdne7918:0",
2121
"logs": "crwdns7920:0crwdne7920:0",
2222
"tools": "crwdns7922:0crwdne7922:0",
23+
"find": "Find",
24+
"replace": "Replace",
2325
"settings": "crwdns7924:0crwdne7924:0",
2426
"hide_main_sidebar": "Collapse sidebar",
2527
"show_main_sidebar": "Expand sidebar",
@@ -219,6 +221,11 @@
219221
"run_once": "crwdns8308:0crwdne8308:0",
220222
"stop": "crwdns8310:0crwdne8310:0",
221223
"edit": "crwdns8312:0crwdne8312:0",
224+
"undo": "Undo",
225+
"redo": "Redo",
226+
"cut": "Cut",
227+
"copy": "Copy",
228+
"paste": "Paste",
222229
"exclude_on": "crwdns8922:0crwdne8922:0",
223230
"exclude_off": "crwdns8924:0crwdne8924:0",
224231
"user_config": "crwdns8320:0crwdne8320:0",

src/locales/de-DE/translation.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"subscribe": "Abonnieren",
2121
"logs": "Protokolle",
2222
"tools": "Werkzeuge",
23+
"find": "Suchen",
24+
"replace": "Ersetzen",
2325
"settings": "Einstellungen",
2426
"hide_main_sidebar": "Seitenleiste einklappen",
2527
"show_main_sidebar": "Seitenleiste ausklappen",
@@ -220,6 +222,11 @@
220222
"run_once": "Einmal ausführen",
221223
"stop": "Stoppen",
222224
"edit": "Bearbeiten",
225+
"undo": "Rückgängig",
226+
"redo": "Wiederherstellen",
227+
"cut": "Ausschneiden",
228+
"copy": "Kopieren",
229+
"paste": "Einfügen",
223230
"exclude_on": "Wiederherstellen auf $0 zur Ausführung",
224231
"exclude_off": "Ausschließen auf $0 zur Ausführung",
225232
"user_config": "Benutzerkonfiguration",

src/locales/en-US/translation.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"subscribe": "Subscribe",
2121
"logs": "Logs",
2222
"tools": "Tools",
23+
"find": "Find",
24+
"replace": "Replace",
2325
"settings": "Settings",
2426
"hide_main_sidebar": "Collapse sidebar",
2527
"show_main_sidebar": "Expand sidebar",
@@ -220,6 +222,11 @@
220222
"run_once": "Run Once",
221223
"stop": "Stop",
222224
"edit": "Edit",
225+
"undo": "Undo",
226+
"redo": "Redo",
227+
"cut": "Cut",
228+
"copy": "Copy",
229+
"paste": "Paste",
223230
"exclude_on": "Reinstate $0's execution",
224231
"exclude_off": "Exclude $0's exeuction",
225232
"user_config": "User Config",

src/locales/ja-JP/translation.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"subscribe": "サブスクライブ",
2121
"logs": "ログ",
2222
"tools": "ツール",
23+
"find": "検索",
24+
"replace": "置換",
2325
"settings": "設定",
2426
"hide_main_sidebar": "サイドバーを折りたたむ",
2527
"show_main_sidebar": "サイドバーを展開",
@@ -220,6 +222,11 @@
220222
"run_once": "一度実行",
221223
"stop": "中止",
222224
"edit": "編集",
225+
"undo": "元に戻す",
226+
"redo": "やり直し",
227+
"cut": "切り取り",
228+
"copy": "コピー",
229+
"paste": "貼り付け",
223230
"exclude_on": "$0の実行を復元",
224231
"exclude_off": "$0の実行を除外",
225232
"user_config": "ユーザー設定",

src/locales/ru-RU/translation.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"subscribe": "Подписаться",
2121
"logs": "Журналы",
2222
"tools": "Инструменты",
23+
"find": "Найти",
24+
"replace": "Заменить",
2325
"settings": "Настройки",
2426
"hide_main_sidebar": "Свернуть боковую панель",
2527
"show_main_sidebar": "Развернуть боковую панель",
@@ -220,6 +222,11 @@
220222
"run_once": "Запустить один раз",
221223
"stop": "Остановить",
222224
"edit": "Редактировать",
225+
"undo": "Отменить",
226+
"redo": "Повторить",
227+
"cut": "Вырезать",
228+
"copy": "Копировать",
229+
"paste": "Вставить",
223230
"exclude_on": "Восстановить в $0 выполнении",
224231
"exclude_off": "Исключить в $0 выполнении",
225232
"user_config": "Конфигурация пользователя",

src/locales/vi-VN/translation.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"subscribe": "Đăng ký",
2121
"logs": "Nhật ký",
2222
"tools": "Công cụ",
23+
"find": "Tìm kiếm",
24+
"replace": "Thay thế",
2325
"settings": "Cài đặt",
2426
"hide_main_sidebar": "Thu gọn thanh bên",
2527
"show_main_sidebar": "Mở rộng thanh bên",
@@ -220,6 +222,11 @@
220222
"run_once": "Chạy một lần",
221223
"stop": "Dừng",
222224
"edit": "Sửa",
225+
"undo": "Hoàn tác",
226+
"redo": "Làm lại",
227+
"cut": "Cắt",
228+
"copy": "Sao chép",
229+
"paste": "Dán",
223230
"exclude_on": "Cho phép chạy lại $0",
224231
"exclude_off": "Loại trừ chạy $0",
225232
"user_config": "Cấu hình người dùng",

src/locales/zh-CN/translation.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"subscribe": "订阅",
2121
"logs": "日志",
2222
"tools": "工具",
23+
"find": "查找",
24+
"replace": "替换",
2325
"settings": "设置",
2426
"hide_main_sidebar": "收起侧边栏",
2527
"show_main_sidebar": "展开侧边栏",
@@ -220,6 +222,11 @@
220222
"run_once": "运行一次",
221223
"stop": "停止",
222224
"edit": "编辑",
225+
"undo": "撤销",
226+
"redo": "重做",
227+
"cut": "剪切",
228+
"copy": "复制",
229+
"paste": "粘贴",
223230
"exclude_on": "恢复在 $0 上执行",
224231
"exclude_off": "排除在 $0 上执行",
225232
"user_config": "用户配置",

src/locales/zh-TW/translation.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"subscribe": "訂閱",
2121
"logs": "紀錄",
2222
"tools": "工具",
23+
"find": "尋找",
24+
"replace": "取代",
2325
"settings": "設定",
2426
"hide_main_sidebar": "摺疊側邊欄",
2527
"show_main_sidebar": "展開側邊欄",
@@ -220,6 +222,11 @@
220222
"run_once": "執行一次",
221223
"stop": "停止",
222224
"edit": "編輯",
225+
"undo": "復原",
226+
"redo": "重做",
227+
"cut": "剪下",
228+
"copy": "複製",
229+
"paste": "貼上",
223230
"exclude_on": "恢復 $0 的執行",
224231
"exclude_off": "排除 $0 的執行",
225232
"user_config": "使用者設定",

src/pages/options/routes/script/ScriptEditor.tsx

Lines changed: 96 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,18 @@ type EditorMenu = {
9393
title: string;
9494
tooltip?: string;
9595
action?: (script: Script, e: editor.ICodeEditor) => void;
96-
items?: {
97-
id: string;
98-
title: string;
99-
tooltip?: string;
100-
hotKey?: number;
101-
hotKeyString?: string;
102-
action: (script: Script, e: editor.ICodeEditor) => void;
103-
}[];
96+
items?: (
97+
| {
98+
id: string;
99+
title: string;
100+
tooltip?: string;
101+
hotKey?: number;
102+
hotKeyString?: string;
103+
action: (script: Script, e: editor.ICodeEditor) => void;
104+
divider?: never;
105+
}
106+
| { divider: true }
107+
)[];
104108
};
105109

106110
const emptyScript = async (template: string, hotKeys: any, target?: string) => {
@@ -498,6 +502,77 @@ function ScriptEditor() {
498502
},
499503
],
500504
},
505+
{
506+
title: t("edit"),
507+
items: [
508+
{
509+
id: "undo",
510+
title: t("undo"),
511+
hotKeyString: "Ctrl+Z",
512+
action(_script, e) {
513+
e.trigger("menu", "undo", null);
514+
},
515+
},
516+
{
517+
id: "redo",
518+
title: t("redo"),
519+
hotKeyString: "Ctrl+Shift+Z",
520+
action(_script, e) {
521+
e.trigger("menu", "redo", null);
522+
},
523+
},
524+
{ divider: true },
525+
{
526+
id: "cut",
527+
title: t("cut"),
528+
hotKeyString: "Ctrl+X",
529+
action(_script, e) {
530+
e.trigger("menu", "editor.action.clipboardCutAction", null);
531+
},
532+
},
533+
{
534+
id: "copy",
535+
title: t("copy"),
536+
hotKeyString: "Ctrl+C",
537+
action(_script, e) {
538+
e.trigger("menu", "editor.action.clipboardCopyAction", null);
539+
},
540+
},
541+
{
542+
id: "paste",
543+
title: t("paste"),
544+
hotKeyString: "Ctrl+V",
545+
action(_script, e) {
546+
e.trigger("menu", "editor.action.clipboardPasteAction", null);
547+
},
548+
},
549+
{ divider: true },
550+
{
551+
id: "find",
552+
title: t("find"),
553+
hotKeyString: "Ctrl+F",
554+
action(_script, e) {
555+
e.getAction("actions.find")?.run();
556+
},
557+
},
558+
{
559+
id: "replace",
560+
title: t("replace"),
561+
hotKeyString: "Ctrl+H",
562+
action(_script, e) {
563+
e.getAction("editor.action.startFindReplaceAction")?.run();
564+
},
565+
},
566+
{
567+
id: "selectAll",
568+
title: t("select_all"),
569+
hotKeyString: "Ctrl+A",
570+
action(_script, e) {
571+
e.trigger("menu", "editor.action.selectAll", null);
572+
},
573+
},
574+
],
575+
},
501576
{
502577
title: t("run"),
503578
items: [
@@ -579,7 +654,7 @@ function ScriptEditor() {
579654
hotKeys.current = [];
580655
menu.forEach((item) => {
581656
item.items?.forEach((menuItem) => {
582-
if (menuItem.hotKey) {
657+
if (!menuItem.divider && menuItem.hotKey) {
583658
hotKeys.current.push({
584659
id: menuItem.id,
585660
title: menuItem.title,
@@ -841,16 +916,25 @@ function ScriptEditor() {
841916
}
842917
return (
843918
<Dropdown
844-
key={`d_${index.toString()}`}
919+
key={`d_${index}`}
845920
droplist={
846921
<Menu
847922
style={{
848923
padding: "0",
849924
margin: "0",
850925
borderRadius: "0",
926+
maxHeight: "none",
927+
overflow: "visible",
851928
}}
852929
>
853930
{item.items.map((menuItem, i) => {
931+
if (menuItem.divider) {
932+
return (
933+
<div key={`divider_${i}`} style={{ padding: "4px 0", background: "var(--color-secondary)" }}>
934+
<div style={{ height: "1px", backgroundColor: "var(--color-neutral-4)" }} />
935+
</div>
936+
);
937+
}
854938
const btn = (
855939
<Button
856940
style={{
@@ -896,15 +980,15 @@ function ScriptEditor() {
896980
);
897981
return (
898982
<Menu.Item
899-
key={`m_${i.toString()}`}
983+
key={`m_${i}`}
900984
style={{
901985
height: "unset",
902986
padding: "0",
903987
lineHeight: "unset",
904988
}}
905989
>
906990
{menuItem.tooltip ? (
907-
<Tooltip key={`m${i.toString()}`} position="right" content={menuItem.tooltip}>
991+
<Tooltip key={`m${i}`} position="right" content={menuItem.tooltip}>
908992
{btn}
909993
</Tooltip>
910994
) : (

0 commit comments

Comments
 (0)