kopia lustrzana https://github.com/Tldraw/Tldraw
[fix] zoom to selection (#164)
* fix camera on zoom to selection * Update tlstate.ts * Update tlstate.tspull/170/head
rodzic
01c824bbbe
commit
62343dab9f
|
@ -1391,12 +1391,15 @@ export class TLDrawState extends StateManager<Data> {
|
|||
|
||||
const bounds = Utils.getCommonBounds(shapes.map(TLDR.getBounds))
|
||||
|
||||
const zoom = TLDR.getCameraZoom(
|
||||
this.bounds.width < this.bounds.height
|
||||
? (this.bounds.width - 128) / bounds.width
|
||||
: (this.bounds.height - 128) / bounds.height
|
||||
let zoom = TLDR.getCameraZoom(
|
||||
Math.min((this.bounds.width - 128) / bounds.width, (this.bounds.height - 128) / bounds.height)
|
||||
)
|
||||
|
||||
zoom =
|
||||
this.pageState.camera.zoom === zoom || this.pageState.camera.zoom < 1
|
||||
? Math.min(1, zoom)
|
||||
: zoom
|
||||
|
||||
const mx = (this.bounds.width - bounds.width * zoom) / 2 / zoom
|
||||
const my = (this.bounds.height - bounds.height * zoom) / 2 / zoom
|
||||
|
||||
|
@ -1413,14 +1416,19 @@ export class TLDrawState extends StateManager<Data> {
|
|||
zoomToSelection = (): this => {
|
||||
if (this.selectedIds.length === 0) return this
|
||||
|
||||
console.log('zooming to selection')
|
||||
|
||||
const bounds = TLDR.getSelectedBounds(this.state)
|
||||
|
||||
const zoom = TLDR.getCameraZoom(
|
||||
this.bounds.width < this.bounds.height
|
||||
? (this.bounds.width - 128) / bounds.width
|
||||
: (this.bounds.height - 128) / bounds.height
|
||||
let zoom = TLDR.getCameraZoom(
|
||||
Math.min((this.bounds.width - 128) / bounds.width, (this.bounds.height - 128) / bounds.height)
|
||||
)
|
||||
|
||||
zoom =
|
||||
this.pageState.camera.zoom === zoom || this.pageState.camera.zoom < 1
|
||||
? Math.min(1, zoom)
|
||||
: zoom
|
||||
|
||||
const mx = (this.bounds.width - bounds.width * zoom) / 2 / zoom
|
||||
const my = (this.bounds.height - bounds.height * zoom) / 2 / zoom
|
||||
|
||||
|
@ -1443,6 +1451,7 @@ export class TLDrawState extends StateManager<Data> {
|
|||
const bounds = Utils.getCommonBounds(Object.values(shapes).map(TLDR.getBounds))
|
||||
|
||||
const { zoom } = pageState.camera
|
||||
|
||||
const mx = (this.bounds.width - bounds.width * zoom) / 2 / zoom
|
||||
const my = (this.bounds.height - bounds.height * zoom) / 2 / zoom
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue