@@ -6,7 +6,6 @@ import type {
66 TLPageId ,
77 TLShape ,
88 TLShapeId ,
9- VecModel ,
109} from "tldraw" ;
1110import {
1211 CANVAS_FILE_SHAPE_TYPE ,
@@ -64,13 +63,13 @@ export function zoomToFill(editor: Editor, id: TLShapeId, animate = true) {
6463 * spend on editing its text zooms it to fill the canvas. tldraw's own double-click would crop a
6564 * picture or, over a locked shape such as a board, drop a new text box on the canvas, so this takes the gesture over in the select tool's
6665 * idle state, where tldraw handles it, rather than watching for it alongside. A note, a text or a
67- * label still edits its text. A second double-click on the shape it last zoomed to puts the camera
68- * back where it was before, on the same page. Returns the uninstaller.
66+ * label still edits its text. A second double-click on the shape it last zoomed to shows the whole
67+ * page. Returns the uninstaller.
6968 */
7069export function installDoubleClickZoom ( editor : Editor ) {
7170 const idle = editor . getStateDescendant < StateNode > ( "select.idle" ) ! ;
7271 const own = idle . onDoubleClick ! ;
73- let before : { id : TLShapeId ; page : TLPageId ; camera : VecModel } | undefined ;
72+ let zoomed : { id : TLShapeId ; page : TLPageId } | undefined ;
7473 idle . onDoubleClick = ( info ) => {
7574 const hit = info . phase === "down" && shapeUnderPointer ( editor ) ;
7675 if (
@@ -81,14 +80,13 @@ export function installDoubleClickZoom(editor: Editor) {
8180 ! editor . canEditShape ( hit ) )
8281 ) {
8382 const page = editor . getCurrentPageId ( ) ;
84- if ( before ?. id === hit . id && before . page === page ) {
85- editor . setCamera ( before . camera , {
83+ if ( zoomed ?. id === hit . id && zoomed . page === page ) {
84+ zoomed = undefined ;
85+ return editor . zoomToFit ( {
8686 animation : { duration : editor . options . animationMediumMs } ,
8787 } ) ;
88- before = undefined ;
89- return ;
9088 }
91- before = { id : hit . id , page, camera : editor . getCamera ( ) } ;
89+ zoomed = { id : hit . id , page } ;
9290 return zoomToFill ( editor , hit . id ) ;
9391 }
9492 own . call ( idle , info ) ;
0 commit comments