]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Improve selection cell selection
authorDaniel Imms <daimms@microsoft.com>
Sun, 18 Jun 2017 19:02:58 +0000 (12:02 -0700)
committerDaniel Imms <daimms@microsoft.com>
Sun, 18 Jun 2017 19:02:58 +0000 (12:02 -0700)
Fixes #709

src/SelectionManager.ts
src/utils/Mouse.ts

index 9cfa53028f194a91736e30b7028b78c5a69557e9..71c712edb26c41368587d3961c59accf5ddc179d 100644 (file)
@@ -309,7 +309,7 @@ export class SelectionManager extends EventEmitter {
    * @param event The mouse event.
    */
   private _getMouseBufferCoords(event: MouseEvent): [number, number] {
-    const coords = Mouse.getCoords(event, this._rowContainer, this._charMeasure, this._terminal.cols, this._terminal.rows);
+    const coords = Mouse.getCoords(event, this._rowContainer, this._charMeasure, this._terminal.cols, this._terminal.rows, true);
     // Convert to 0-based
     coords[0]--;
     coords[1]--;
index 79c5d5c1160735a0f47ce37f161e3a787840b467..a5d72c1e9310b199ca8df8b0c449548d7912795d 100644 (file)
@@ -30,12 +30,17 @@ export function getCoordsRelativeToElement(event: MouseEvent, element: HTMLEleme
  * @param event The mouse event.
  * @param rowContainer The terminal's row container.
  * @param charMeasure The char measure object used to determine character sizes.
+ * @param colCount The number of columns in the terminal.
+ * @param rowCount The number of rows n the terminal.
+ * @param isSelection Whether the request is for the selection or not. This 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.
  */
-export function getCoords(event: MouseEvent, rowContainer: HTMLElement, charMeasure: CharMeasure, colCount: number, rowCount: number): [number, number] {
+export function getCoords(event: MouseEvent, rowContainer: HTMLElement, charMeasure: CharMeasure, colCount: number, rowCount: number, isSelection?: boolean): [number, number] {
   const coords = getCoordsRelativeToElement(event, rowContainer);
 
-  // Convert to cols/rows
-  coords[0] = Math.ceil(coords[0] / charMeasure.width);
+  // Convert to cols/rows.
+  coords[0] = Math.ceil((coords[0] + (isSelection ? charMeasure.width / 2 : 0)) / charMeasure.width);
   coords[1] = Math.ceil(coords[1] / charMeasure.height);
 
   // Ensure coordinates are within the terminal viewport.