From 11d8b1eb4220949095533ae61a1a7b1a0613760b Mon Sep 17 00:00:00 2001 From: dutzi Date: Fri, 10 Jul 2020 02:31:30 +0300 Subject: [PATCH] add multi segment path support --- extension.js | 71 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/extension.js b/extension.js index f7d3d54..f62ecd0 100644 --- a/extension.js +++ b/extension.js @@ -63,35 +63,58 @@ exports.activate = context => { } } + function navigateTo(relavtivePath) { + const selectedPath = path.join(folderPath, relavtivePath); + const selectedFullPath = path.join(workspaceRoot, selectedPath); + + // If selected is a folder, traverse it, + // otherwise open file. + fs.stat(selectedFullPath, (statErr, stats) => { + if (stats.isDirectory()) { + searchPath(workspaceName, workspaceRoot, selectedPath); + } else { + lastWorkspaceName = workspaceName; + lastWorkspaceRoot = workspaceRoot; + lastFolder = folderPath; + + vscode.workspace.openTextDocument(selectedFullPath, selectedPath) + .then(vscode.window.showTextDocument); + } + }); + } - vscode.window.showQuickPick(options, { - placeHolder: path.format({ dir: workspaceName, base: folderPath}) - - }) - .then(selected => { - // node_modules shortcut selected - if (selected === workspaceNodeModules) { + let lastValue; + let lastSelection; + const quickPick = vscode.window.createQuickPick(); + quickPick.items = [ + ...options.map(option => ({label: option})), + { + alwaysShow: true, + label: 'Navigate...' + } + ]; + quickPick.placeHolder = path.format({ dir: workspaceName, base: folderPath}); + quickPick.onDidHide(() => quickPick.dispose()); + quickPick.onDidChangeSelection(selection => { + lastSelection = selection[0].label; + }); + quickPick.onDidChangeValue(value => { + lastValue = value; + }); + quickPick.onDidAccept(() => { + const selected = lastSelection; + if (selected === 'Navigate...') { + // "deep" navigate, using last entered value + navigateTo(lastValue); + } else if (selected === workspaceNodeModules) { + // node_modules shortcut selected searchPath(workspaceName, workspaceRoot, nodeModulesPath); } else { - const selectedPath = path.join(folderPath, selected); - const selectedFullPath = path.join(workspaceRoot, selectedPath); - - // If selected is a folder, traverse it, - // otherwise open file. - fs.stat(selectedFullPath, (statErr, stats) => { - if (stats.isDirectory()) { - searchPath(workspaceName, workspaceRoot, selectedPath); - } else { - lastWorkspaceName = workspaceName; - lastWorkspaceRoot = workspaceRoot; - lastFolder = folderPath; - - vscode.workspace.openTextDocument(selectedFullPath, selectedPath) - .then(vscode.window.showTextDocument); - } - }); + navigateTo(selected); } + }); + quickPick.show(); }); };