Move MouseHelper into browser
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import jsdom = require('jsdom');
|
import jsdom = require('jsdom');
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import { MouseHelper } from './MouseHelper';
|
import { MouseHelper } from './browser/input/MouseHelper';
|
||||||
import { MockRenderer, MockCharSizeService } from './TestUtils.test';
|
import { MockRenderer, MockCharSizeService } from './TestUtils.test';
|
||||||
|
|
||||||
const CHAR_WIDTH = 10;
|
const CHAR_WIDTH = 10;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import { ITerminal, ISelectionManager, ISelectionRedrawRequestEvent } from './Types';
|
import { ITerminal, ISelectionManager, ISelectionRedrawRequestEvent } from './Types';
|
||||||
import { IBuffer } from 'common/buffer/Types';
|
import { IBuffer } from 'common/buffer/Types';
|
||||||
import { IBufferLine } from 'common/Types';
|
import { IBufferLine } from 'common/Types';
|
||||||
import { MouseHelper } from './MouseHelper';
|
import { MouseHelper } from './browser/input/MouseHelper';
|
||||||
import * as Browser from 'common/Platform';
|
import * as Browser from 'common/Platform';
|
||||||
import { SelectionModel } from './SelectionModel';
|
import { SelectionModel } from './SelectionModel';
|
||||||
import { AltClickHandler } from './handlers/AltClickHandler';
|
import { AltClickHandler } from './handlers/AltClickHandler';
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ import { SelectionManager } from './SelectionManager';
|
|||||||
import * as Browser from 'common/Platform';
|
import * as Browser from 'common/Platform';
|
||||||
import { addDisposableDomListener } from 'browser/Lifecycle';
|
import { addDisposableDomListener } from 'browser/Lifecycle';
|
||||||
import * as Strings from './Strings';
|
import * as Strings from './Strings';
|
||||||
import { MouseHelper } from './MouseHelper';
|
import { MouseHelper } from './browser/input/MouseHelper';
|
||||||
import { SoundManager } from './SoundManager';
|
import { SoundManager } from './SoundManager';
|
||||||
import { MouseZoneManager } from './MouseZoneManager';
|
import { MouseZoneManager } from './MouseZoneManager';
|
||||||
import { AccessibilityManager } from './AccessibilityManager';
|
import { AccessibilityManager } from './AccessibilityManager';
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { IRenderer, IRenderDimensions, CharacterJoinerHandler } from 'browser/renderer/Types';
|
import { IRenderer, IRenderDimensions, CharacterJoinerHandler } from 'browser/renderer/Types';
|
||||||
import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminal, IBrowser, ISelectionManager, ITerminalOptions, ILinkifier, IMouseHelper, ILinkMatcherOptions } from './Types';
|
import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminal, IBrowser, ISelectionManager, ITerminalOptions, ILinkifier, ILinkMatcherOptions } from './Types';
|
||||||
import { IBuffer, IBufferStringIterator, IBufferSet } from 'common/buffer/Types';
|
import { IBuffer, IBufferStringIterator, IBufferSet } from 'common/buffer/Types';
|
||||||
import { IBufferLine, ICellData, IAttributeData, ICircularList, XtermListener } from 'common/Types';
|
import { IBufferLine, ICellData, IAttributeData, ICircularList, XtermListener } from 'common/Types';
|
||||||
import { Buffer } from 'common/buffer/Buffer';
|
import { Buffer } from 'common/buffer/Buffer';
|
||||||
@@ -12,7 +12,7 @@ import * as Browser from 'common/Platform';
|
|||||||
import { IDisposable, IMarker, IEvent, ISelectionPosition } from 'xterm';
|
import { IDisposable, IMarker, IEvent, ISelectionPosition } from 'xterm';
|
||||||
import { Terminal } from './Terminal';
|
import { Terminal } from './Terminal';
|
||||||
import { AttributeData } from 'common/buffer/BufferLine';
|
import { AttributeData } from 'common/buffer/BufferLine';
|
||||||
import { IColorManager, IColorSet } from 'browser/Types';
|
import { IColorManager, IColorSet, IMouseHelper } from 'browser/Types';
|
||||||
import { IOptionsService } from 'common/services/Services';
|
import { IOptionsService } from 'common/services/Services';
|
||||||
import { ICharSizeService } from 'browser/services/Services';
|
import { ICharSizeService } from 'browser/services/Services';
|
||||||
|
|
||||||
|
|||||||
+1
-6
@@ -6,7 +6,7 @@
|
|||||||
import { ITerminalOptions as IPublicTerminalOptions, IEventEmitter, IDisposable, IMarker, ISelectionPosition } from 'xterm';
|
import { ITerminalOptions as IPublicTerminalOptions, IEventEmitter, IDisposable, IMarker, ISelectionPosition } from 'xterm';
|
||||||
import { ICharset, IAttributeData, CharData } from 'common/Types';
|
import { ICharset, IAttributeData, CharData } from 'common/Types';
|
||||||
import { IEvent } from 'common/EventEmitter2';
|
import { IEvent } from 'common/EventEmitter2';
|
||||||
import { IColorSet } from 'browser/Types';
|
import { IColorSet, IMouseHelper } from 'browser/Types';
|
||||||
import { IOptionsService } from 'common/services/Services';
|
import { IOptionsService } from 'common/services/Services';
|
||||||
import { IBuffer, IBufferSet } from 'common/buffer/Types';
|
import { IBuffer, IBufferSet } from 'common/buffer/Types';
|
||||||
|
|
||||||
@@ -277,11 +277,6 @@ export interface ILinkifierAccessor {
|
|||||||
linkifier: ILinkifier;
|
linkifier: ILinkifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IMouseHelper {
|
|
||||||
getCoords(event: { clientX: number, clientY: number }, element: HTMLElement, colCount: number, rowCount: number, isSelection?: boolean): [number, number];
|
|
||||||
getRawByteCoords(event: MouseEvent, element: HTMLElement, colCount: number, rowCount: number): { x: number, y: number };
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: The options that are not in the public API should be reviewed
|
// TODO: The options that are not in the public API should be reviewed
|
||||||
export interface ITerminalOptions extends IPublicTerminalOptions {
|
export interface ITerminalOptions extends IPublicTerminalOptions {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
|
|||||||
@@ -20,3 +20,8 @@ export interface IColorSet {
|
|||||||
selection: IColor;
|
selection: IColor;
|
||||||
ansi: IColor[];
|
ansi: IColor[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IMouseHelper {
|
||||||
|
getCoords(event: { clientX: number, clientY: number }, element: HTMLElement, colCount: number, rowCount: number, isSelection?: boolean): [number, number] | undefined;
|
||||||
|
getRawByteCoords(event: MouseEvent, element: HTMLElement, colCount: number, rowCount: number): { x: number | undefined, y: number | undefined };
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IMouseHelper } from './Types';
|
import { IMouseHelper } from 'browser/Types';
|
||||||
import { RenderService } from 'browser/services/RenderService';
|
import { RenderService } from 'browser/services/RenderService';
|
||||||
import { ICharSizeService } from 'browser/services/Services';
|
import { ICharSizeService } from 'browser/services/Services';
|
||||||
|
|
||||||
@@ -31,15 +31,15 @@ export class MouseHelper implements IMouseHelper {
|
|||||||
* apply an offset to the x value such that the left half of the cell will
|
* apply an offset to the x value such that the left half of the cell will
|
||||||
* select that cell and the right half will select the next cell.
|
* select that cell and the right half will select the next cell.
|
||||||
*/
|
*/
|
||||||
public getCoords(event: {clientX: number, clientY: number}, element: HTMLElement, colCount: number, rowCount: number, isSelection?: boolean): [number, number] {
|
public getCoords(event: {clientX: number, clientY: number}, element: HTMLElement, colCount: number, rowCount: number, isSelection?: boolean): [number, number] | undefined {
|
||||||
// Coordinates cannot be measured if there are no valid
|
// Coordinates cannot be measured if there are no valid
|
||||||
if (!this._charSizeService.hasValidSize) {
|
if (!this._charSizeService.hasValidSize) {
|
||||||
return null;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const coords = MouseHelper.getCoordsRelativeToElement(event, element);
|
const coords = MouseHelper.getCoordsRelativeToElement(event, element);
|
||||||
if (!coords) {
|
if (!coords) {
|
||||||
return null;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
coords[0] = Math.ceil((coords[0] + (isSelection ? this._renderService.dimensions.actualCellWidth / 2 : 0)) / this._renderService.dimensions.actualCellWidth);
|
coords[0] = Math.ceil((coords[0] + (isSelection ? this._renderService.dimensions.actualCellWidth / 2 : 0)) / this._renderService.dimensions.actualCellWidth);
|
||||||
@@ -63,14 +63,12 @@ export class MouseHelper implements IMouseHelper {
|
|||||||
* @param colCount The number of columns in the terminal.
|
* @param colCount The number of columns in the terminal.
|
||||||
* @param rowCount The number of rows in the terminal.
|
* @param rowCount The number of rows in the terminal.
|
||||||
*/
|
*/
|
||||||
public getRawByteCoords(event: MouseEvent, element: HTMLElement, colCount: number, rowCount: number): { x: number, y: number } {
|
public getRawByteCoords(event: MouseEvent, element: HTMLElement, colCount: number, rowCount: number): { x: number | undefined, y: number | undefined } {
|
||||||
const coords = this.getCoords(event, element, colCount, rowCount);
|
const coords = this.getCoords(event, element, colCount, rowCount);
|
||||||
let x = coords[0];
|
|
||||||
let y = coords[1];
|
|
||||||
|
|
||||||
// xterm sends raw bytes and starts at 32 (SP) for each.
|
// xterm sends raw bytes and starts at 32 (SP) for each.
|
||||||
x += 32;
|
const x = coords ? coords[0] + 32 : undefined;
|
||||||
y += 32;
|
const y = coords ? coords[1] + 32 : undefined;
|
||||||
|
|
||||||
return { x, y };
|
return { x, y };
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user