mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
💄
This commit is contained in:
parent
1e1da2aed3
commit
6aba22da1a
|
@ -63,11 +63,12 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri
|
|||
|
||||
this.toUnhook.add(linkGesture.onExecute((mouseEvent: ClickLinkMouseEvent) => {
|
||||
if (this.isEnabled(mouseEvent)) {
|
||||
this.gotoDefinition(mouseEvent.target.position!, mouseEvent.hasSideBySideModifier).then(() => {
|
||||
this.removeLinkDecorations();
|
||||
}, (error: Error) => {
|
||||
this.removeLinkDecorations();
|
||||
this.gotoDefinition(mouseEvent.target.position!, mouseEvent.hasSideBySideModifier)
|
||||
.catch((error: Error) => {
|
||||
onUnexpectedError(error);
|
||||
})
|
||||
.finally(() => {
|
||||
this.removeLinkDecorations();
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
@ -82,14 +83,13 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri
|
|||
return editor.getContribution<GotoDefinitionAtPositionEditorContribution>(GotoDefinitionAtPositionEditorContribution.ID);
|
||||
}
|
||||
|
||||
startFindDefinitionFromCursor(position: Position) {
|
||||
async startFindDefinitionFromCursor(position: Position) {
|
||||
// For issue: https://github.com/microsoft/vscode/issues/46257
|
||||
// equivalent to mouse move with meta/ctrl key
|
||||
|
||||
// First find the definition and add decorations
|
||||
// to the editor to be shown with the content hover widget
|
||||
return this.startFindDefinition(position).then(() => {
|
||||
|
||||
await this.startFindDefinition(position);
|
||||
// Add listeners for editor cursor move and key down events
|
||||
// Dismiss the "extended" editor decorations when the user hides
|
||||
// the hover widget. There is no event for the widget itself so these
|
||||
|
@ -100,7 +100,6 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri
|
|||
this.removeLinkDecorations();
|
||||
this.toUnhookForKeyboard.clear();
|
||||
}));
|
||||
|
||||
this.toUnhookForKeyboard.add(this.editor.onKeyDown((e: IKeyboardEvent) => {
|
||||
if (e) {
|
||||
this.currentWordAtPosition = null;
|
||||
|
@ -108,7 +107,6 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri
|
|||
this.toUnhookForKeyboard.clear();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private startFindDefinitionFromMouse(mouseEvent: ClickLinkMouseEvent, withKey?: ClickLinkKeyboardEvent): void {
|
||||
|
@ -129,7 +127,7 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri
|
|||
this.startFindDefinition(position);
|
||||
}
|
||||
|
||||
private startFindDefinition(position: Position): Promise<number | undefined> {
|
||||
private async startFindDefinition(position: Position): Promise<void> {
|
||||
|
||||
// Dispose listeners for updating decorations when using keyboard to show definition hover
|
||||
this.toUnhookForKeyboard.clear();
|
||||
|
@ -139,12 +137,12 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri
|
|||
if (!word) {
|
||||
this.currentWordAtPosition = null;
|
||||
this.removeLinkDecorations();
|
||||
return Promise.resolve(0);
|
||||
return;
|
||||
}
|
||||
|
||||
// Return early if word at position is still the same
|
||||
if (this.currentWordAtPosition && this.currentWordAtPosition.startColumn === word.startColumn && this.currentWordAtPosition.endColumn === word.endColumn && this.currentWordAtPosition.word === word.word) {
|
||||
return Promise.resolve(0);
|
||||
return;
|
||||
}
|
||||
|
||||
this.currentWordAtPosition = word;
|
||||
|
@ -159,7 +157,15 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri
|
|||
|
||||
this.previousPromise = createCancelablePromise(token => this.findDefinition(position, token));
|
||||
|
||||
return this.previousPromise.then(results => {
|
||||
let results: LocationLink[] | null;
|
||||
try {
|
||||
results = await this.previousPromise;
|
||||
|
||||
} catch (error) {
|
||||
onUnexpectedError(error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!results || !results.length || !state.validate(this.editor)) {
|
||||
this.removeLinkDecorations();
|
||||
return;
|
||||
|
@ -183,10 +189,8 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri
|
|||
combinedRange,
|
||||
new MarkdownString().appendText(nls.localize('multipleResults', "Click to show {0} definitions.", results.length))
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Single result
|
||||
else {
|
||||
const result = results[0];
|
||||
|
||||
if (!result.uri) {
|
||||
|
@ -218,7 +222,6 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri
|
|||
ref.dispose();
|
||||
});
|
||||
}
|
||||
}).then(undefined, onUnexpectedError);
|
||||
}
|
||||
|
||||
private getPreviewValue(textEditorModel: ITextModel, startLineNumber: number, result: LocationLink) {
|
||||
|
@ -314,6 +317,7 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri
|
|||
|
||||
public dispose(): void {
|
||||
this.toUnhook.dispose();
|
||||
this.toUnhookForKeyboard.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue