]> git.proxmox.com Git - mirror_xterm.js.git/blobdiff - src/SelectionModel.ts
Merge pull request #926 from ficristo/search-fix
[mirror_xterm.js.git] / src / SelectionModel.ts
index 03c99abe583445449fc301c5aff69055caa35196..8c599fd7ae1177e66fe0ea0beda84f11707ea225 100644 (file)
@@ -4,6 +4,10 @@
 
 import { ITerminal } from './Interfaces';
 
+/**
+ * Represents a selection within the buffer. This model only cares about column
+ * and row coordinates, not wide characters.
+ */
 export class SelectionModel {
   /**
    * Whether select all is currently active.
@@ -30,6 +34,7 @@ export class SelectionModel {
   constructor(
     private _terminal: ITerminal
   ) {
+    this.clearSelection();
   }
 
   /**
@@ -39,6 +44,7 @@ export class SelectionModel {
     this.selectionStart = null;
     this.selectionEnd = null;
     this.isSelectAllActive = false;
+    this.selectionStartLength = 0;
   }
 
   /**
@@ -49,11 +55,11 @@ export class SelectionModel {
       return [0, 0];
     }
 
-    if (!this.selectionEnd) {
+    if (!this.selectionEnd || !this.selectionStart) {
       return this.selectionStart;
     }
 
-    return this._areSelectionValuesReversed() ? this.selectionEnd : this.selectionStart;
+    return this.areSelectionValuesReversed() ? this.selectionEnd : this.selectionStart;
   }
 
   /**
@@ -62,7 +68,7 @@ export class SelectionModel {
    */
   public get finalSelectionEnd(): [number, number] {
     if (this.isSelectAllActive) {
-      return [this._terminal.cols - 1, this._terminal.ybase + this._terminal.rows - 1];
+      return [this._terminal.cols, this._terminal.buffer.ybase + this._terminal.rows - 1];
     }
 
     if (!this.selectionStart) {
@@ -70,7 +76,7 @@ export class SelectionModel {
     }
 
     // Use the selection start if the end doesn't exist or they're reversed
-    if (!this.selectionEnd || this._areSelectionValuesReversed()) {
+    if (!this.selectionEnd || this.areSelectionValuesReversed()) {
       return [this.selectionStart[0] + this.selectionStartLength, this.selectionStart[1]];
     }
 
@@ -87,7 +93,7 @@ export class SelectionModel {
   /**
    * Returns whether the selection start and end are reversed.
    */
-  protected _areSelectionValuesReversed(): boolean {
+  public areSelectionValuesReversed(): boolean {
     const start = this.selectionStart;
     const end = this.selectionEnd;
     return start[1] > end[1] || (start[1] === end[1] && start[0] > end[0]);