fix camerarevert and default to select tool
This commit is contained in:
parent
45ddffbde3
commit
e6ddce8be7
|
|
@ -95,7 +95,7 @@ export function Board() {
|
||||||
onSelect: () => {
|
onSelect: () => {
|
||||||
if (editor.getSelectedShapeIds().length > 0) {
|
if (editor.getSelectedShapeIds().length > 0) {
|
||||||
zoomToSelection(editor);
|
zoomToSelection(editor);
|
||||||
editor.setCurrentTool('hand');
|
editor.setCurrentTool('select');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
readonlyOk: true,
|
readonlyOk: true,
|
||||||
|
|
@ -111,7 +111,7 @@ export function Board() {
|
||||||
url.searchParams.set('y', camera.y.toString());
|
url.searchParams.set('y', camera.y.toString());
|
||||||
url.searchParams.set('zoom', camera.z.toString());
|
url.searchParams.set('zoom', camera.z.toString());
|
||||||
navigator.clipboard.writeText(url.toString());
|
navigator.clipboard.writeText(url.toString());
|
||||||
editor.setCurrentTool('hand');
|
editor.setCurrentTool('select');
|
||||||
},
|
},
|
||||||
readonlyOk: true,
|
readonlyOk: true,
|
||||||
},
|
},
|
||||||
|
|
@ -121,7 +121,7 @@ export function Board() {
|
||||||
kbd: 'b',
|
kbd: 'b',
|
||||||
onSelect: () => {
|
onSelect: () => {
|
||||||
revertCamera();
|
revertCamera();
|
||||||
editor.setCurrentTool('hand');
|
editor.setCurrentTool('select');
|
||||||
},
|
},
|
||||||
readonlyOk: true,
|
readonlyOk: true,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,14 @@ let cameraHistory: CameraState[] = [];
|
||||||
|
|
||||||
// Improved camera change tracking with debouncing
|
// Improved camera change tracking with debouncing
|
||||||
const trackCameraChange = (editor: Editor) => {
|
const trackCameraChange = (editor: Editor) => {
|
||||||
// Only track if not in animation
|
|
||||||
if (editor.getCameraState() === 'moving') return;
|
|
||||||
|
|
||||||
const currentCamera = editor.getCamera();
|
const currentCamera = editor.getCamera();
|
||||||
const lastPosition = cameraHistory[cameraHistory.length - 1];
|
const lastPosition = cameraHistory[cameraHistory.length - 1];
|
||||||
|
|
||||||
// Enhanced threshold check for meaningful changes
|
// Store any viewport change that's not from a revert operation
|
||||||
if (!lastPosition ||
|
if (!lastPosition ||
|
||||||
(Math.abs(lastPosition.x - currentCamera.x) > 1 ||
|
currentCamera.x !== lastPosition.x ||
|
||||||
Math.abs(lastPosition.y - currentCamera.y) > 1 ||
|
currentCamera.y !== lastPosition.y ||
|
||||||
Math.abs(lastPosition.z - currentCamera.z) > 0.1)) {
|
currentCamera.z !== lastPosition.z) {
|
||||||
|
|
||||||
cameraHistory.push({ ...currentCamera });
|
cameraHistory.push({ ...currentCamera });
|
||||||
if (cameraHistory.length > MAX_HISTORY) {
|
if (cameraHistory.length > MAX_HISTORY) {
|
||||||
cameraHistory.shift();
|
cameraHistory.shift();
|
||||||
|
|
@ -77,15 +73,16 @@ export function useCameraControls(editor: Editor | null) {
|
||||||
if (!editor) return;
|
if (!editor) return;
|
||||||
|
|
||||||
const handler = () => {
|
const handler = () => {
|
||||||
if (editor.getCameraState() !== 'moving') {
|
trackCameraChange(editor);
|
||||||
trackCameraChange(editor);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Track both viewport changes and user interaction end
|
||||||
editor.on('viewportChange' as keyof TLEventMap, handler);
|
editor.on('viewportChange' as keyof TLEventMap, handler);
|
||||||
|
editor.on('userChangeEnd' as keyof TLEventMap, handler);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
editor.off('viewportChange' as keyof TLEventMap, handler);
|
editor.off('viewportChange' as keyof TLEventMap, handler);
|
||||||
|
editor.off('userChangeEnd' as keyof TLEventMap, handler);
|
||||||
};
|
};
|
||||||
}, [editor]);
|
}, [editor]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue