feat(vscode-ide-companion): send initial active editor state to WebView on initialization

- Send activeEditorChanged message with initial editor state when WebView is created
- Include fileName, filePath, and selection info if available
- Applied in both side panel and editor panel initialization

This ensures the WebView displays the current file context immediately on load.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yiliang114
2025-11-23 21:45:44 +08:00
parent 4f964b5281
commit 826516581b

View File

@@ -231,6 +231,27 @@ export class WebViewProvider {
});
this.disposables.push(selectionChangeDisposable);
// Send initial active editor state to WebView
const initialEditor = vscode.window.activeTextEditor;
if (initialEditor) {
const filePath = initialEditor.document.uri.fsPath || null;
const fileName = filePath ? getFileName(filePath) : null;
let selectionInfo = null;
if (!initialEditor.selection.isEmpty) {
const selection = initialEditor.selection;
selectionInfo = {
startLine: selection.start.line + 1,
endLine: selection.end.line + 1,
};
}
this.sendMessageToWebView({
type: 'activeEditorChanged',
data: { fileName, filePath, selection: selectionInfo },
});
}
// Check if we have valid auth cache and auto-reconnect
if (!this.agentInitialized) {
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
@@ -520,6 +541,27 @@ export class WebViewProvider {
);
this.disposables.push(editorChangeDisposable);
// Send initial active editor state to WebView
const initialEditor = vscode.window.activeTextEditor;
if (initialEditor) {
const filePath = initialEditor.document.uri.fsPath || null;
const fileName = filePath ? getFileName(filePath) : null;
let selectionInfo = null;
if (!initialEditor.selection.isEmpty) {
const selection = initialEditor.selection;
selectionInfo = {
startLine: selection.start.line + 1,
endLine: selection.end.line + 1,
};
}
this.sendMessageToWebView({
type: 'activeEditorChanged',
data: { fileName, filePath, selection: selectionInfo },
});
}
// Capture the tab reference on restore
this.panelManager.captureTab();