mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-04-01 17:40:30 -04:00
Merge from master
This commit is contained in:
@@ -3,28 +3,27 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import 'vs/css!./links';
|
||||
import * as nls from 'vs/nls';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { registerEditorAction, registerEditorContribution, ServicesAccessor, EditorAction } from 'vs/editor/browser/editorExtensions';
|
||||
import { LinkProviderRegistry } from 'vs/editor/common/modes';
|
||||
import { ICodeEditor, MouseTargetType } from 'vs/editor/browser/editorBrowser';
|
||||
import { getLinks, Link } from 'vs/editor/contrib/links/getLinks';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
|
||||
import { editorActiveLinkForeground } from 'vs/platform/theme/common/colorRegistry';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
|
||||
import { ClickLinkGesture, ClickLinkMouseEvent, ClickLinkKeyboardEvent } from 'vs/editor/contrib/goToDefinition/clickLinkGesture';
|
||||
import { MarkdownString } from 'vs/base/common/htmlContent';
|
||||
import { TrackedRangeStickiness, IModelDeltaDecoration, IModelDecorationsChangeAccessor } from 'vs/editor/common/model';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import * as async from 'vs/base/common/async';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { MarkdownString } from 'vs/base/common/htmlContent';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import { ICodeEditor, MouseTargetType } from 'vs/editor/browser/editorBrowser';
|
||||
import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { IModelDecorationsChangeAccessor, IModelDeltaDecoration, TrackedRangeStickiness } from 'vs/editor/common/model';
|
||||
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
|
||||
import { LinkProviderRegistry } from 'vs/editor/common/modes';
|
||||
import { ClickLinkGesture, ClickLinkKeyboardEvent, ClickLinkMouseEvent } from 'vs/editor/contrib/goToDefinition/clickLinkGesture';
|
||||
import { Link, getLinks } from 'vs/editor/contrib/links/getLinks';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
import { editorActiveLinkForeground } from 'vs/platform/theme/common/colorRegistry';
|
||||
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
|
||||
|
||||
const HOVER_MESSAGE_GENERAL_META = new MarkdownString().appendText(
|
||||
platform.isMacintosh
|
||||
@@ -53,41 +52,49 @@ const HOVER_MESSAGE_COMMAND_ALT = new MarkdownString().appendText(
|
||||
const decoration = {
|
||||
meta: ModelDecorationOptions.register({
|
||||
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
||||
collapseOnReplaceEdit: true,
|
||||
inlineClassName: 'detected-link',
|
||||
hoverMessage: HOVER_MESSAGE_GENERAL_META
|
||||
}),
|
||||
metaActive: ModelDecorationOptions.register({
|
||||
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
||||
collapseOnReplaceEdit: true,
|
||||
inlineClassName: 'detected-link-active',
|
||||
hoverMessage: HOVER_MESSAGE_GENERAL_META
|
||||
}),
|
||||
alt: ModelDecorationOptions.register({
|
||||
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
||||
collapseOnReplaceEdit: true,
|
||||
inlineClassName: 'detected-link',
|
||||
hoverMessage: HOVER_MESSAGE_GENERAL_ALT
|
||||
}),
|
||||
altActive: ModelDecorationOptions.register({
|
||||
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
||||
collapseOnReplaceEdit: true,
|
||||
inlineClassName: 'detected-link-active',
|
||||
hoverMessage: HOVER_MESSAGE_GENERAL_ALT
|
||||
}),
|
||||
altCommand: ModelDecorationOptions.register({
|
||||
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
||||
collapseOnReplaceEdit: true,
|
||||
inlineClassName: 'detected-link',
|
||||
hoverMessage: HOVER_MESSAGE_COMMAND_ALT
|
||||
}),
|
||||
altCommandActive: ModelDecorationOptions.register({
|
||||
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
||||
collapseOnReplaceEdit: true,
|
||||
inlineClassName: 'detected-link-active',
|
||||
hoverMessage: HOVER_MESSAGE_COMMAND_ALT
|
||||
}),
|
||||
metaCommand: ModelDecorationOptions.register({
|
||||
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
||||
collapseOnReplaceEdit: true,
|
||||
inlineClassName: 'detected-link',
|
||||
hoverMessage: HOVER_MESSAGE_COMMAND_META
|
||||
}),
|
||||
metaCommandActive: ModelDecorationOptions.register({
|
||||
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
||||
collapseOnReplaceEdit: true,
|
||||
inlineClassName: 'detected-link-active',
|
||||
hoverMessage: HOVER_MESSAGE_COMMAND_META
|
||||
}),
|
||||
@@ -104,7 +111,7 @@ class LinkOccurrence {
|
||||
}
|
||||
|
||||
private static _getOptions(link: Link, useMetaKey: boolean, isActive: boolean): ModelDecorationOptions {
|
||||
if (/^command:/i.test(link.url)) {
|
||||
if (link.url && /^command:/i.test(link.url)) {
|
||||
if (useMetaKey) {
|
||||
return (isActive ? decoration.metaCommandActive : decoration.metaCommand);
|
||||
} else {
|
||||
@@ -150,8 +157,8 @@ class LinkDetector implements editorCommon.IEditorContribution {
|
||||
private enabled: boolean;
|
||||
private listenersToRemove: IDisposable[];
|
||||
private timeout: async.TimeoutTimer;
|
||||
private computePromise: async.CancelablePromise<Link[]>;
|
||||
private activeLinkDecorationId: string;
|
||||
private computePromise: async.CancelablePromise<Link[]> | null;
|
||||
private activeLinkDecorationId: string | null;
|
||||
private openerService: IOpenerService;
|
||||
private notificationService: INotificationService;
|
||||
private currentOccurrences: { [decorationId: string]: LinkOccurrence; };
|
||||
@@ -229,15 +236,17 @@ class LinkDetector implements editorCommon.IEditorContribution {
|
||||
}
|
||||
|
||||
private async beginCompute(): Promise<void> {
|
||||
if (!this.editor.getModel() || !this.enabled) {
|
||||
if (!this.editor.hasModel() || !this.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!LinkProviderRegistry.has(this.editor.getModel())) {
|
||||
const model = this.editor.getModel();
|
||||
|
||||
if (!LinkProviderRegistry.has(model)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.computePromise = async.createCancelablePromise(token => getLinks(this.editor.getModel(), token));
|
||||
this.computePromise = async.createCancelablePromise(token => getLinks(model, token));
|
||||
try {
|
||||
const links = await this.computePromise;
|
||||
this.updateDecorations(links);
|
||||
@@ -276,7 +285,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
|
||||
}
|
||||
}
|
||||
|
||||
private _onEditorMouseMove(mouseEvent: ClickLinkMouseEvent, withKey?: ClickLinkKeyboardEvent): void {
|
||||
private _onEditorMouseMove(mouseEvent: ClickLinkMouseEvent, withKey: ClickLinkKeyboardEvent | null): 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
|
||||
@@ -325,7 +334,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
|
||||
|
||||
const { link } = occurrence;
|
||||
|
||||
link.resolve().then(uri => {
|
||||
link.resolve(CancellationToken.None).then(uri => {
|
||||
// open the uri
|
||||
return this.openerService.open(uri, { openToSide });
|
||||
|
||||
@@ -338,10 +347,13 @@ class LinkDetector implements editorCommon.IEditorContribution {
|
||||
} else {
|
||||
onUnexpectedError(err);
|
||||
}
|
||||
}).done(null, onUnexpectedError);
|
||||
});
|
||||
}
|
||||
|
||||
public getLinkOccurrence(position: Position): LinkOccurrence {
|
||||
public getLinkOccurrence(position: Position | null): LinkOccurrence | null {
|
||||
if (!this.editor.hasModel() || !position) {
|
||||
return null;
|
||||
}
|
||||
const decorations = this.editor.getModel().getDecorationsInRange({
|
||||
startLineNumber: position.lineNumber,
|
||||
startColumn: position.column,
|
||||
@@ -360,9 +372,9 @@ class LinkDetector implements editorCommon.IEditorContribution {
|
||||
return null;
|
||||
}
|
||||
|
||||
private isEnabled(mouseEvent: ClickLinkMouseEvent, withKey?: ClickLinkKeyboardEvent): boolean {
|
||||
return (
|
||||
mouseEvent.target.type === MouseTargetType.CONTENT_TEXT
|
||||
private isEnabled(mouseEvent: ClickLinkMouseEvent, withKey?: ClickLinkKeyboardEvent | null): boolean {
|
||||
return Boolean(
|
||||
(mouseEvent.target.type === MouseTargetType.CONTENT_TEXT)
|
||||
&& (mouseEvent.hasTriggerModifier || (withKey && withKey.keyCodeIsTriggerKey))
|
||||
);
|
||||
}
|
||||
@@ -398,6 +410,9 @@ class OpenLinkAction extends EditorAction {
|
||||
if (!linkDetector) {
|
||||
return;
|
||||
}
|
||||
if (!editor.hasModel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let selections = editor.getSelections();
|
||||
|
||||
@@ -415,7 +430,7 @@ registerEditorContribution(LinkDetector);
|
||||
registerEditorAction(OpenLinkAction);
|
||||
|
||||
registerThemingParticipant((theme, collector) => {
|
||||
let activeLinkForeground = theme.getColor(editorActiveLinkForeground);
|
||||
const activeLinkForeground = theme.getColor(editorActiveLinkForeground);
|
||||
if (activeLinkForeground) {
|
||||
collector.addRule(`.monaco-editor .detected-link-active { color: ${activeLinkForeground} !important; }`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user