Fire onSelectionChange when starting to drag

This commit is contained in:
Daniel Imms
2026-01-08 16:51:45 -08:00
parent 8e4de23c11
commit 613aa6ba23
3 changed files with 69 additions and 0 deletions
@@ -496,5 +496,19 @@ describe('SelectionService', () => {
assert.isFalse(selectionService.areCoordsInSelection([2, 1], [2, 0], [2, 1]));
});
});
describe('onSelectionChange', () => {
it('should not fire when setting model properties directly', () => {
buffer.lines.set(0, stringToRow('foo bar'));
let eventFired = false;
selectionService.onSelectionChange(() => { eventFired = true; });
selectionService.model.selectionStart = [0, 0];
selectionService.model.selectionEnd = undefined;
assert.isFalse(eventFired);
});
});
});
+8
View File
@@ -532,6 +532,9 @@ export class SelectionService extends Disposable implements ISelectionService {
* @param event The mouse event.
*/
private _handleSingleClick(event: MouseEvent): void {
// Track if there was a selection before clearing
const hadSelection = this.hasSelection;
this._model.selectionStartLength = 0;
this._model.isSelectAllActive = false;
this._activeSelectionMode = this.shouldColumnSelect(event) ? SelectionMode.COLUMN : SelectionMode.NORMAL;
@@ -543,6 +546,11 @@ export class SelectionService extends Disposable implements ISelectionService {
}
this._model.selectionEnd = undefined;
// Fire selection change event if a selection was cleared
if (hadSelection) {
this._fireOnSelectionChange(this._model.finalSelectionStart, this._model.finalSelectionEnd, false);
}
// Ensure the line exists
const line = this._bufferService.buffer.lines.get(this._model.selectionStart[1]);
if (!line) {