remove selectionPageCenter
(#1766)
This PR removes `Editor.selectionPageCenter` and moves its implementation inline where used (in two places). ### Change Type - [x] `major` — Breaking change ### Release Notes - [dev] Removes `Editor.selectionPageCenter`
This commit is contained in:
parent
e3f4cac786
commit
7e4fb59a48
6 changed files with 27 additions and 18 deletions
|
@ -913,7 +913,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
get selectedShapes(): TLShape[];
|
||||
get selectionBounds(): Box2d | undefined;
|
||||
get selectionPageBounds(): Box2d | null;
|
||||
get selectionPageCenter(): null | Vec2d;
|
||||
get selectionRotation(): number;
|
||||
selectNone(): this;
|
||||
sendBackward(shapes: TLShape[]): this;
|
||||
|
|
|
@ -1657,18 +1657,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
return box
|
||||
}
|
||||
|
||||
/**
|
||||
* The center of the selection bounding box.
|
||||
*
|
||||
* @readonly
|
||||
* @public
|
||||
*/
|
||||
@computed get selectionPageCenter() {
|
||||
const { selectionBounds, selectionRotation } = this
|
||||
if (!selectionBounds) return null
|
||||
return Vec2d.RotWith(selectionBounds.center, selectionBounds.point, selectionRotation)
|
||||
}
|
||||
|
||||
// Focus Layer Id
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,7 +9,7 @@ import { Vec2d } from '../primitives/Vec2d'
|
|||
export function getRotationSnapshot({ editor }: { editor: Editor }): TLRotationSnapshot | null {
|
||||
const {
|
||||
selectionRotation,
|
||||
selectionPageCenter,
|
||||
selectionBounds,
|
||||
inputs: { originPagePoint },
|
||||
selectedShapes,
|
||||
} = editor
|
||||
|
@ -19,10 +19,14 @@ export function getRotationSnapshot({ editor }: { editor: Editor }): TLRotationS
|
|||
// will produce the wrong results
|
||||
|
||||
// Return null if there are no selected shapes
|
||||
if (!selectionPageCenter) {
|
||||
if (!selectionBounds) {
|
||||
return null
|
||||
}
|
||||
|
||||
const selectionPageCenter = selectionBounds.center
|
||||
.clone()
|
||||
.rotWith(selectionBounds.point, selectionRotation)
|
||||
|
||||
return {
|
||||
selectionPageCenter: selectionPageCenter,
|
||||
initialCursorAngle: selectionPageCenter.angle(originPagePoint),
|
||||
|
|
|
@ -139,13 +139,19 @@ export class Rotating extends StateNode {
|
|||
|
||||
_getRotationFromPointerPosition({ snapToNearestDegree }: { snapToNearestDegree: boolean }) {
|
||||
const {
|
||||
selectionPageCenter,
|
||||
selectionBounds,
|
||||
selectionRotation,
|
||||
inputs: { shiftKey, currentPagePoint },
|
||||
} = this.editor
|
||||
const { initialCursorAngle, initialSelectionRotation } = this.snapshot
|
||||
|
||||
if (!selectionBounds) return initialSelectionRotation
|
||||
|
||||
const selectionPageCenter = selectionBounds.center
|
||||
.clone()
|
||||
.rotWith(selectionBounds.point, selectionRotation)
|
||||
|
||||
// The delta is the difference between the current angle and the initial angle
|
||||
if (!selectionPageCenter) return initialSelectionRotation
|
||||
const preSnapRotationDelta = selectionPageCenter.angle(currentPagePoint) - initialCursorAngle
|
||||
let newSelectionRotation = initialSelectionRotation + preSnapRotationDelta
|
||||
|
||||
|
|
|
@ -493,6 +493,18 @@ export class TestEditor extends Editor {
|
|||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* The center of the selection bounding box.
|
||||
*
|
||||
* @readonly
|
||||
* @public
|
||||
*/
|
||||
get selectionPageCenter() {
|
||||
const { selectionBounds, selectionRotation } = this
|
||||
if (!selectionBounds) return null
|
||||
return Vec2d.RotWith(selectionBounds.center, selectionBounds.point, selectionRotation)
|
||||
}
|
||||
|
||||
translateSelection(dx: number, dy: number, options?: Partial<TLPointerEventInfo>) {
|
||||
if (this.selectedShapeIds.length === 0) {
|
||||
throw new Error('No selection')
|
||||
|
|
|
@ -77,6 +77,6 @@ describe('editor.rotateShapes', () => {
|
|||
.expectShapeToMatch({ id: ids.box2, rotation: Math.PI })
|
||||
|
||||
// Are the centers the same?
|
||||
expect(selectionPageCenter).toMatchObject(editor.selectionPageCenter!)
|
||||
expect(selectionPageCenter).toCloselyMatchObject(editor.selectionPageCenter!)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue