]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Undo CiruclarList id changes, fix null check, lint
authorDaniel Imms <daimms@microsoft.com>
Wed, 7 Jun 2017 05:59:16 +0000 (22:59 -0700)
committerDaniel Imms <daimms@microsoft.com>
Wed, 7 Jun 2017 05:59:16 +0000 (22:59 -0700)
src/Renderer.ts
src/SelectionManager.test.ts
src/SelectionManager.ts
src/utils/CircularList.ts

index 82f5a3eef454de7c9ceb0709fbd27192dd5745aa..f0f50f61fb8d32afd6ac893db3204336c9e42e78 100644 (file)
@@ -365,11 +365,15 @@ export class Renderer {
     this._terminal.selectionContainer.appendChild(documentFragment);
   }
 
+  /**
+   * Creates a selection element at the specified position.
+   * @param row The row of the selection.
+   * @param colStart The start column.
+   * @param colEnd The end columns.
+   */
   private _createSelectionElement(row: number, colStart: number, colEnd: number): HTMLElement {
     const element = document.createElement('div');
-    // TODO: Move into a generated <style> element
     element.style.height = `${this._terminal.charMeasure.height}px`;
-
     element.style.top = `${row * this._terminal.charMeasure.height}px`;
     element.style.left = `${colStart * this._terminal.charMeasure.width}px`;
     element.style.width = `${this._terminal.charMeasure.width * (colEnd - colStart)}px`;
index d9d3a8034779a2e3a1ef1a9790871a5eb5a6e838..5266030732de627af1e0f84b485710062c5fd579 100644 (file)
@@ -7,7 +7,7 @@ import { ITerminal } from './Interfaces';
 import { CharMeasure } from './utils/CharMeasure';
 import { CircularList } from './utils/CircularList';
 import { SelectionManager } from './SelectionManager';
-import { SelectionModel } from "./SelectionModel";
+import { SelectionModel } from './SelectionModel';
 
 class TestSelectionManager extends SelectionManager {
   constructor(
index e5b627804729f7fd86b9843f9190d094346d609e..04834d225b4a8f6711f5085f8486d3f78f8d9b18 100644 (file)
@@ -245,7 +245,6 @@ export class SelectionManager extends EventEmitter {
    */
   private _getMouseBufferCoords(event: MouseEvent): [number, number] {
     const coords = Mouse.getCoords(event, this._rowContainer, this._charMeasure, this._terminal.cols, this._terminal.rows);
-    console.log(coords);
     // Convert to 0-based
     coords[0]--;
     coords[1]--;
@@ -285,7 +284,6 @@ export class SelectionManager extends EventEmitter {
     }
 
     this._setMouseClickCount(event);
-    console.log(this._clickCount);
 
     if (event.shiftKey) {
       this._onShiftClick(event);
@@ -424,9 +422,11 @@ export class SelectionManager extends EventEmitter {
     // If the character is a wide character include the cell to the right in the
     // selection. Note that selections at the very end of the line will never
     // have a character.
-    const char = this._buffer.get(this._model.selectionEnd[1])[this._model.selectionEnd[0]];
-    if (char && char[2] === 0) {
-      this._model.selectionEnd[0]++;
+    if (this._model.selectionEnd[1] < this._buffer.length) {
+      const char = this._buffer.get(this._model.selectionEnd[1])[this._model.selectionEnd[0]];
+      if (char && char[2] === 0) {
+        this._model.selectionEnd[0]++;
+      }
     }
 
     // Only draw here if the selection changes.
index b6fafe7ced4afac8988fcc4acd9bb753722f837a..d0b2f685a48031d79d87cd3de761de54e60148b1 100644 (file)
@@ -6,22 +6,14 @@
  */
 import { EventEmitter } from '../EventEmitter';
 
-// TODO: Do we need the ID here?
-interface ListEntry<T> {
-  id: number;
-  value: T;
-}
-
 export class CircularList<T> extends EventEmitter {
-  private _array: ListEntry<T>[];
+  private _array: T[];
   private _startIndex: number;
   private _length: number;
 
-  private _nextId = 0;
-
   constructor(maxLength: number) {
     super();
-    this._array = new Array<ListEntry<T>>(maxLength);
+    this._array = new Array<T>(maxLength);
     this._startIndex = 0;
     this._length = 0;
   }
@@ -33,14 +25,9 @@ export class CircularList<T> extends EventEmitter {
   public set maxLength(newMaxLength: number) {
     // Reconstruct array, starting at index 0. Only transfer values from the
     // indexes 0 to length.
-    let newArray = new Array<ListEntry<T>>(newMaxLength);
-    // Reset ids when maxLength is changed
-    this._nextId = 0;
+    let newArray = new Array<T>(newMaxLength);
     for (let i = 0; i < Math.min(newMaxLength, this.length); i++) {
-      newArray[i] = {
-        id: this._nextId++,
-        value: this._array[this._getCyclicIndex(i)].value
-      };
+      newArray[i] = this._array[this._getCyclicIndex(i)];
     }
     this._array = newArray;
     this._startIndex = 0;
@@ -78,10 +65,6 @@ export class CircularList<T> extends EventEmitter {
    * @return The value corresponding to the index.
    */
   public get(index: number): T {
-    return this.getEntry(index).value;
-  }
-
-  public getEntry(index: number): ListEntry<T> {
     return this._array[this._getCyclicIndex(index)];
   }
 
@@ -94,11 +77,7 @@ export class CircularList<T> extends EventEmitter {
    * @param value The value to set.
    */
   public set(index: number, value: T): void {
-    this._array[this._getCyclicIndex(index)].value = value;
-  }
-
-  private _setEntry(index: number, entry: ListEntry<T>): void {
-    this._array[this._getCyclicIndex(index)] = entry;
+    this._array[this._getCyclicIndex(index)] = value;
   }
 
   /**
@@ -107,10 +86,7 @@ export class CircularList<T> extends EventEmitter {
    * @param value The value to push onto the list.
    */
   public push(value: T): void {
-    this._array[this._getCyclicIndex(this._length)] = {
-      id: this._nextId,
-      value
-    };
+    this._array[this._getCyclicIndex(this._length)] = value;
     if (this._length === this.maxLength) {
       this._startIndex++;
       if (this._startIndex === this.maxLength) {
@@ -127,7 +103,7 @@ export class CircularList<T> extends EventEmitter {
    * @return The popped value.
    */
   public pop(): T {
-    return this._array[this._getCyclicIndex(this._length-- - 1)].value;
+    return this._array[this._getCyclicIndex(this._length-- - 1)];
   }
 
   /**
@@ -154,10 +130,7 @@ export class CircularList<T> extends EventEmitter {
         this._array[this._getCyclicIndex(i + items.length)] = this._array[this._getCyclicIndex(i)];
       }
       for (let i = 0; i < items.length; i++) {
-        this._array[this._getCyclicIndex(start + i)] = {
-          id: this._nextId,
-          value: items[i]
-        };
+        this._array[this._getCyclicIndex(start + i)] = items[i];
       }
 
       // Adjust length as needed
@@ -198,10 +171,7 @@ export class CircularList<T> extends EventEmitter {
 
     if (offset > 0) {
       for (let i = count - 1; i >= 0; i--) {
-        this._setEntry(start + i + offset, {
-          id: this._nextId++,
-          value: this.get(start + i)
-        });
+        this.set(start + i + offset, this.get(start + i));
       }
       const expandListBy = (start + count + offset) - this._length;
       if (expandListBy > 0) {