From e53645e82497f86707644029bcf06135d3cb925a Mon Sep 17 00:00:00 2001 From: hippietrail Date: Sun, 26 Jan 2025 02:45:51 +0800 Subject: [PATCH] add a random tab command --- .gitignore | 1 + .vscode/settings.json | 37 +++++++++++++++++++++++++++++++++++++ out/extension.js | 23 +++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..caa3d2b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,37 @@ +{ + "randomFile.extensions": [ + + ".htm", + ".html", + ".md", + ".txt", + ".asm", + ".s", + ".c", + ".cpp", + ".h", + ".cs", + ".dart", + ".go", + ".jai", + ".java", + ".js", + ".jsx", + ".ts", + ".tsx", + ".kt", + ".lua", + ".odin", + ".php", + ".pl", + ".py", + ".rb", + ".rs", + ".sh", + ".swift", + ".zig" + ], + "randomFile.excludeDirs": [ + "node_modules" + ] +} \ No newline at end of file diff --git a/out/extension.js b/out/extension.js index 9eca684..d0cb2b7 100644 --- a/out/extension.js +++ b/out/extension.js @@ -27,8 +27,31 @@ async function randomFile() { } } +async function randomTab() { + try { + const tabGroups = vscode.window.tabGroups; + const numTabGroups = tabGroups.all.length; + + if (numTabGroups > 0) { + const g = Math.floor(Math.random() * numTabGroups); + + const tabGroup = tabGroups.all[g]; + const tabs = tabGroup.tabs; + const numTabs = tabs.length; + + if (numTabs > 0) { + await vscode.window.showTextDocument(tabs[Math.floor(Math.random() * numTabs)].input, { viewColumn: tabGroup.viewColumn }); + } + } + } catch (error) { + console.error(error); + vscode.window.showErrorMessage('An error occurred while trying to switch to a random tab.'); + } +} + exports.activate = function (context) { context.subscriptions.push(vscode.commands.registerCommand('extension.randomFile', randomFile)); + context.subscriptions.push(vscode.commands.registerCommand('extension.randomTab', randomTab)); }; exports.deactivate = function () { }