From 582b54529f8e2576bb847fa986c6d0b3f8a57955 Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Fri, 15 Sep 2023 13:17:54 +0530 Subject: [PATCH] dep(): `searchPossibleTargets` => `findTargets` --- src/canvas/Canvas.ts | 6 +++--- src/canvas/SelectableCanvas.ts | 18 +++++++++++------- src/canvas/__tests__/eventData.test.ts | 12 +++++------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/canvas/Canvas.ts b/src/canvas/Canvas.ts index 6f2f49739c2..8c64a8d9ca3 100644 --- a/src/canvas/Canvas.ts +++ b/src/canvas/Canvas.ts @@ -399,7 +399,7 @@ export class Canvas extends SelectableCanvas implements CanvasOptions { * Override at will */ protected findDragTargets(e: DragEvent) { - const { target, targets } = this.searchPossibleTargets( + const { target, targets } = this.findTargets( this._objects, this.getPointer(e, true) ); @@ -1487,10 +1487,10 @@ export class Canvas extends SelectableCanvas implements CanvasOptions { const pointer = this.getPointer(e, true); target = // first search active objects for a target to remove - this.searchPossibleTargets(prevActiveObjects, pointer).target || + this.findTargets(prevActiveObjects, pointer).target || // if not found, search under active selection for a target to add // `prevActiveObjects` will be searched but we already know they will not be found - this.searchPossibleTargets(this._objects, pointer).target; + this.findTargets(this._objects, pointer).target; // if nothing is found bail out if (!target || !target.selectable) { return false; diff --git a/src/canvas/SelectableCanvas.ts b/src/canvas/SelectableCanvas.ts index 112809f2ae2..bcb11684ec7 100644 --- a/src/canvas/SelectableCanvas.ts +++ b/src/canvas/SelectableCanvas.ts @@ -727,7 +727,7 @@ export class SelectableCanvas // check pointer is over active selection and possibly perform `subTargetCheck` const { target: selectedTarget, targets: selectedTargets } = - this.searchPossibleTargets([activeObject], pointer); + this.findTargets([activeObject], pointer); if (selectedTarget && aObjects.length > 1) { // active selection does not select sub targets like normal groups @@ -743,7 +743,7 @@ export class SelectableCanvas ); return activeObject; } else { - const { target, targets: canvasTargets } = this.searchPossibleTargets( + const { target, targets: canvasTargets } = this.findTargets( this._objects, pointer ); @@ -769,10 +769,7 @@ export class SelectableCanvas } } - const { target, targets } = this.searchPossibleTargets( - this._objects, - pointer - ); + const { target, targets } = this.findTargets(this._objects, pointer); this.targets = target ? targets.slice(0, targets.indexOf(target)) : targets; return target; } @@ -860,7 +857,7 @@ export class SelectableCanvas * @param {Object} [pointer] canvas element plane coordinates to check * @return {FabricObject} **top most selectable object on screen** that contains {@link pointer} */ - searchPossibleTargets( + findTargets( objects: FabricObject[], pointer: Point, { @@ -883,6 +880,13 @@ export class SelectableCanvas }; } + /** + * @deprecated see {@link findTargets} + */ + searchPossibleTargets(objects: FabricObject[], pointer: Point) { + return this.findTargets(objects, pointer).target; + } + /** * Returns pointer coordinates without the effect of the viewport * @param {Object} pointer with "x" and "y" number values in canvas HTML coordinates diff --git a/src/canvas/__tests__/eventData.test.ts b/src/canvas/__tests__/eventData.test.ts index 50be437c1fd..a2fae8bb48e 100644 --- a/src/canvas/__tests__/eventData.test.ts +++ b/src/canvas/__tests__/eventData.test.ts @@ -303,7 +303,7 @@ describe('Event targets', () => { } ); - test('searchPossibleTargets', () => { + test('findTargets', () => { const subTarget = new FabricObject(); const target = new Group([subTarget], { subTargetCheck: true, @@ -318,14 +318,14 @@ describe('Event targets', () => { canvas.add(parent); jest.spyOn(canvas, '_checkTarget').mockReturnValue(true); - expect(canvas.searchPossibleTargets([parent], new Point())).toEqual({ + expect(canvas.findTargets([parent], new Point())).toEqual({ target, targets: [subTarget, target, parent], }); }); test.each([true, false])( - 'searchPossibleTargets with selection and subTargetCheck %s', + 'findTargets with selection and subTargetCheck %s', (subTargetCheck) => { const subTarget = new FabricObject(); const target = new Group([subTarget], { @@ -355,9 +355,7 @@ describe('Event targets', () => { : [activeSelection] ); - expect( - canvas.searchPossibleTargets([activeSelection], new Point()) - ).toEqual({ + expect(canvas.findTargets([activeSelection], new Point())).toEqual({ target: activeSelection, targets: subTargetCheck ? [other, activeSelection] @@ -365,7 +363,7 @@ describe('Event targets', () => { }); expect( - canvas.searchPossibleTargets(canvas.getActiveObjects(), new Point()) + canvas.findTargets(canvas.getActiveObjects(), new Point()) ).toEqual({ target: other, targets: [other],