]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Add more selection manager/model tests
authorDaniel Imms <daimms@microsoft.com>
Wed, 7 Jun 2017 21:37:09 +0000 (14:37 -0700)
committerDaniel Imms <daimms@microsoft.com>
Wed, 7 Jun 2017 21:37:09 +0000 (14:37 -0700)
src/SelectionManager.test.ts
src/SelectionModel.test.ts
src/SelectionModel.ts

index e0ff6789712daa40fb42045b1c682ebe6ca2e93c..70eba55b5176b622397a7f1e19bbf72a1f5109c9 100644 (file)
@@ -166,4 +166,15 @@ describe('SelectionManager', () => {
       assert.equal(selectionManager.selectionText, '1\n2\n3\n4\n5');
     });
   });
+
+  describe('selectionText', () => {
+    it('should return the empty string when start or end selections are not set', () => {
+      assert.equal(selectionManager.selectionText, '');
+      selectionManager.model.selectionStart = [0, 0];
+      assert.equal(selectionManager.selectionText, '');
+      selectionManager.model.selectionStart = null;
+      selectionManager.model.selectionEnd = [0, 0];
+      assert.equal(selectionManager.selectionText, '');
+    });
+  });
 });
index f617772d663aeba1920457ddef2e809d6a864ab8..621026ed223ad4e5cd5efb357c007fa63ec147d2 100644 (file)
@@ -106,6 +106,10 @@ describe('SelectionManager', () => {
       model.selectionEnd = [1, 2];
       assert.equal(model.finalSelectionEnd, null);
     });
+    it('should return null if there is no selection end or selection start length', () => {
+      model.selectionStart = [1, 2];
+      assert.equal(model.finalSelectionEnd, null);
+    });
     it('should return selection start + length if there is no selection end', () => {
       model.selectionStart = [2, 2];
       model.selectionStartLength = 2;
index 03c99abe583445449fc301c5aff69055caa35196..f6491ae50af6bd5cefc2ab84a729c581bb2b4fd8 100644 (file)
@@ -30,6 +30,7 @@ export class SelectionModel {
   constructor(
     private _terminal: ITerminal
   ) {
+    this.clearSelection();
   }
 
   /**
@@ -39,6 +40,7 @@ export class SelectionModel {
     this.selectionStart = null;
     this.selectionEnd = null;
     this.isSelectAllActive = false;
+    this.selectionStartLength = 0;
   }
 
   /**
@@ -49,7 +51,7 @@ export class SelectionModel {
       return [0, 0];
     }
 
-    if (!this.selectionEnd) {
+    if (!this.selectionEnd || !this.selectionStart) {
       return this.selectionStart;
     }
 
@@ -71,6 +73,9 @@ export class SelectionModel {
 
     // Use the selection start if the end doesn't exist or they're reversed
     if (!this.selectionEnd || this._areSelectionValuesReversed()) {
+      if (this.selectionStartLength === 0) {
+        return null;
+      }
       return [this.selectionStart[0] + this.selectionStartLength, this.selectionStart[1]];
     }