Merge remote-tracking branch 'upstream/master' into typedarray_parser
This commit is contained in:
@@ -347,7 +347,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
|
|||||||
* @param event The mouse event.
|
* @param event The mouse event.
|
||||||
*/
|
*/
|
||||||
private _getMouseBufferCoords(event: MouseEvent): [number, number] {
|
private _getMouseBufferCoords(event: MouseEvent): [number, number] {
|
||||||
const coords = this._terminal.mouseHelper.getCoords(event, this._terminal.screenElement, this._charMeasure, this._terminal.options.lineHeight, this._terminal.cols, this._terminal.rows, true);
|
const coords = this._terminal.mouseHelper.getCoords(event, this._terminal.screenElement, this._charMeasure, this._terminal.cols, this._terminal.rows, true);
|
||||||
if (!coords) {
|
if (!coords) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -807,7 +807,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
|||||||
button = getButton(ev);
|
button = getButton(ev);
|
||||||
|
|
||||||
// get mouse coordinates
|
// get mouse coordinates
|
||||||
pos = self.mouseHelper.getRawByteCoords(ev, self.screenElement, self.charMeasure, self.options.lineHeight, self.cols, self.rows);
|
pos = self.mouseHelper.getRawByteCoords(ev, self.screenElement, self.charMeasure, self.cols, self.rows);
|
||||||
if (!pos) return;
|
if (!pos) return;
|
||||||
|
|
||||||
sendEvent(button, pos);
|
sendEvent(button, pos);
|
||||||
@@ -833,7 +833,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
|||||||
// ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<
|
// ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<
|
||||||
function sendMove(ev: MouseEvent): void {
|
function sendMove(ev: MouseEvent): void {
|
||||||
let button = pressed;
|
let button = pressed;
|
||||||
const pos = self.mouseHelper.getRawByteCoords(ev, self.screenElement, self.charMeasure, self.options.lineHeight, self.cols, self.rows);
|
const pos = self.mouseHelper.getRawByteCoords(ev, self.screenElement, self.charMeasure, self.cols, self.rows);
|
||||||
if (!pos) return;
|
if (!pos) return;
|
||||||
|
|
||||||
// buttons marked as motions
|
// buttons marked as motions
|
||||||
|
|||||||
+2
-2
@@ -245,8 +245,8 @@ export interface ILinkifierAccessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IMouseHelper {
|
export interface IMouseHelper {
|
||||||
getCoords(event: { pageX: number, pageY: number }, element: HTMLElement, charMeasure: ICharMeasure, lineHeight: number, colCount: number, rowCount: number, isSelection?: boolean): [number, number];
|
getCoords(event: { pageX: number, pageY: number }, element: HTMLElement, charMeasure: ICharMeasure, colCount: number, rowCount: number, isSelection?: boolean): [number, number];
|
||||||
getRawByteCoords(event: MouseEvent, element: HTMLElement, charMeasure: ICharMeasure, lineHeight: number, colCount: number, rowCount: number): { x: number, y: number };
|
getRawByteCoords(event: MouseEvent, element: HTMLElement, charMeasure: ICharMeasure, colCount: number, rowCount: number): { x: number, y: number };
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICharMeasure {
|
export interface ICharMeasure {
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ export class AltClickHandler {
|
|||||||
this._mouseEvent,
|
this._mouseEvent,
|
||||||
this._terminal.element,
|
this._terminal.element,
|
||||||
this._terminal.charMeasure,
|
this._terminal.charMeasure,
|
||||||
this._terminal.options.lineHeight,
|
|
||||||
this._terminal.cols,
|
this._terminal.cols,
|
||||||
this._terminal.rows,
|
this._terminal.rows,
|
||||||
false
|
false
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ export class MouseZoneManager extends Disposable implements IMouseZoneManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _findZoneEventAt(e: MouseEvent): IMouseZone {
|
private _findZoneEventAt(e: MouseEvent): IMouseZone {
|
||||||
const coords = this._terminal.mouseHelper.getCoords(e, this._terminal.screenElement, this._terminal.charMeasure, this._terminal.options.lineHeight, this._terminal.cols, this._terminal.rows);
|
const coords = this._terminal.mouseHelper.getCoords(e, this._terminal.screenElement, this._terminal.charMeasure, this._terminal.cols, this._terminal.rows);
|
||||||
if (!coords) {
|
if (!coords) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,34 +37,34 @@ describe('MouseHelper.getCoords', () => {
|
|||||||
describe('when charMeasure is not initialized', () => {
|
describe('when charMeasure is not initialized', () => {
|
||||||
it('should return null', () => {
|
it('should return null', () => {
|
||||||
charMeasure = new MockCharMeasure();
|
charMeasure = new MockCharMeasure();
|
||||||
assert.equal(mouseHelper.getCoords({ pageX: 0, pageY: 0 }, document.createElement('div'), charMeasure, 1, 10, 10), null);
|
assert.equal(mouseHelper.getCoords({ pageX: 0, pageY: 0 }, document.createElement('div'), charMeasure, 10, 10), null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when pageX/pageY are not supported', () => {
|
describe('when pageX/pageY are not supported', () => {
|
||||||
it('should return null', () => {
|
it('should return null', () => {
|
||||||
assert.equal(mouseHelper.getCoords({ pageX: undefined, pageY: undefined }, document.createElement('div'), charMeasure, 1, 10, 10), null);
|
assert.equal(mouseHelper.getCoords({ pageX: undefined, pageY: undefined }, document.createElement('div'), charMeasure, 10, 10), null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the cell that was clicked', () => {
|
it('should return the cell that was clicked', () => {
|
||||||
let coords: [number, number];
|
let coords: [number, number];
|
||||||
coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH / 2, pageY: CHAR_HEIGHT / 2 }, document.createElement('div'), charMeasure, 1, 10, 10);
|
coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH / 2, pageY: CHAR_HEIGHT / 2 }, document.createElement('div'), charMeasure, 10, 10);
|
||||||
assert.deepEqual(coords, [1, 1]);
|
assert.deepEqual(coords, [1, 1]);
|
||||||
coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH, pageY: CHAR_HEIGHT }, document.createElement('div'), charMeasure, 1, 10, 10);
|
coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH, pageY: CHAR_HEIGHT }, document.createElement('div'), charMeasure, 10, 10);
|
||||||
assert.deepEqual(coords, [1, 1]);
|
assert.deepEqual(coords, [1, 1]);
|
||||||
coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH, pageY: CHAR_HEIGHT + 1 }, document.createElement('div'), charMeasure, 1, 10, 10);
|
coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH, pageY: CHAR_HEIGHT + 1 }, document.createElement('div'), charMeasure, 10, 10);
|
||||||
assert.deepEqual(coords, [1, 2]);
|
assert.deepEqual(coords, [1, 2]);
|
||||||
coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH + 1, pageY: CHAR_HEIGHT }, document.createElement('div'), charMeasure, 1, 10, 10);
|
coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH + 1, pageY: CHAR_HEIGHT }, document.createElement('div'), charMeasure, 10, 10);
|
||||||
assert.deepEqual(coords, [2, 1]);
|
assert.deepEqual(coords, [2, 1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should ensure the coordinates are returned within the terminal bounds', () => {
|
it('should ensure the coordinates are returned within the terminal bounds', () => {
|
||||||
let coords: [number, number];
|
let coords: [number, number];
|
||||||
coords = mouseHelper.getCoords({ pageX: -1, pageY: -1 }, document.createElement('div'), charMeasure, 1, 10, 10);
|
coords = mouseHelper.getCoords({ pageX: -1, pageY: -1 }, document.createElement('div'), charMeasure, 10, 10);
|
||||||
assert.deepEqual(coords, [1, 1]);
|
assert.deepEqual(coords, [1, 1]);
|
||||||
// Event are double the cols/rows
|
// Event are double the cols/rows
|
||||||
coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH * 20, pageY: CHAR_HEIGHT * 20 }, document.createElement('div'), charMeasure, 1, 10, 10);
|
coords = mouseHelper.getCoords({ pageX: CHAR_WIDTH * 20, pageY: CHAR_HEIGHT * 20 }, document.createElement('div'), charMeasure, 10, 10);
|
||||||
assert.deepEqual(coords, [10, 10], 'coordinates should never come back as larger than the terminal');
|
assert.deepEqual(coords, [10, 10], 'coordinates should never come back as larger than the terminal');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export class MouseHelper {
|
|||||||
* 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: {pageX: number, pageY: number}, element: HTMLElement, charMeasure: ICharMeasure, lineHeight: number, colCount: number, rowCount: number, isSelection?: boolean): [number, number] {
|
public getCoords(event: {pageX: number, pageY: number}, element: HTMLElement, charMeasure: ICharMeasure, colCount: number, rowCount: number, isSelection?: boolean): [number, number] {
|
||||||
// Coordinates cannot be measured if charMeasure has not been initialized
|
// Coordinates cannot be measured if charMeasure has not been initialized
|
||||||
if (!charMeasure.width || !charMeasure.height) {
|
if (!charMeasure.width || !charMeasure.height) {
|
||||||
return null;
|
return null;
|
||||||
@@ -85,8 +85,8 @@ export class MouseHelper {
|
|||||||
* @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, charMeasure: ICharMeasure, lineHeight: number, colCount: number, rowCount: number): { x: number, y: number } {
|
public getRawByteCoords(event: MouseEvent, element: HTMLElement, charMeasure: ICharMeasure, colCount: number, rowCount: number): { x: number, y: number } {
|
||||||
const coords = this.getCoords(event, element, charMeasure, lineHeight, colCount, rowCount);
|
const coords = this.getCoords(event, element, charMeasure, colCount, rowCount);
|
||||||
let x = coords[0];
|
let x = coords[0];
|
||||||
let y = coords[1];
|
let y = coords[1];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user