[ide-mode] Hide diff options when active diff is not focused (#5808)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
parent
51d09e720b
commit
407393b128
|
@ -54,11 +54,25 @@ export class DiffManager {
|
||||||
new vscode.EventEmitter<JSONRPCNotification>();
|
new vscode.EventEmitter<JSONRPCNotification>();
|
||||||
readonly onDidChange = this.onDidChangeEmitter.event;
|
readonly onDidChange = this.onDidChangeEmitter.event;
|
||||||
private diffDocuments = new Map<string, DiffInfo>();
|
private diffDocuments = new Map<string, DiffInfo>();
|
||||||
|
private readonly subscriptions: vscode.Disposable[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly log: (message: string) => void,
|
private readonly log: (message: string) => void,
|
||||||
private readonly diffContentProvider: DiffContentProvider,
|
private readonly diffContentProvider: DiffContentProvider,
|
||||||
) {}
|
) {
|
||||||
|
this.subscriptions.push(
|
||||||
|
vscode.window.onDidChangeActiveTextEditor((editor) => {
|
||||||
|
this.onActiveEditorChange(editor);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
this.onActiveEditorChange(vscode.window.activeTextEditor);
|
||||||
|
}
|
||||||
|
|
||||||
|
dispose() {
|
||||||
|
for (const subscription of this.subscriptions) {
|
||||||
|
subscription.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and shows a new diff view.
|
* Creates and shows a new diff view.
|
||||||
|
@ -199,6 +213,18 @@ export class DiffManager {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async onActiveEditorChange(editor: vscode.TextEditor | undefined) {
|
||||||
|
const isVisible =
|
||||||
|
!!editor &&
|
||||||
|
editor.document.uri.scheme === DIFF_SCHEME &&
|
||||||
|
this.diffDocuments.has(editor.document.uri.toString());
|
||||||
|
await vscode.commands.executeCommand(
|
||||||
|
'setContext',
|
||||||
|
'gemini.diff.isVisible',
|
||||||
|
isVisible,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private addDiffDocument(uri: vscode.Uri, diffInfo: DiffInfo) {
|
private addDiffDocument(uri: vscode.Uri, diffInfo: DiffInfo) {
|
||||||
this.diffDocuments.set(uri.toString(), diffInfo);
|
this.diffDocuments.set(uri.toString(), diffInfo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,13 @@ vi.mock('vscode', () => ({
|
||||||
show: vi.fn(),
|
show: vi.fn(),
|
||||||
sendText: vi.fn(),
|
sendText: vi.fn(),
|
||||||
})),
|
})),
|
||||||
|
onDidChangeActiveTextEditor: vi.fn(),
|
||||||
|
activeTextEditor: undefined,
|
||||||
|
tabGroups: {
|
||||||
|
all: [],
|
||||||
|
close: vi.fn(),
|
||||||
|
},
|
||||||
|
showTextDocument: vi.fn(),
|
||||||
},
|
},
|
||||||
workspace: {
|
workspace: {
|
||||||
workspaceFolders: [],
|
workspaceFolders: [],
|
||||||
|
|
Loading…
Reference in New Issue