Add active files to file context menu (#4048)
* Add active files to file context menu Add support to include active files (open tabs) within the WorkspaceTracker. This enables the tracker to send the webview with a file list that has active files listed at the top. The changes include: - Listening for tab group changes using `vscode.window.tabGroups.onDidChangeTabs` to trigger workspace updates. - Introducing an `activeFiles` getter that retrieves the file paths of all currently open text editor tabs. - Modifying the `workspaceDidUpdate` function to include both `activeFiles` and `filePaths` when posting the `workspaceUpdated` message to the webview. * use set * add changeset
This commit is contained in:
1 parent
14b6e71416
commit
5b3647fdff
2 files changed
+17
-1
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": minor
|
||||
---
|
||||
|
||||
Prioritize active files in file context menu
|
||||
@@ -10,6 +10,14 @@ class WorkspaceTracker {
|
||||
private disposables: vscode.Disposable[] = []
|
||||
private filePaths: Set<string> = new Set()
|
||||
|
||||
private get activeFiles() {
|
||||
return new Set(
|
||||
vscode.window.tabGroups.activeTabGroup.tabs
|
||||
.filter((tab) => tab.input instanceof vscode.TabInputText)
|
||||
.map((tab) => (tab.input as vscode.TabInputText).uri.fsPath),
|
||||
)
|
||||
}
|
||||
|
||||
constructor(private readonly postMessageToWebview: (message: ExtensionMessage) => Promise<void>) {
|
||||
this.postMessageToWebview = postMessageToWebview
|
||||
this.registerListeners()
|
||||
@@ -36,6 +44,9 @@ class WorkspaceTracker {
|
||||
// Listen for file renaming
|
||||
this.disposables.push(vscode.workspace.onDidRenameFiles(this.onFilesRenamed.bind(this)))
|
||||
|
||||
// Listen for tab groups changes
|
||||
this.disposables.push(vscode.window.tabGroups.onDidChangeTabs(this.workspaceDidUpdate.bind(this)))
|
||||
|
||||
/*
|
||||
An event that is emitted when a workspace folder is added or removed.
|
||||
**Note:** this event will not fire if the first workspace folder is added, removed or changed,
|
||||
@@ -86,7 +97,7 @@ class WorkspaceTracker {
|
||||
}
|
||||
this.postMessageToWebview({
|
||||
type: "workspaceUpdated",
|
||||
filePaths: Array.from(this.filePaths).map((file) => {
|
||||
filePaths: Array.from(new Set([...this.activeFiles, ...this.filePaths])).map((file) => {
|
||||
const relativePath = path.relative(cwd, file).toPosix()
|
||||
return file.endsWith("/") ? relativePath + "/" : relativePath
|
||||
}),
|
||||
|
||||
Reference in new issue
Block a user