Skip to content

Commit f65cb9e

Browse files
committed
feat(monaco-editor): 优化使用指定字符集打开文件功能 | Optimize the function of opening files using the specified character set.
#14
1 parent b6ebe15 commit f65cb9e

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

public/i18n/en_US.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
}
285285
},
286286
"menu": {
287+
"charset": {
288+
"label": "Character set",
289+
"placeholder": "The name of the character set",
290+
"text": "Open the file with encoding"
291+
},
287292
"confirm": {
288293
"placeholder": "The full path to the resource",
289294
"text": "Warning: You are operating on a protected resource ${1} !<br/>Your subsequent activities may lead to data loss or damage!<br/><br/>If you want to continue the operation, please enter the complete path of the resource ${2} in the text box below",

public/i18n/zh_CHT.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
}
285285
},
286286
"menu": {
287+
"charset": {
288+
"label": "字符集",
289+
"placeholder": "字符集名稱",
290+
"text": "使用編碼打開文件"
291+
},
287292
"confirm": {
288293
"placeholder": "資源完整路徑",
289294
"text": "警告:您正在操作受保護的資源 ${1} !<br/>您之後的活動可能導致資料丟失或損壞!<br/><br/>若繼續操作,請在下方文字框中輸入該資源的完整路徑 ${2}",

public/i18n/zh_CN.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
}
285285
},
286286
"menu": {
287+
"charset": {
288+
"label": "字符集",
289+
"placeholder": "字符集名称",
290+
"text": "使用编码打开文件"
291+
},
287292
"confirm": {
288293
"placeholder": "资源完整路径",
289294
"text": "警告:您正在操作受保护的资源 ${1} !<br/>您之后的活动可能导致数据丢失或损坏!<br/><br/>若继续操作,请在下方文本框中输入该资源的完整路径 ${2}",

src/handlers/asset.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type { IEditorModel } from "@/types/editor";
2222
import type { IMonacoEditorOptions } from "@/types/config";
2323
import { staticPathname2WorkspacePath } from "@workspace/utils/siyuan/url";
2424
import { extname } from "@workspace/utils/path/browserify";
25-
import { UTF8_CHAR_SET, type TLabel } from "@workspace/utils/coder/text";
25+
import { UTF8_CHAR_SET, type TLabel, CHAR_SET_LIST, CHAR_SET } from "@workspace/utils/coder/text";
2626
import { detect } from "@workspace/utils/coder/text/charset";
2727
import { TextTranscoder } from "@workspace/utils/coder/text/transcoder";
2828
import { fn__code } from "@workspace/utils/siyuan/text/span";
@@ -97,7 +97,7 @@ export class AssetHandler extends Handler {
9797
handler: IAssetHandler,
9898
): Promise<void> {
9999
try {
100-
this.plugin.siyuan.showMessage(`charset: ${fn__code(charset)}`);
100+
this.plugin.siyuan.showMessage(`${this.plugin.i18n.menu.charset.label}: ${fn__code(charset)}`);
101101

102102
const buffer = await blob.arrayBuffer();
103103
const transcoder = new TextTranscoder(charset);
@@ -152,8 +152,12 @@ export class AssetHandler extends Handler {
152152

153153
if (flag_trans) {
154154
const input = await asyncPrompt(this.plugin.siyuan.Dialog, {
155-
title: "charset",
156-
value: charset,
155+
title: `${fn__code(this.plugin.name)}: ${this.plugin.i18n.menu.charset.label}`,
156+
text: this.plugin.i18n.menu.charset.text,
157+
placeholder: this.plugin.i18n.menu.charset.placeholder,
158+
value: charset || "utf-8",
159+
datalist: CHAR_SET_LIST,
160+
confirm: value => CHAR_SET.has(value as TLabel),
157161
}) as TLabel;
158162
await this.updateHandlerWithCharset(input, response, options, handler);
159163
}

0 commit comments

Comments
 (0)