Skip to content

Commit

Permalink
add selection even listener to detect cursor movement
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewbastien committed Feb 27, 2025
1 parent 8b52e1f commit 3da633b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/documentation/DocumentationPreviewEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class DocumentationPreviewEditor implements vscode.Disposable {
}

private activeTextEditor?: vscode.TextEditor;
private activeTextEditorSelection?: vscode.Selection;
private subscriptions: vscode.Disposable[] = [];

private disposeEmitter = new vscode.EventEmitter<void>();
Expand All @@ -110,6 +111,7 @@ export class DocumentationPreviewEditor implements vscode.Disposable {
this.subscriptions.push(
this.webviewPanel.webview.onDidReceiveMessage(this.receiveMessage, this),
vscode.window.onDidChangeActiveTextEditor(this.handleActiveTextEditorChange, this),
vscode.window.onDidChangeTextEditorSelection(this.handleSelectionChange, this),
vscode.workspace.onDidChangeTextDocument(this.handleDocumentChange, this),
this.webviewPanel.onDidDispose(this.dispose, this)
);
Expand Down Expand Up @@ -163,9 +165,21 @@ export class DocumentationPreviewEditor implements vscode.Disposable {
return;
}
this.activeTextEditor = activeTextEditor;
this.activeTextEditorSelection = activeTextEditor.selection;
this.convertDocumentation(activeTextEditor);
}

private handleSelectionChange(event: vscode.TextEditorSelectionChangeEvent) {
if (
this.activeTextEditor !== event.textEditor ||
this.activeTextEditorSelection === event.textEditor.selection
) {
return;
}
this.activeTextEditorSelection = event.textEditor.selection;
this.convertDocumentation(event.textEditor);
}

private handleDocumentChange(event: vscode.TextDocumentChangeEvent) {
if (this.activeTextEditor?.document === event.document) {
this.convertDocumentation(this.activeTextEditor);
Expand Down

0 comments on commit 3da633b

Please sign in to comment.