New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(smartAutocomplete): View data update on file change #103
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,47 +3,63 @@ import {TextDocumentContentProvider} from './TextDocumentContentProvider'; | |
|
||
export function registerPreview(context, window, client) { | ||
|
||
const aureliaViewDataPanelType = 'aureliaViewData'; | ||
|
||
let previewUri = vscode.Uri.parse('aurelia-preview://authority/aurelia-preview'); | ||
|
||
let provider = new TextDocumentContentProvider(client); | ||
let registration = vscode.workspace.registerTextDocumentContentProvider('aurelia-preview', provider); | ||
let isPanelVisible: boolean = false; | ||
let panel: vscode.WebviewPanel; | ||
|
||
function fillWebViewHtml(bodyContent: string): string { | ||
return ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Cat Coding</title> | ||
</head> | ||
${bodyContent} | ||
</html> | ||
`; | ||
} | ||
|
||
vscode.workspace.onDidChangeTextDocument((e: vscode.TextDocumentChangeEvent) => { | ||
if (!isPanelVisible) return; | ||
if (e.document === vscode.window.activeTextEditor.document) { | ||
provider.update(previewUri); | ||
provider.update(previewUri).then(success => { | ||
panel.webview.html = fillWebViewHtml(success); | ||
}); | ||
} | ||
}); | ||
|
||
vscode.window.onDidChangeTextEditorSelection((e: vscode.TextEditorSelectionChangeEvent) => { | ||
if (e.textEditor === vscode.window.activeTextEditor) { | ||
provider.update(previewUri); | ||
} | ||
vscode.window.onDidChangeActiveTextEditor((editor: vscode.TextEditor) => { | ||
setTimeout(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I could not solve it another way atm. |
||
if (!isPanelVisible) return; | ||
if (editor === vscode.window.activeTextEditor) { | ||
provider.update(previewUri).then(success => { | ||
panel.webview.html = fillWebViewHtml(success); | ||
}); | ||
} | ||
}, 0); | ||
}); | ||
|
||
context.subscriptions.push(vscode.commands.registerCommand('aurelia.showViewProperties', () => { | ||
|
||
const smartAutocomplete = vscode.workspace.getConfiguration().get('aurelia.featureToggles.smartAutocomplete'); | ||
if (smartAutocomplete) { | ||
const panel = vscode.window.createWebviewPanel( | ||
'aureliaViewData', | ||
panel = vscode.window.createWebviewPanel( | ||
aureliaViewDataPanelType, | ||
'Aurelia view data', | ||
vscode.ViewColumn.Two, | ||
); | ||
|
||
provider.provideTextDocumentContent(previewUri) | ||
.then( | ||
(success) => { | ||
panel.webview.html = ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Cat Coding</title> | ||
</head> | ||
${success} | ||
</html> | ||
` | ||
panel.webview.html = fillWebViewHtml(success); | ||
}, | ||
(reason) => { | ||
window.showErrorMessage(reason); | ||
|
@@ -52,8 +68,23 @@ export function registerPreview(context, window, client) { | |
return vscode.window.showWarningMessage('This command requires the experimental feature "smartAutocomplete" to be enabled'); | ||
} | ||
|
||
/** | ||
* Set panel visible flag to true, if | ||
* - we have the correct WebView type (multiple WebView types possible) | ||
* - and panel itself is not active | ||
*/ | ||
panel.onDidChangeViewState(event => { | ||
const correctPanelType = (event.webviewPanel.viewType === aureliaViewDataPanelType); | ||
/** Don't update panel if the panel itself is 'active' */ | ||
const panelNotActive = !event.webviewPanel.active | ||
isPanelVisible = correctPanelType && panelNotActive; | ||
}); | ||
|
||
panel.onDidDispose(event => { | ||
isPanelVisible = false; | ||
}); | ||
|
||
})); | ||
})); | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,5 +119,6 @@ | |
|
||
public update(uri: vscode.Uri) { | ||
this._onDidChange.fire(uri); | ||
return this.provideTextDocumentContent(uri); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to return content for webview |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
onDidChangeTextEditorSelection
toonDidChangeActiveTextEditor
.Looking at this again after a while, seems like the intent behind
onDidChangeTextEditorSelection
was to update the webview after changes as well.I might revert this change