mirror of
https://github.com/dream-num/univer.git
synced 2026-09-19 02:18:42 +08:00
fix(sheets-ui): end selection when pointer is released (#7301)
This commit is contained in:
+28
@@ -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]));
|
||||
|
||||
Reference in New Issue
Block a user