diff --git a/src/vs/editor/browser/controller/mouseTarget.ts b/src/vs/editor/browser/controller/mouseTarget.ts index c1fefa4ce52..cf96a22b934 100644 --- a/src/vs/editor/browser/controller/mouseTarget.ts +++ b/src/vs/editor/browser/controller/mouseTarget.ts @@ -66,7 +66,7 @@ interface IHitTestResult { hitTarget: Element; } -class MouseTarget implements IMouseTarget { +export class MouseTarget implements IMouseTarget { public readonly element: Element; public readonly type: MouseTargetType; @@ -87,48 +87,52 @@ class MouseTarget implements IMouseTarget { this.detail = detail; } - private _typeToString(): string { - if (this.type === MouseTargetType.TEXTAREA) { + private static _typeToString(type: MouseTargetType): string { + if (type === MouseTargetType.TEXTAREA) { return 'TEXTAREA'; } - if (this.type === MouseTargetType.GUTTER_GLYPH_MARGIN) { + if (type === MouseTargetType.GUTTER_GLYPH_MARGIN) { return 'GUTTER_GLYPH_MARGIN'; } - if (this.type === MouseTargetType.GUTTER_LINE_NUMBERS) { + if (type === MouseTargetType.GUTTER_LINE_NUMBERS) { return 'GUTTER_LINE_NUMBERS'; } - if (this.type === MouseTargetType.GUTTER_LINE_DECORATIONS) { + if (type === MouseTargetType.GUTTER_LINE_DECORATIONS) { return 'GUTTER_LINE_DECORATIONS'; } - if (this.type === MouseTargetType.GUTTER_VIEW_ZONE) { + if (type === MouseTargetType.GUTTER_VIEW_ZONE) { return 'GUTTER_VIEW_ZONE'; } - if (this.type === MouseTargetType.CONTENT_TEXT) { + if (type === MouseTargetType.CONTENT_TEXT) { return 'CONTENT_TEXT'; } - if (this.type === MouseTargetType.CONTENT_EMPTY) { + if (type === MouseTargetType.CONTENT_EMPTY) { return 'CONTENT_EMPTY'; } - if (this.type === MouseTargetType.CONTENT_VIEW_ZONE) { + if (type === MouseTargetType.CONTENT_VIEW_ZONE) { return 'CONTENT_VIEW_ZONE'; } - if (this.type === MouseTargetType.CONTENT_WIDGET) { + if (type === MouseTargetType.CONTENT_WIDGET) { return 'CONTENT_WIDGET'; } - if (this.type === MouseTargetType.OVERVIEW_RULER) { + if (type === MouseTargetType.OVERVIEW_RULER) { return 'OVERVIEW_RULER'; } - if (this.type === MouseTargetType.SCROLLBAR) { + if (type === MouseTargetType.SCROLLBAR) { return 'SCROLLBAR'; } - if (this.type === MouseTargetType.OVERLAY_WIDGET) { + if (type === MouseTargetType.OVERLAY_WIDGET) { return 'OVERLAY_WIDGET'; } return 'UNKNOWN'; } + public static toString(target: IMouseTarget): string { + return this._typeToString(target.type) + ': ' + target.position + ' - ' + target.range + ' - ' + target.detail; + } + public toString(): string { - return this._typeToString() + ': ' + this.position + ' - ' + this.range + ' - ' + this.detail; + return MouseTarget.toString(this); } } diff --git a/src/vs/editor/browser/view/viewOutgoingEvents.ts b/src/vs/editor/browser/view/viewOutgoingEvents.ts index 4c1457190d5..16ce702ebc5 100644 --- a/src/vs/editor/browser/view/viewOutgoingEvents.ts +++ b/src/vs/editor/browser/view/viewOutgoingEvents.ts @@ -10,8 +10,9 @@ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; import { IViewModel } from 'vs/editor/common/viewModel/viewModel'; -import { EventType, EditorLayoutInfo, IScrollEvent } from 'vs/editor/common/editorCommon'; +import { EventType, EditorLayoutInfo, IScrollEvent, MouseTargetType } from 'vs/editor/common/editorCommon'; import { IEditorMouseEvent, IMouseTarget } from 'vs/editor/browser/editorBrowser'; +import { MouseTarget } from 'vs/editor/browser/controller/mouseTarget'; export class ViewOutgoingEvents extends Disposable { @@ -87,14 +88,14 @@ export class ViewOutgoingEvents extends Disposable { } private _convertViewToModelMouseTarget(target: IMouseTarget): IMouseTarget { - return { - element: target.element, - type: target.type, - position: target.position ? this._convertViewToModelPosition(target.position) : null, - mouseColumn: target.mouseColumn, - range: target.range ? this._convertViewToModelRange(target.range) : null, - detail: target.detail - }; + return new ExternalMouseTarget( + target.element, + target.type, + target.mouseColumn, + target.position ? this._convertViewToModelPosition(target.position) : null, + target.range ? this._convertViewToModelRange(target.range) : null, + target.detail + ); } private _convertViewToModelPosition(viewPosition: Position): Position { @@ -105,3 +106,26 @@ export class ViewOutgoingEvents extends Disposable { return this._viewModel.convertViewRangeToModelRange(viewRange); } } + +class ExternalMouseTarget implements IMouseTarget { + + public readonly element: Element; + public readonly type: MouseTargetType; + public readonly mouseColumn: number; + public readonly position: Position; + public readonly range: Range; + public readonly detail: any; + + constructor(element: Element, type: MouseTargetType, mouseColumn: number, position: Position, range: Range, detail: any) { + this.element = element; + this.type = type; + this.mouseColumn = mouseColumn; + this.position = position; + this.range = range; + this.detail = detail; + } + + public toString(): string { + return MouseTarget.toString(this); + } +}