diff --git a/src/cmd.js b/src/cmd.js index cc47ffb..ecf58fc 100644 --- a/src/cmd.js +++ b/src/cmd.js @@ -540,11 +540,11 @@ const change_current_module = (state, current_module) => { } } -const change_entrypoint = (state, entrypoint) => { +const change_entrypoint = (state, entrypoint, current_module = entrypoint) => { return run_code( {...state, entrypoint, - current_module: entrypoint, + current_module, } ) } diff --git a/src/editor/files.js b/src/editor/files.js index 3c59b8a..4038a23 100644 --- a/src/editor/files.js +++ b/src/editor/files.js @@ -226,33 +226,32 @@ export class Files { exec('change_current_module', file.path) } } else { - if(file.path == null) { // root of examples dir, do nothing - return - } - - if(file.path == '') { + } else if(file.path == '') { exec('change_entrypoint', '') - return - } + } else { + const find_node = n => + n.path == file.path + || + n.children != null && n.children.find(find_node) - const find_node = n => - n.path == file.path - || - n.children != null && n.children.find(find_node) + // find example dir + const example_dir = get_state().project_dir.children.find( + c => find_node(c) != null + ) - // find example dir - const example_dir = get_state().project_dir.children.find( - c => find_node(c) != null - ) - - // in examples mode, on click file we also change entrypoint for - // simplicity - const example = examples.find(e => e.path == example_dir.path) - exec('change_entrypoint', example.entrypoint) - if(example.with_app_window && !localStorage.onboarding_open_app_window) { - this.ui.toggle_open_app_window_tooltip(true) + // in examples mode, on click file we also change entrypoint for + // simplicity + const example = examples.find(e => e.path == example_dir.path) + exec( + 'change_entrypoint', + example.entrypoint, + file.kind == 'directory' ? undefined : file.path + ) + if(example.with_app_window && !localStorage.onboarding_open_app_window) { + this.ui.toggle_open_app_window_tooltip(true) + } } }