mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Polish comments and cap code
This commit is contained in:
+8
-11
@@ -13,7 +13,7 @@ import { CharMeasure } from './CharMeasure';
|
||||
* @param charMeasure The char measure object used to determine character sizes.
|
||||
*/
|
||||
export function getCoords(event: MouseEvent, rowContainer: HTMLElement, charMeasure: CharMeasure): [number, number] {
|
||||
// ignore browsers without pageX for now
|
||||
// Ignore browsers that don't support MouseEvent.pageX
|
||||
if (event.pageX == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -22,15 +22,15 @@ export function getCoords(event: MouseEvent, rowContainer: HTMLElement, charMeas
|
||||
let y = event.pageY;
|
||||
let el = rowContainer;
|
||||
|
||||
// should probably check offsetParent
|
||||
// but this is more portable
|
||||
// Converts the coordinates from being relative to the document to being
|
||||
// relative to the terminal.
|
||||
while (el && el !== self.document.documentElement) {
|
||||
x -= el.offsetLeft;
|
||||
y -= el.offsetTop;
|
||||
el = 'offsetParent' in el ? <HTMLElement>el.offsetParent : <HTMLElement>el.parentElement;
|
||||
}
|
||||
|
||||
// convert to cols/rows
|
||||
// Convert to cols/rows
|
||||
x = Math.ceil(x / charMeasure.width);
|
||||
y = Math.ceil(y / charMeasure.height);
|
||||
|
||||
@@ -52,14 +52,11 @@ export function getRawByteCoords(event: MouseEvent, rowContainer: HTMLElement, c
|
||||
let x = coords[0];
|
||||
let y = coords[1];
|
||||
|
||||
// be sure to avoid sending bad positions to the program
|
||||
if (x < 0) x = 0;
|
||||
if (x > colCount) x = colCount;
|
||||
if (y < 0) y = 0;
|
||||
if (y > rowCount) y = rowCount;
|
||||
// Ensure coordinates are within the terminal viewport.
|
||||
x = Math.min(Math.max(x, 0), colCount);
|
||||
y = Math.min(Math.max(y, 0), rowCount);
|
||||
|
||||
// xterm sends raw bytes and
|
||||
// starts at 32 (SP) for each.
|
||||
// xterm sends raw bytes and starts at 32 (SP) for each.
|
||||
x += 32;
|
||||
y += 32;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user