How to access search results in CustomTextEditor #2621
Unanswered
vaclavHala
asked this question in
Extension Development QnA
Replies: 2 comments
-
|
This is an old question, but I'd love to see an answer... I've been digging through the events that VS Code exposes, and none of them seem to trigger when the search result is clicked |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Hello! For CustomTextEditor providers, you can access search result selections through the class MyCustomTextEditorProvider implements vscode.CustomTextEditorProvider {
async resolveCustomTextEditor(
document: vscode.TextDocument,
webviewPanel: vscode.WebviewPanel,
token: vscode.CancellationToken,
options: { selection?: vscode.Selection }
): Promise<void> {
if (options?.selection) {
const { start, end } = options.selection;
await this.revealSearchResult(webviewPanel, start.line, start.character, end.line, end.character);
}
this.setupWebview(webviewPanel, document);
}
private async revealSearchResult(
webviewPanel: vscode.WebviewPanel,
startLine: number,
startChar: number,
endLine: number,
endChar: number
): Promise<void> {
webviewPanel.webview.postMessage({
type: 'NAVIGATE_TO_SEARCH_RESULT',
payload: {
start: { line: startLine, character: startChar },
end: { line: endLine, character: endChar }
}
});
}
}
vscode.window.registerCustomEditorProvider(
'myCustomEditor',
new MyCustomTextEditorProvider(),
{
webviewOptions: {
retainContextWhenHidden: true
},
supportsMultipleEditorsPerDocument: true
}
);Key points:
This approach provides seamless integration with VS Code's native search functionality for your custom text editor. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have registered a
CustomTextEditorProviderwith"priority": "default". Now when a user does text search through the nativeSearchview and clicks some result from file covered by my custom editor, the custom editor opens but always scrolled to the top.Is there some way to know what search result user wanted to go to from inside my custom editor provider so I can try to move to it/focus it somehow in the custom editor? Alternatively, is there some way to disable the custom editor when user tries to open the file at specific location rather than opening the custom editor?
Beta Was this translation helpful? Give feedback.
All reactions