offset drop point by editor client rect (#1564)

In my app, I have a sidebar and noticed that dropped shapes were being
created at an offset by the sidebar's width. This is because the current
point given to `putExternalContent` does not offset by the editor's
client rect.
This commit is contained in:
Brian Hung 2023-06-12 08:23:15 -07:00 committed by GitHub
parent 1927f88041
commit 8d409462c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -106,10 +106,12 @@ export function useCanvasEvents() {
(file) => !file.name.endsWith('.tldr')
)
const rect = editor.getContainer().getBoundingClientRect()
await editor.putExternalContent({
type: 'files',
files,
point: editor.screenToPage(e.clientX, e.clientY),
point: editor.screenToPage(e.clientX - rect.x, e.clientY - rect.y),
ignoreParent: false,
})
}