Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
- fixed error caused by new text auto-completions
- auto-completion LIB may now contain functions
- renamed "internal_buildFromCache" to "buildFromCache"
- added Bridge.FS.readDirectorySync(...)
- fixed bridge:saveFile event linking to wrongly structured "previous" object
- fixed undo
  • Loading branch information
solvedDev committed Apr 29, 2019
1 parent 6c703f2 commit 6ea0e82
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/renderer/components/editor_shell/TextAutoCompletions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@
methods: {
updateSuggestions(propose, sel_obj) {
last_sel_object = sel_obj;
this.x = Number(cursors.children[0].style.left.replace("px", ""));
this.y = Number(cursors.children[0].style.top.replace("px", ""));
if(cursors.children[0] !== undefined) {
this.x = Number(cursors.children[0].style.left.replace("px", ""));
this.y = Number(cursors.children[0].style.top.replace("px", ""));
}
if(propose.length > 0) {
this.propose = propose;
Expand Down
8 changes: 6 additions & 2 deletions src/renderer/scripts/TabSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,16 @@ class TabSystem {
if(cap <= 0) return PluginAssert.throw("Dependency Update Failed", new Error("Reached maximum update depth. Make sure you haven't created a dependency loop!"));
FileSystem.Cache.get(file_path)
.then(cache => {
if(cache.update != undefined) {
if(cache.update !== undefined) {
cache.update.forEach(file => {
console.log("[UPDATE] Dependency " + file);
FileSystem.Cache.get(file)
.then(d_cache => {
this.dependencyUpdate({ ...d_cache, file_path: file }, previous, cap);
this.dependencyUpdate({
...d_cache,
content: JSONTree.buildFromCache(d_cache.content),
file_path: file
}, previous, cap);
})
// .catch(err => console.log("File \"" + file + "\" does not exist in cache. Cannot update."));
.catch(err => console.error(err));
Expand Down
1 change: 1 addition & 0 deletions src/renderer/scripts/TabSystem/CommonHistory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
import Store from "../../store/index";
import ProblemIterator from "../editor/problems/Problems";
import TabSystem from "../TabSystem";

/**
* @class History
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/scripts/autoCompletions/Dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let PARENT_CONTEXT = {};
let NODE_CONTEXT = {};
let PREV_CONTEXT = undefined;

function walkSync(dir, filelist = []) {
export function walkSync(dir, filelist = []) {
fs.readdirSync(dir).forEach(file => {

filelist = fs.statSync(path.join(dir, file)).isDirectory()
Expand Down
9 changes: 7 additions & 2 deletions src/renderer/scripts/autoCompletions/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ class Provider {
}

get(path, context) {
if(this.start_state === "unknown") return { object: [], value: [] };
path = path.replace("global",
VersionMap.convert(this.start_state, Store.state.Settings.target_version)
);
SET_CONTEXT(context, context === undefined ? undefined : context.parent);
let propose = this.walk(path.split("/"));
console.log("[PROPOSING]", path, propose, LIB);
// console.log("[PROPOSING]", path, propose, LIB);

return this.preparePropose(propose, context === undefined ? [] : Object.keys(context.toJSON(false)));
}
Expand Down Expand Up @@ -172,7 +173,11 @@ class Provider {
}

walk(path_arr, current=LIB) {
if(typeof current === "string") {
if(typeof current === "function") {
if(path_arr.length === 0)
return { object: {}, value: current() };
current = current();
} else if(typeof current === "string") {
let { object, value } = this.omegaExpression(current);
if(path_arr.length === 0)
return { object, value };
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/scripts/editor/JsonTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,14 @@ export default class JSONTree {
};
}
static buildFromCache(c) {
return new JSONTree(c.key, c.data, undefined, undefined, c.open).internal_buildFromCache(c);
return new JSONTree(c.key, c.data, undefined, undefined, c.open).buildFromCache(c);
}
internal_buildFromCache(c) {
buildFromCache(c) {
//Load attributes which cannot be set with constructor
this.comment = c.comment;
this.type = c.type || (c.data === "" ? "object" : typeof Json.toCorrectType(c.data));

this.children = c.children.map(child => new JSONTree(child.key, child.data, this, undefined, child.open).internal_buildFromCache(child));
this.children = c.children.map(child => new JSONTree(child.key, child.data, this, undefined, child.open).buildFromCache(child));
return this;
}

Expand Down
18 changes: 16 additions & 2 deletions src/renderer/scripts/plugins/Bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import FileSystem from "../FileSystem";
import { BASE_PATH } from "../constants";
import JSONTree from "../editor/JsonTree";
import Provider from "../autoCompletions/Provider";
import { walkSync } from "../autoCompletions/Dynamic";

export default class Bridge {
constructor(is_module, file_path) {
Expand Down Expand Up @@ -121,6 +122,14 @@ export default class Bridge {
cb(err, data);
});
},
readDirectorySync(path, deep=false) {
if(deep)
return walkSync(Runtime.Paths.project() + path).map(e => {
return e.replace(BASE_PATH.replace(/\//g, "\\") + Store.state.Explorer.project + "\\", "").replace(/\\/g, "/");
});
else
return fs.readdirSync(Runtime.Paths.project() + path);
},
exists(path) {
return fs.existsSync((Runtime.Paths.project() + path).replace(/\//g, "\\"));
},
Expand Down Expand Up @@ -200,7 +209,7 @@ export default class Bridge {

this.Footer = {
register(footer_element) {
if(footer_element.id == undefined) throw new Error("No footer id defined.");
if(footer_element.id === undefined) throw new Error("No footer id defined.");
Store.commit("addPluginFooter", footer_element);
},
update(footer_element) {
Expand All @@ -213,7 +222,7 @@ export default class Bridge {

this.Window = {
register(window) {
if(window.id == undefined) throw new Error("No window id defined.");
if(window.id === undefined) throw new Error("No window id defined.");
Store.commit("addPluginWindow", window);
},
update(window) {
Expand Down Expand Up @@ -267,6 +276,11 @@ export default class Bridge {
},
get current_file_content() {
return TabSystem.getSelected().content;
},
get current_file_name() {
let arr = TabSystem.getSelected().file_path.split(/\/|\\/g).pop().split(".");
arr.pop();
return arr.join(".");
}
};
}
Expand Down

0 comments on commit 6ea0e82

Please sign in to comment.