提交 eae2a774 编写于 作者: A Alex Dima 提交者: Dirk Baeumer

Show correct link hover when links open with Alt

上级 17ea00ea
......@@ -27,15 +27,40 @@ import { Position } from 'vs/editor/common/core/position';
import { ModelDecorationOptions } from "vs/editor/common/model/textModelWithDecorations";
import { ClickLinkGesture, ClickLinkMouseEvent, ClickLinkKeyboardEvent } from "vs/editor/contrib/goToDeclaration/browser/clickLinkGesture";
const HOVER_MESSAGE_GENERAL = (
const HOVER_MESSAGE_GENERAL_META = (
platform.isMacintosh
? nls.localize('links.navigate.mac', "Cmd + click to follow link")
: nls.localize('links.navigate', "Ctrl + click to follow link")
);
const HOVER_MESSAGE_GENERAL_ALT = nls.localize('links.navigate.al', "Alt + click to follow link");
const decoration = {
meta: ModelDecorationOptions.register({
stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
inlineClassName: 'detected-link',
hoverMessage: HOVER_MESSAGE_GENERAL_META
}),
metaActive: ModelDecorationOptions.register({
stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
inlineClassName: 'detected-link-active',
hoverMessage: HOVER_MESSAGE_GENERAL_META
}),
alt: ModelDecorationOptions.register({
stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
inlineClassName: 'detected-link',
hoverMessage: HOVER_MESSAGE_GENERAL_ALT
}),
altActive: ModelDecorationOptions.register({
stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
inlineClassName: 'detected-link-active',
hoverMessage: HOVER_MESSAGE_GENERAL_ALT
}),
};
class LinkOccurence {
public static decoration(link: Link): editorCommon.IModelDeltaDecoration {
public static decoration(link: Link, useMetaKey: boolean): editorCommon.IModelDeltaDecoration {
return {
range: {
startLineNumber: link.range.startLineNumber,
......@@ -43,24 +68,15 @@ class LinkOccurence {
endLineNumber: link.range.endLineNumber,
endColumn: link.range.endColumn
},
options: LinkOccurence._getOptions(false)
options: LinkOccurence._getOptions(useMetaKey, false)
};
}
private static _LINK_DECORATION = ModelDecorationOptions.register({
stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
inlineClassName: 'detected-link',
hoverMessage: HOVER_MESSAGE_GENERAL
});
private static _ACTIVE_LINK_DECORATION = ModelDecorationOptions.register({
stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
inlineClassName: 'detected-link-active',
hoverMessage: HOVER_MESSAGE_GENERAL
});
private static _getOptions(isActive: boolean): ModelDecorationOptions {
return (isActive ? this._ACTIVE_LINK_DECORATION : this._LINK_DECORATION);
private static _getOptions(useMetaKey: boolean, isActive: boolean): ModelDecorationOptions {
if (useMetaKey) {
return (isActive ? decoration.metaActive : decoration.meta);
}
return (isActive ? decoration.altActive : decoration.alt);
}
public decorationId: string;
......@@ -71,12 +87,12 @@ class LinkOccurence {
this.decorationId = decorationId;
}
public activate(changeAccessor: editorCommon.IModelDecorationsChangeAccessor): void {
changeAccessor.changeDecorationOptions(this.decorationId, LinkOccurence._getOptions(true));
public activate(changeAccessor: editorCommon.IModelDecorationsChangeAccessor, useMetaKey: boolean): void {
changeAccessor.changeDecorationOptions(this.decorationId, LinkOccurence._getOptions(useMetaKey, true));
}
public deactivate(changeAccessor: editorCommon.IModelDecorationsChangeAccessor): void {
changeAccessor.changeDecorationOptions(this.decorationId, LinkOccurence._getOptions(false));
public deactivate(changeAccessor: editorCommon.IModelDecorationsChangeAccessor, useMetaKey: boolean): void {
changeAccessor.changeDecorationOptions(this.decorationId, LinkOccurence._getOptions(useMetaKey, false));
}
}
......@@ -183,6 +199,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
}
private updateDecorations(links: Link[]): void {
const useMetaKey = (this.editor.getConfiguration().multicursorModifier === 'altKey');
this.editor.changeDecorations((changeAccessor: editorCommon.IModelDecorationsChangeAccessor) => {
var oldDecorations: string[] = [];
let keys = Object.keys(this.currentOccurences);
......@@ -196,7 +213,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
if (links) {
// Not sure why this is sometimes null
for (var i = 0; i < links.length; i++) {
newDecorations.push(LinkOccurence.decoration(links[i]));
newDecorations.push(LinkOccurence.decoration(links[i], useMetaKey));
}
}
......@@ -212,12 +229,13 @@ class LinkDetector implements editorCommon.IEditorContribution {
}
private _onEditorMouseMove(mouseEvent: ClickLinkMouseEvent, withKey?: ClickLinkKeyboardEvent): void {
const useMetaKey = (this.editor.getConfiguration().multicursorModifier === 'altKey');
if (this.isEnabled(mouseEvent, withKey)) {
this.cleanUpActiveLinkDecoration(); // always remove previous link decoration as their can only be one
var occurence = this.getLinkOccurence(mouseEvent.target.position);
if (occurence) {
this.editor.changeDecorations((changeAccessor) => {
occurence.activate(changeAccessor);
occurence.activate(changeAccessor, useMetaKey);
this.activeLinkDecorationId = occurence.decorationId;
});
}
......@@ -227,11 +245,12 @@ class LinkDetector implements editorCommon.IEditorContribution {
}
private cleanUpActiveLinkDecoration(): void {
const useMetaKey = (this.editor.getConfiguration().multicursorModifier === 'altKey');
if (this.activeLinkDecorationId) {
var occurence = this.currentOccurences[this.activeLinkDecorationId];
if (occurence) {
this.editor.changeDecorations((changeAccessor) => {
occurence.deactivate(changeAccessor);
occurence.deactivate(changeAccessor, useMetaKey);
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册