Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(edgeless): change surface selection to multi-instance #5852

Merged
merged 8 commits into from
Dec 26, 2023

Conversation

doouding
Copy link
Member

@doouding doouding commented Dec 25, 2023

close #5623

Change

Change surface selection to a multi-instance approach.

All selected canvas elements are still put into a single selection instance, but the path property now has a value equal to the path of the currently rendered surface block:

const canvasMultiSelection = block.host.selection.getInstance(
                               buildPath(surfaceBlock),
                               'surface',
                               ['canvasElement1', 'canvasElement2', 'canvasElement3' ]
                             )

Now each selected block has a corresponding selection instance, and the path property equal to its actual rendering path in edgeless. So if there are multiple blocks are selected, we'll have more than one instance:

const blockSelections = selectedBlocks.map((block) => 
                          block.host.selection.getInstance(
                            buildPath(block)
                            'surface', 
                            [block.id]
                          )
                        )

The code above is just an explanation of how the surface selection is modified. During actual development, you just
need to use the previous method edgelessPage.selectionManager.set(elements, editing). This function will automatically create the correct selection instance internally.

Now we can query the selected block view through a selection like this:

const selection = edgelessBlock
                    .selectionManager
                    .selections
                    .filter(sel => sel.elements.include(targetBlock));

const blockView = editorHost.std.view.viewFromPath('block', selection.path);

Copy link

vercel bot commented Dec 25, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
blocksuite ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 26, 2023 7:37am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
blocksuite-docs ⬜️ Ignored (Inspect) Visit Preview Dec 26, 2023 7:37am

@doouding doouding changed the title refactor(edgeless): edgeless selection manager refactor(edgeless): change surface selection to multi-instance Dec 26, 2023
@doouding doouding marked this pull request as ready for review December 26, 2023 07:41
@doodlewind doodlewind added the notable Major improvement worth emphasizing label Dec 26, 2023
@doodlewind doodlewind merged commit 8b72dc1 into master Dec 26, 2023
21 checks passed
@doodlewind doodlewind deleted the fix/edgeless-selection branch December 26, 2023 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notable Major improvement worth emphasizing
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Surface selection's path should match current selected element
2 participants