From bf4673b00b59c36946a2b65ec49051ad7d2eeb77 Mon Sep 17 00:00:00 2001 From: yiliang114 <1204183885@qq.com> Date: Fri, 5 Dec 2025 18:03:08 +0800 Subject: [PATCH] feat(vscode-ide-companion/webview): enhance text selection tracking and restore path --- .../src/webview/WebViewProvider.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/vscode-ide-companion/src/webview/WebViewProvider.ts b/packages/vscode-ide-companion/src/webview/WebViewProvider.ts index b229eb2e..1efde30c 100644 --- a/packages/vscode-ide-companion/src/webview/WebViewProvider.ts +++ b/packages/vscode-ide-companion/src/webview/WebViewProvider.ts @@ -900,6 +900,35 @@ export class WebViewProvider { }); } + // Listen for text selection changes (restore path) + const selectionChangeDisposableRestore = + vscode.window.onDidChangeTextEditorSelection((event) => { + const editor = event.textEditor; + if (editor === vscode.window.activeTextEditor) { + const filePath = editor.document.uri.fsPath || null; + const fileName = filePath ? getFileName(filePath) : null; + + // Get selection info if there is any selected text + let selectionInfo = null; + if (!event.selections[0].isEmpty) { + const selection = event.selections[0]; + selectionInfo = { + startLine: selection.start.line + 1, + endLine: selection.end.line + 1, + }; + } + + // Update last known state + _lastEditorState = { fileName, filePath, selection: selectionInfo }; + + this.sendMessageToWebView({ + type: 'activeEditorChanged', + data: { fileName, filePath, selection: selectionInfo }, + }); + } + }); + this.disposables.push(selectionChangeDisposableRestore); + // Capture the tab reference on restore this.panelManager.captureTab();