mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-11 14:04:49 -05:00
Towards simplifying MouseTargetFactory
This commit is contained in:
@@ -453,23 +453,23 @@ class MouseDownOperation extends Disposable {
|
||||
|
||||
let mouseColumn = this._getMouseColumn(e);
|
||||
|
||||
if (e.posy < editorContent.top) {
|
||||
let aboveLineNumber = this._viewHelper.getLineNumberAtVerticalOffset(Math.max(this._viewHelper.getScrollTop() - (editorContent.top - e.posy), 0));
|
||||
if (e.posy < editorContent.y) {
|
||||
let aboveLineNumber = this._viewHelper.getLineNumberAtVerticalOffset(Math.max(this._viewHelper.getScrollTop() - (editorContent.y - e.posy), 0));
|
||||
return new MousePosition(new Position(aboveLineNumber, 1), mouseColumn);
|
||||
}
|
||||
|
||||
if (e.posy > editorContent.top + editorContent.height) {
|
||||
let belowLineNumber = this._viewHelper.getLineNumberAtVerticalOffset(this._viewHelper.getScrollTop() + (e.posy - editorContent.top));
|
||||
if (e.posy > editorContent.y + editorContent.height) {
|
||||
let belowLineNumber = this._viewHelper.getLineNumberAtVerticalOffset(this._viewHelper.getScrollTop() + (e.posy - editorContent.y));
|
||||
return new MousePosition(new Position(belowLineNumber, this._context.model.getLineMaxColumn(belowLineNumber)), mouseColumn);
|
||||
}
|
||||
|
||||
let possibleLineNumber = this._viewHelper.getLineNumberAtVerticalOffset(this._viewHelper.getScrollTop() + (e.posy - editorContent.top));
|
||||
let possibleLineNumber = this._viewHelper.getLineNumberAtVerticalOffset(this._viewHelper.getScrollTop() + (e.posy - editorContent.y));
|
||||
|
||||
if (e.posx < editorContent.left) {
|
||||
if (e.posx < editorContent.x) {
|
||||
return new MousePosition(new Position(possibleLineNumber, 1), mouseColumn);
|
||||
}
|
||||
|
||||
if (e.posx > editorContent.left + editorContent.width) {
|
||||
if (e.posx > editorContent.x + editorContent.width) {
|
||||
return new MousePosition(new Position(possibleLineNumber, this._context.model.getLineMaxColumn(possibleLineNumber)), mouseColumn);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,27 +9,81 @@ import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
|
||||
import * as dom from 'vs/base/browser/dom';
|
||||
import { GlobalMouseMoveMonitor } from 'vs/base/browser/globalMouseMoveMonitor';
|
||||
|
||||
/**
|
||||
* Coordinates relative to the whole document (e.g. mouse event's pageX and pageY)
|
||||
*/
|
||||
export class PageCoordinates {
|
||||
_pageCoordinatesBrand: void;
|
||||
public readonly x: number;
|
||||
public readonly y: number;
|
||||
|
||||
constructor(x: number, y: number) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public toClientCoordinates(): ClientCoordinates {
|
||||
return new ClientCoordinates(this.x - dom.StandardWindow.scrollX, this.y - dom.StandardWindow.scrollY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Coordinates within the application's client area (i.e. origin is document's scroll position).
|
||||
*
|
||||
* For example, clicking in the top-left corner of the client area will
|
||||
* always result in a mouse event with a client.x value of 0, regardless
|
||||
* of whether the page is scrolled horizontally.
|
||||
*/
|
||||
export class ClientCoordinates {
|
||||
_clientCoordinatesBrand: void;
|
||||
|
||||
public readonly clientX: number;
|
||||
public readonly clientY: number;
|
||||
|
||||
constructor(clientX: number, clientY: number) {
|
||||
this.clientX = clientX;
|
||||
this.clientY = clientY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The position of the editor in the page.
|
||||
*/
|
||||
export class EditorPagePosition {
|
||||
_editorPagePositionBrand: void;
|
||||
|
||||
public readonly x: number;
|
||||
public readonly y: number;
|
||||
public readonly width: number;
|
||||
public readonly height: number;
|
||||
|
||||
constructor(x: number, y: number, width: number, height: number) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
export class EditorMouseEvent extends StandardMouseEvent {
|
||||
_editorMouseEventBrand: void;
|
||||
|
||||
editorPos: dom.IDomNodePagePosition;
|
||||
/**
|
||||
* Coordinates relative to the whole document.
|
||||
*/
|
||||
public readonly page: PageCoordinates;
|
||||
|
||||
/**
|
||||
* The horizontal position of the cursor relative to the viewport (i.e. scrolled).
|
||||
* Editor's coordinates relative to the whole document.
|
||||
*/
|
||||
viewportx: number;
|
||||
|
||||
/**
|
||||
* The vertical position of the cursor relative to the viewport (i.e. scrolled).
|
||||
*/
|
||||
viewporty: number;
|
||||
public readonly editorPos: EditorPagePosition;
|
||||
|
||||
constructor(e: MouseEvent, editorViewDomNode: HTMLElement) {
|
||||
super(e);
|
||||
this.editorPos = dom.getDomNodePagePosition(editorViewDomNode);
|
||||
this.page = new PageCoordinates(this.posx, this.posy);
|
||||
|
||||
this.viewportx = this.posx - dom.StandardWindow.scrollX;
|
||||
this.viewporty = this.posy - dom.StandardWindow.scrollY;
|
||||
let editorPos = dom.getDomNodePagePosition(editorViewDomNode);
|
||||
this.editorPos = new EditorPagePosition(editorPos.left, editorPos.top, editorPos.width, editorPos.height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user