Skip to content

Commit

Permalink
fix Web IDE visual script tab handling issue. [skip CI]
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Dec 19, 2023
1 parent e93f881 commit d25b6de
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Tools/dora-dora/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"react-syntax-highlighter": "^15.5.0",
"remark-gfm": "^4.0.0",
"tailwindcss": "^3.0.2",
"typescript": "^5.2.2"
"typescript": "^5.3.3"
},
"scripts": {
"start": "node scripts/start.js",
Expand Down
62 changes: 60 additions & 2 deletions Tools/dora-dora/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,48 @@ export default function PersistentDrawerLeft() {
setExpandedKeys(keys);
};

const addNewFileNodeInTree = (parentFullPath: string, newFile: string, newName: string) => {
const rootNode = treeData.at(0);
if (rootNode === undefined) return;
const newNode: TreeDataType = {
key: newFile,
title: newName,
dir: false,
};
const visitData = (node: TreeDataType) => {
if (node.key === parentFullPath) return "find";
if (node.children) {
for (let i = 0; i < node.children.length; i++) {
const res = visitData(node.children[i]);
if (res === "find") {
let parent = node.children[i];
if (parent.dir) {
if (parent.children === undefined) {
parent.children = [];
}
} else {
parent = node;
}
if (parent.children !== undefined && parent.children.find(n => n.key === newFile) === undefined) {
parent.children.push(newNode);
}
return "stop";
} else if (res === "stop") {
return "stop";
}
}
}
return "continue";
};
if (visitData(rootNode) === "find") {
if (rootNode.children === undefined) {
rootNode.children = [];
}
rootNode.children.push(newNode);
}
setTreeData([rootNode]);
};

const saveCurrentTab = () => {
if (tabIndex === null) return;
const file = files[tabIndex];
Expand Down Expand Up @@ -498,13 +540,21 @@ export default function PersistentDrawerLeft() {
Service.write({path: tlFile, content: tealCode}).then((res) => {
if (res.success) {
if (fileInTab !== undefined) {
setFiles(prev => prev.filter(f => f.key !== fileInTab.key));
setFiles(prev => {
const newTabs = prev.filter(f => f.key !== fileInTab.key);
const newIndex = newTabs.findIndex(t => t.key === file.key);
if (newIndex >= 0) {
setTabIndex(newIndex);
}
return newTabs;
});
}
} else {
addAlert(t("alert.saveCurrent"), "error");
}
}).then(() => {
saveFile();
addNewFileNodeInTree(path.dirname(tlFile), tlFile, path.basename(tlFile));
Service.check({file: tlFile, content: tealCode}).then((res) => {
if (res.success && tealCode !== "") {
codeWireData.reportVisualScriptError("");
Expand Down Expand Up @@ -601,13 +651,21 @@ export default function PersistentDrawerLeft() {
Service.write({path: tlFile, content: tealCode}).then((res) => {
if (res.success) {
if (fileInTab !== undefined) {
setFiles(prev => prev.filter(f => f.key !== fileInTab.key));
setFiles(prev => {
const newTabs = prev.filter(f => f.key !== fileInTab.key);
const newIndex = newTabs.findIndex(t => t.key === file.key);
if (newIndex >= 0) {
setTabIndex(newIndex);
}
return newTabs;
});
}
} else {
addAlert(t("alert.save", {title: file.title}), "error");
}
}).then(() => {
saveFile(vscript);
addNewFileNodeInTree(path.dirname(tlFile), tlFile, path.basename(tlFile));
Service.check({file: tlFile, content: tealCode}).then((res) => {
if (res.success) {
codeWireData.reportVisualScriptError("");
Expand Down
2 changes: 1 addition & 1 deletion Tools/dora-dora/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ monaco.languages.registerSignatureHelpProvider("lua", signatureHelpProvider(["("
monaco.languages.register({id: 'yue'});
monaco.languages.setLanguageConfiguration("yue", yuescript.config);
monaco.languages.setMonarchTokensProvider("yue", yuescript.language);
const yueComplete = completionItemProvider([".", "::", "\\", "/", "\"", "'"], "yue");
const yueComplete = completionItemProvider([".", "\\", "/", "\"", "'"], "yue");
monaco.languages.registerCompletionItemProvider("yue", yueComplete);
monaco.languages.registerHoverProvider("yue", hoverProvider("yue"));
monaco.languages.registerSignatureHelpProvider("yue", signatureHelpProvider(["(", ",", " "], "yue"));
Expand Down
2 changes: 1 addition & 1 deletion Tools/dora-dora/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10605,7 +10605,7 @@ typed-array-length@^1.0.4:
for-each "^0.3.3"
is-typed-array "^1.1.9"

typescript@^5.2.2:
typescript@^5.3.3:
version "5.3.3"
resolved "https://registry.npmmirror.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==
Expand Down

0 comments on commit d25b6de

Please sign in to comment.