tldraw
tldraw copied to clipboard
[Feature]: (API) Get shapes from other page & moveShapesToPage to not change page
What's the feature?
The editor instance has a method to editor.moveShapesToPage(...) As noted in the forum discussion below, this doesn't only move shapes to that page, but also changes the editor to that page.
A work around is shown here
editor.batch(() => {
const pageId = editor.getCurrentPageId()
editor.moveShapesToPage(...)
editor.setCurrentPageId(pageId)
})
However, in some instances this causes issues. In my setup, as the user begins drawing, I immediately move some records to another page. This is actually an optimisation step for me as the canvas can be heavy and slow down responsiveness while drawing (Less noticeable in other tasks).
There is no visual page change using the above fix (It appears as though the page remains the same and the drawing continues), however, because the page changes and changes back, The pen line jumps to a random position and then back, leaving a large streak across the page.
Similarly, when the user begins moving the camera, I bring all shapes back to the current page, however, there's no way to access the shapes to do this without the below approach (I believe):
editor.batch( () => {
const curPageId = editor.currentPageId;
editor.setCurrentPage(stashPage);
allStashShapes = editor.currentPageShapes;
editor.moveShapesToPage(allStashShapes, curPageId);
})
However, while the page doesn't appear to change, the camera position jumps due to the change and change back. Making what could be seamless, to something unusable.
So... It would be more versatile in instances like these, if editor.moveShapesToPage(...) didn't automatically change the page, and if there was a way to get shapes from another page without changing to it.
Note, I brought the moveShapesToPage comment up on discord at this link where Steve replied: https://discord.com/channels/859816885297741824/926464446694580275/1182275012653228113
Contact Details
Code of Conduct
- [X] I agree to follow this project's Code of Conduct