Skip to content

Commit 01c0f01

Browse files
committed
temp sending messages [ci skip]
1 parent 8137e7e commit 01c0f01

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

vscode/extension/src/webviews/lineagePanel.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ export class LineagePanel implements WebviewViewProvider, Disposable {
3030

3131
window.onDidChangeActiveTextEditor((editor) => {
3232
if (editor) {
33+
console.log("sending message to web view", editor.document.uri.fsPath, "panel is present", this.panel?.webview);
3334
this.panel?.webview.postMessage({
34-
key: "vscode_callback",
35+
key: "vscode_send",
3536
payload: {
3637
key: "changeFocusOnFile",
3738
payload: { path: editor.document.uri.fsPath },
@@ -82,9 +83,6 @@ export class LineagePanel implements WebviewViewProvider, Disposable {
8283
const document = await workspace.openTextDocument(fullPath);
8384
await window.showTextDocument(document);
8485
break;
85-
case "formatProject":
86-
console.log("formatProject", message.payload);
87-
break;
8886
default:
8987
console.log(`Unhandled message type in key: ${message.key}`);
9088
}
@@ -129,10 +127,19 @@ export class LineagePanel implements WebviewViewProvider, Disposable {
129127
130128
// Define a function to handle events from the extension and send them to the iframe
131129
const vscode = acquireVsCodeApi();
130+
vscode.postMessage = function(message) {
131+
// Forward the message to the iframe
132+
const iframe = document.querySelector('iframe');
133+
if (iframe && iframe.contentWindow) {
134+
iframe.contentWindow.postMessage(message, '*');
135+
}
136+
};
137+
138+
// Listen for messages from the extension
132139
window.addEventListener('message', (event) => {
133-
// Check if the message is from the extension
134-
if (event.source === window && event.data) {
135-
// Forward the message to the iframe
140+
console.log("message received in web view", event);
141+
// Only handle messages that are from the extension
142+
if (event.data && event.data.key === 'vscode_send') {
136143
const iframe = document.querySelector('iframe');
137144
if (iframe && iframe.contentWindow) {
138145
iframe.contentWindow.postMessage(event.data, '*');

vscode/react/src/routes/lineage.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ function Wrappper() {
2020
React.useEffect(() => {
2121
const handleMessage = (event: MessageEvent) => {
2222
// Ensure the message is from VSCode
23-
if (event.data && event.data.key === 'vscode_callback') {
23+
if (event.data && event.data.key === 'vscode_send') {
2424
const payload = event.data.payload
25-
console.log('Received message from VSCode:', payload)
26-
27-
// Handle different types of messages
2825
switch (payload.key) {
2926
case 'changeFocusOnFile':
3027
console.log('Changing focus to file:', payload.payload.path)
@@ -35,10 +32,7 @@ function Wrappper() {
3532
}
3633
}
3734
}
38-
3935
window.addEventListener('message', handleMessage)
40-
41-
// Clean up event listener on component unmount
4236
return () => {
4337
window.removeEventListener('message', handleMessage)
4438
}

0 commit comments

Comments
 (0)