Skip to content

Commit 4e1dfe9

Browse files
committed
编辑器 外部编辑按钮与顶栏其他开关按钮一样交互方式
1 parent 4c73b16 commit 4e1dfe9

2 files changed

Lines changed: 12 additions & 40 deletions

File tree

lib/translate/source.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,6 @@
691691
"处理帧数": "624330",
692692
"处理": "89e28c",
693693
"总耗时": "19b872",
694-
"正在外部编辑中,双击退出": "a4c134",
695694
"画布": "57d15e",
696695
"缩放": "8f0bb2",
697696
"移动和调节": "ca4116",

src/renderer/editor/editor.ts

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,8 @@ try {
113113
{};
114114
} catch (error) {}
115115

116-
let editOnOtherType: "o" | "c" | null = null;
117116
let fileWatcher: FSWatcher | null = null;
118117

119-
let editingOnOther = false;
120-
121118
let lo: import("esearch-ocr").initType;
122119

123120
const 浏览器打开 = store.get("浏览器中打开");
@@ -147,15 +144,14 @@ const navConciseSwitch = buttonSwitch(iconBEl("concise", "简洁模式"), (c) =>
147144
});
148145
nav.add([navTopSwitch, navDingSwitch, navConciseSwitch]).addInto();
149146

150-
const editOnOtherEl = iconBEl("super_edit", "其他编辑器打开")
151-
.on("click", () => {
152-
editOnOtherType = "o";
153-
editOnOther();
154-
})
155-
.on("contextmenu", () => {
156-
editOnOtherType = "c";
157-
editOnOther();
158-
});
147+
const editOnOtherEl = buttonSwitch(
148+
iconBEl("super_edit", "其他编辑器打开"),
149+
(c) => {
150+
editOnOther(c);
151+
},
152+
).on("contextmenu", () => {
153+
clipboard.writeText(tmpTextPath);
154+
});
159155
nav.add([editOnOtherEl]);
160156

161157
const ziCount = view().style({
@@ -1025,7 +1021,7 @@ function editorChange() {
10251021
find_();
10261022
}
10271023
countWords();
1028-
if (editingOnOther) writeEditOnOther();
1024+
if (editOnOtherEl.gv) writeEditOnOther();
10291025
if (isCheck) runSpellcheck();
10301026
}
10311027

@@ -1954,43 +1950,28 @@ renderOn("editorInit", ([name, list]) => {
19541950
}
19551951
});
19561952

1957-
function editOnOther() {
1958-
editingOnOther = !editingOnOther;
1953+
function editOnOther(editingOnOther: boolean) {
19591954
if (editingOnOther) {
19601955
const data = Buffer.from(editor.get());
19611956
fs.writeFile(tmpTextPath, data, () => {
1962-
if (editOnOtherType === "o") {
1963-
shell.openPath(tmpTextPath);
1964-
} else if (editOnOtherType === "c") {
1965-
openWith(tmpTextPath);
1966-
}
1957+
shell.openPath(tmpTextPath);
19671958
fileWatcher = fs.watch(tmpTextPath, () => {
19681959
fs.readFile(tmpTextPath, "utf8", (e, data) => {
19691960
if (e) console.log(e);
19701961
editor.push(data, true);
19711962
});
19721963
});
1973-
textOut.attr({ title: "正在外部编辑中,双击退出" });
1974-
document.addEventListener("dblclick", () => {
1975-
editingOnOther = true;
1976-
editOnOther();
1977-
});
19781964
});
19791965
} else {
19801966
try {
1981-
textOut.attr({ title: "" });
1982-
document.removeEventListener("dblclick", () => {
1983-
editingOnOther = true;
1984-
editOnOther();
1985-
});
19861967
fileWatcher?.close();
19871968
fs.unlink(tmpTextPath, () => {});
19881969
} catch {}
19891970
}
19901971
}
19911972

19921973
function writeEditOnOther() {
1993-
if (!editingOnOther) return;
1974+
if (!editOnOtherEl.gv) return;
19941975
const data = Buffer.from(editor.get());
19951976
fs.writeFile(tmpTextPath, data, () => {});
19961977
}
@@ -2030,14 +2011,6 @@ async function edit(arg: EditToolsType) {
20302011
case "show_history":
20312012
historySwitch.sv(!historySwitch.gv);
20322013
break;
2033-
case "edit_on_other":
2034-
editOnOtherType = "o";
2035-
editOnOther();
2036-
break;
2037-
case "choose_editer":
2038-
editOnOtherType = "c";
2039-
editOnOther();
2040-
break;
20412014
case "wrap":
20422015
wrap();
20432016
break;

0 commit comments

Comments
 (0)