Merge pull request #3227 from marvinthepa/3225_onSelectionChange_on_clear
Store old selection when firing onSelectionChange
This commit is contained in:
@@ -685,23 +685,22 @@ export class SelectionService extends Disposable implements ISelectionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this._fireIfSelectionChanged();
|
this._fireEventIfSelectionChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _fireIfSelectionChanged(): void {
|
private _fireEventIfSelectionChanged(): void {
|
||||||
// Fire if there is no selection
|
const start = this._model.finalSelectionStart;
|
||||||
const hasSelection = this.hasSelection;
|
const end = this._model.finalSelectionEnd;
|
||||||
|
const hasSelection = !!start && !!end && (start[0] !== end[0] || start[1] !== end[1]);
|
||||||
|
|
||||||
if (!hasSelection) {
|
if (!hasSelection) {
|
||||||
if (this._oldHasSelection) {
|
if (this._oldHasSelection) {
|
||||||
this._onSelectionChange.fire();
|
this._fireOnSelectionChange(start, end, hasSelection);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const start = this._model.finalSelectionStart;
|
|
||||||
const end = this._model.finalSelectionEnd;
|
|
||||||
|
|
||||||
// Sanity check, these should not be undefined as there is a selection
|
// Sanity check, these should not be undefined as there is a selection
|
||||||
if (!start || !end) {
|
if (!start || !end) {
|
||||||
return;
|
return;
|
||||||
@@ -711,13 +710,17 @@ export class SelectionService extends Disposable implements ISelectionService {
|
|||||||
start[0] !== this._oldSelectionStart[0] || start[1] !== this._oldSelectionStart[1] ||
|
start[0] !== this._oldSelectionStart[0] || start[1] !== this._oldSelectionStart[1] ||
|
||||||
end[0] !== this._oldSelectionEnd[0] || end[1] !== this._oldSelectionEnd[1])) {
|
end[0] !== this._oldSelectionEnd[0] || end[1] !== this._oldSelectionEnd[1])) {
|
||||||
|
|
||||||
this._oldSelectionStart = start;
|
this._fireOnSelectionChange(start, end, hasSelection);
|
||||||
this._oldSelectionEnd = end;
|
|
||||||
this._oldHasSelection = hasSelection;
|
|
||||||
this._onSelectionChange.fire();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _fireOnSelectionChange(start: [number, number] | undefined, end: [number, number] | undefined, hasSelection: boolean): void {
|
||||||
|
this._oldSelectionStart = start;
|
||||||
|
this._oldSelectionEnd = end;
|
||||||
|
this._oldHasSelection = hasSelection;
|
||||||
|
this._onSelectionChange.fire();
|
||||||
|
}
|
||||||
|
|
||||||
private _onBufferActivate(e: {activeBuffer: IBuffer, inactiveBuffer: IBuffer}): void {
|
private _onBufferActivate(e: {activeBuffer: IBuffer, inactiveBuffer: IBuffer}): void {
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
// Only adjust the selection on trim, shiftElements is rarely used (only in
|
// Only adjust the selection on trim, shiftElements is rarely used (only in
|
||||||
@@ -762,7 +765,7 @@ export class SelectionService extends Disposable implements ISelectionService {
|
|||||||
public rightClickSelect(ev: MouseEvent): void {
|
public rightClickSelect(ev: MouseEvent): void {
|
||||||
if (!this._isClickInSelection(ev)) {
|
if (!this._isClickInSelection(ev)) {
|
||||||
this._selectWordAtCursor(ev);
|
this._selectWordAtCursor(ev);
|
||||||
this._fireIfSelectionChanged();
|
this._fireEventIfSelectionChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user