fix(sheets-ui): end selection when pointer is released (#7301)

This commit is contained in:
白熱
2026-07-22 20:51:36 +08:00
committed by GitHub
parent 35115da915
commit 5828eec9b0
2 changed files with 33 additions and 0 deletions
@@ -441,6 +441,34 @@ describe('BaseSelectionRenderService', () => {
expect(movingSelections.length).toBeGreaterThan(0);
});
it('ends a leaked drag before handling pointer movement with no pressed buttons', () => {
const { service } = createSelectionRenderService();
const { scene } = service.changeRuntimeForTest();
service.resetSelectionsByModelData([selections[0]]);
service.listenPointerMoveForTest();
(scene.onPointerMove$ as unknown as { emit: (evt: unknown) => void }).emit({
offsetX: 350,
offsetY: 65,
buttons: 1,
});
expect(service.selectionMoving).toBe(true);
(scene.onPointerMove$ as unknown as { emit: (evt: unknown) => void }).emit({
offsetX: 450,
offsetY: 85,
buttons: 0,
});
expect(service.getActiveRange()).toEqual({
startRow: 1,
startColumn: 1,
endRow: 3,
endColumn: 3,
});
expect(service.selectionMoving).toBe(false);
});
it('cancels an in-progress selection when another scene receives a pointer event', () => {
const { service } = createSelectionRenderService();
const { scene } = service.changeRuntimeForTest();
@@ -520,6 +520,11 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele
// #region onPointerMove$
// eslint-disable-next-line max-lines-per-function, complexity
this._scenePointerMoveSub = scene.onPointerMove$.subscribeEvent((moveEvt: IPointerEvent | IMouseEvent) => {
if (moveEvt.buttons === 0) {
this.endSelection();
return;
}
const { offsetX: moveOffsetX, offsetY: moveOffsetY } = moveEvt;
const { x: newMoveOffsetX, y: newMoveOffsetY } = scene.getCoordRelativeToViewport(Vector2.FromArray([moveOffsetX, moveOffsetY]));