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`;
*/
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]--;
}
this._setMouseClickCount(event);
- console.log(this._clickCount);
if (event.shiftKey) {
this._onShiftClick(event);
// 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.
*/
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;
}
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;
* @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)];
}
* @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;
}
/**
* @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) {
* @return The popped value.
*/
public pop(): T {
- return this._array[this._getCyclicIndex(this._length-- - 1)].value;
+ return this._array[this._getCyclicIndex(this._length-- - 1)];
}
/**
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
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) {