-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
revert(): rm active selection ref #9561
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4358971
update CHANGELOG.md
github-actions[bot] 324e0c1
rm ref
ShaMan123 4515535
unrelated comment
ShaMan123 570788d
rm(): `instanceof ActiveSelection` => `isActiveSelection`
ShaMan123 56bbc03
put changelot at the top
asturur 50f9630
add to remove calssregistry because of jest
asturur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ import type { | |
} from '../EventTypeDefs'; | ||
import { | ||
addTransformToObject, | ||
resetObjectTransform, | ||
saveObjectTransform, | ||
} from '../util/misc/objectTransforms'; | ||
import type { TCanvasSizeOptions } from './StaticCanvas'; | ||
|
@@ -31,13 +30,13 @@ import type { IText } from '../shapes/IText/IText'; | |
import type { BaseBrush } from '../brushes/BaseBrush'; | ||
import { pick } from '../util/misc/pick'; | ||
import { sendPointToPlane } from '../util/misc/planeChange'; | ||
import { ActiveSelection } from '../shapes/ActiveSelection'; | ||
import { cos, createCanvasElement, sin } from '../util'; | ||
import { CanvasDOMManager } from './DOMManagers/CanvasDOMManager'; | ||
import { BOTTOM, CENTER, LEFT, RIGHT, TOP } from '../constants'; | ||
import type { CanvasOptions, TCanvasOptions } from './CanvasOptions'; | ||
import type { CanvasOptions } from './CanvasOptions'; | ||
import { canvasDefaults } from './CanvasOptions'; | ||
import { Intersection } from '../Intersection'; | ||
import { isActiveSelection } from '../util/typeAssertions'; | ||
|
||
/** | ||
* Canvas class | ||
|
@@ -294,17 +293,6 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents> | |
protected declare _isCurrentlyDrawing: boolean; | ||
declare freeDrawingBrush?: BaseBrush; | ||
declare _activeObject?: FabricObject; | ||
protected _activeSelection: ActiveSelection; | ||
|
||
constructor( | ||
el?: string | HTMLCanvasElement, | ||
{ activeSelection = new ActiveSelection(), ...options }: TCanvasOptions = {} | ||
) { | ||
super(el, options); | ||
this._activeSelection = activeSelection; | ||
this._activeSelection.set('canvas', this); | ||
this._activeSelection.setCoords(); | ||
} | ||
|
||
protected initElements(el?: string | HTMLCanvasElement) { | ||
this.elements = new CanvasDOMManager(el, { | ||
|
@@ -1029,27 +1017,17 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents> | |
return this._activeObject; | ||
} | ||
|
||
/** | ||
* Returns instance's active selection | ||
*/ | ||
getActiveSelection() { | ||
return this._activeSelection; | ||
} | ||
|
||
/** | ||
* Returns an array with the current selected objects | ||
* @return {FabricObject[]} active objects array | ||
*/ | ||
getActiveObjects(): FabricObject[] { | ||
const active = this._activeObject; | ||
if (active) { | ||
if (active === this._activeSelection) { | ||
return [...(active as ActiveSelection)._objects]; | ||
} else { | ||
return [active]; | ||
} | ||
} | ||
return []; | ||
return isActiveSelection(active) | ||
? active.getObjects() | ||
: active | ||
? [active] | ||
: []; | ||
} | ||
|
||
/** | ||
|
@@ -1134,6 +1112,7 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents> | |
* @return {Boolean} true if the object has been selected | ||
*/ | ||
_setActiveObject(object: FabricObject, e?: TPointerEvent) { | ||
const prevActiveObject = this._activeObject; | ||
if (this._activeObject === object) { | ||
return false; | ||
} | ||
|
@@ -1144,10 +1123,10 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents> | |
if (object.onSelect({ e })) { | ||
return false; | ||
} | ||
|
||
this._activeObject = object; | ||
|
||
if (object instanceof ActiveSelection && this._activeSelection !== object) { | ||
this._activeSelection = object; | ||
if (isActiveSelection(object) && prevActiveObject !== object) { | ||
object.set('canvas', this); | ||
object.setCoords(); | ||
} | ||
|
@@ -1173,11 +1152,6 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents> | |
if (obj.onDeselect({ e, object })) { | ||
return false; | ||
} | ||
// clear active selection | ||
if (obj === this._activeSelection) { | ||
this._activeSelection.removeAll(); | ||
resetObjectTransform(this._activeSelection); | ||
} | ||
if (this._currentTransform && this._currentTransform.target === obj) { | ||
// @ts-expect-error this method exists in the subclass - should be moved or declared as abstract | ||
this.endCurrentTransform(e); | ||
|
@@ -1227,11 +1201,13 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents> | |
*/ | ||
destroy() { | ||
// dispose of active selection | ||
const activeSelection = this._activeSelection; | ||
activeSelection.removeAll(); | ||
// @ts-expect-error disposing | ||
this._activeSelection = undefined; | ||
activeSelection.dispose(); | ||
const activeObject = this._activeObject; | ||
if (isActiveSelection(activeObject)) { | ||
activeObject.removeAll(); | ||
activeObject.dispose(); | ||
} | ||
|
||
delete this._activeObject; | ||
|
||
super.destroy(); | ||
|
||
|
@@ -1296,11 +1272,7 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents> | |
_realizeGroupTransformOnObject( | ||
instance: FabricObject | ||
): Partial<typeof instance> { | ||
if ( | ||
instance.group && | ||
instance.group === this._activeSelection && | ||
this._activeObject === instance.group | ||
) { | ||
if (instance.group && isActiveSelection(instance.group)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this check is different now, we still have to check that instance.group is activeObject |
||
const layoutProps = [ | ||
'angle', | ||
'flipX', | ||
|
@@ -1313,7 +1285,7 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents> | |
TOP, | ||
] as (keyof typeof instance)[]; | ||
const originalValues = pick<typeof instance>(instance, layoutProps); | ||
addTransformToObject(instance, this._activeObject.calcOwnMatrix()); | ||
addTransformToObject(instance, instance.group.calcOwnMatrix()); | ||
return originalValues; | ||
} else { | ||
return {}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I removed this line but still the layout manager is present and does the same.
Let's see what will happen when I remove it