More work on SelectionManager
This commit is contained in:
+38
-1
@@ -12,12 +12,14 @@ export class SelectionManager {
|
||||
|
||||
private _buffer: CircularList<any>;
|
||||
private _rowContainer: HTMLElement;
|
||||
private _selectionContainer: HTMLElement;
|
||||
private _charMeasure: CharMeasure;
|
||||
|
||||
private _mouseMoveListener: EventListener;
|
||||
|
||||
constructor(buffer: CircularList<any>, rowContainer: HTMLElement, charMeasure: CharMeasure) {
|
||||
constructor(buffer: CircularList<any>, rowContainer: HTMLElement, selectionContainer: HTMLElement, charMeasure: CharMeasure) {
|
||||
this._rowContainer = rowContainer;
|
||||
this._selectionContainer = selectionContainer;
|
||||
this._buffer = buffer;
|
||||
this._charMeasure = charMeasure;
|
||||
this._attachListeners();
|
||||
@@ -38,10 +40,43 @@ export class SelectionManager {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Redraws the selection.
|
||||
*/
|
||||
public refresh(): void {
|
||||
console.log(`Selection: Start: (${this._selectionStart[0]}, ${this._selectionStart[1]}), End: (${this._selectionEnd[0]}, ${this._selectionEnd[1]})`);
|
||||
this._selectionContainer.innerHTML = `<div><br><br></div>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the buffer being trimmed, adjust the selection position.
|
||||
* @param amount The amount the buffer is being trimmed.
|
||||
*/
|
||||
private _onTrim(amount: number) {
|
||||
// TODO: Somehow map the selection coordinates with the list that is constantly being trimmed
|
||||
// Maybe we need an ID in the CircularList that starts from 0 for the first entry and increments
|
||||
console.log('trimmed: ' + amount);
|
||||
|
||||
// Adjust the selection position based on the trimmed amount.
|
||||
this._selectionStart[0] -= amount;
|
||||
this._selectionEnd[0] -= amount;
|
||||
|
||||
// The selection has moved off the buffer, clear it.
|
||||
if (this._selectionEnd[0] < 0) {
|
||||
this._selectionStart = null;
|
||||
this._selectionEnd = null;
|
||||
this.refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
// If the selection start is trimmed, ensure the start column is 0.
|
||||
if (this._selectionStart[0] < 0) {
|
||||
this._selectionStart[1] = 0;
|
||||
}
|
||||
|
||||
// Maybe SelectionManager could maintain it's own ID concept from 0 (top of
|
||||
// buffer) to n (size of buffer). On trim just increment the selection if
|
||||
// necessary. This would reduce complexity and potentially not need the
|
||||
}
|
||||
|
||||
private _getMouseBufferCoords(event: MouseEvent) {
|
||||
@@ -58,6 +93,8 @@ export class SelectionManager {
|
||||
|
||||
private _onMouseMove(event: MouseEvent) {
|
||||
this._selectionEnd = this._getMouseBufferCoords(event);
|
||||
// TODO: Only draw here if the selection changes
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
private _onMouseUp(event: MouseEvent) {
|
||||
|
||||
Reference in New Issue
Block a user