Skip to content

Commit

Permalink
fix: should only reset portal position when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 authored and tiensonqin committed Dec 6, 2022
1 parent 923eaf6 commit 2a96cf6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tldraw/apps/tldraw-logseq/src/lib/shapes/LogseqPortalShape.tsx
@@ -1,7 +1,9 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {
BoundsUtils,
delay,
getComputedColor,
TLBounds,
TLBoxShape,
TLBoxShapeProps,
TLResetBoundsInfo,
Expand Down Expand Up @@ -392,9 +394,18 @@ export class LogseqPortalShape extends TLBoxShape<LogseqPortalShapeProps> {

React.useEffect(() => {
if (isCreating) {
app.viewport.zoomToBounds({ ...this.bounds, minY: this.bounds.maxY + 25 })
const screenSize = [app.viewport.bounds.width, app.viewport.bounds.height]
const boundScreenCenter = app.viewport.getScreenPoint([this.bounds.minX, this.bounds.minY])

if (
boundScreenCenter[0] > screenSize[0] - 400 ||
boundScreenCenter[1] > screenSize[1] - 240 ||
app.viewport.camera.zoom > 1.5 || app.viewport.camera.zoom < 0.5
) {
app.viewport.zoomToBounds({ ...this.bounds, minY: this.bounds.maxY + 25 })
}
}
}, [app.viewport.currentView.height])
}, [app.viewport.bounds.height.toFixed(2)])

const onPageNameChanged = React.useCallback((id: string) => {
this.initialHeightCalculated = false
Expand Down Expand Up @@ -434,6 +445,7 @@ export class LogseqPortalShape extends TLBoxShape<LogseqPortalShapeProps> {
}}
{...events}
>
<div className=""></div>
{isBinding && <BindingIndicator mode="html" strokeWidth={strokeWidth} size={size} />}
<div
data-inner-events={!tlEventsEnabled}
Expand Down

0 comments on commit 2a96cf6

Please sign in to comment.