Fix: 修复图形块转代码时中文变量和函数名未编码

This commit is contained in:
王立帮
2024-10-12 20:51:19 +08:00
parent 05be16af79
commit 0e42ca74d4
2 changed files with 11 additions and 2 deletions

View File

@@ -181,6 +181,10 @@ class EditorBlockly extends EditorBase {
return $xml[0].outerHTML; return $xml[0].outerHTML;
} }
this.getRawCode = (workspace, generator) => {
return generator?.workspaceToCode(workspace) || '';
}
this.getCode = (workspace, generator) => { this.getCode = (workspace, generator) => {
let code = generator?.workspaceToCode(workspace) || ''; let code = generator?.workspaceToCode(workspace) || '';
code = code.replace(/(_E[0-9A-F]{1}_[0-9A-F]{2}_[0-9A-F]{2})+/g, function (s) { code = code.replace(/(_E[0-9A-F]{1}_[0-9A-F]{2}_[0-9A-F]{2})+/g, function (s) {
@@ -327,6 +331,11 @@ class EditorBlockly extends EditorBase {
return EditorBlockly.getXML(workspace); return EditorBlockly.getXML(workspace);
} }
getRawCode() {
const workspace = this.#getTargetWorkspace_();
return EditorBlockly.getRawCode(workspace, Blockly.generator);
}
getCode() { getCode() {
const workspace = this.#getTargetWorkspace_(); const workspace = this.#getTargetWorkspace_();
return EditorBlockly.getCode(workspace, Blockly.generator); return EditorBlockly.getCode(workspace, Blockly.generator);

View File

@@ -458,8 +458,8 @@ class EditorMix extends EditorBase {
getCode() { getCode() {
const blockPage = this.getPage('block'); const blockPage = this.getPage('block');
const codePage = this.getPage('code'); const codePage = this.getPage('code');
if (this.drag.shown === Drag.Extend.POSITIVE) { if (this.drag.shown !== Drag.Extend.NEGATIVE) {
return blockPage.getCode(); return blockPage.getRawCode();
} else { } else {
return codePage.getCode(); return codePage.getCode();
} }