fix(GraphPlayground): skip editor updates for multi-block selections#223
Open
180107072 wants to merge 1 commit intogravity-ui:mainfrom
Open
fix(GraphPlayground): skip editor updates for multi-block selections#223180107072 wants to merge 1 commit intogravity-ui:mainfrom
180107072 wants to merge 1 commit intogravity-ui:mainfrom
Conversation
Author
|
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=ru. |
Contributor
|
Preview is ready. |
Collaborator
|
Hi, thanks for your contribution. I have looked at your suggestion and have some ideas. The fact is that when dragging blocks the updateBlocks() method is called on each block individually, so the current change doesn't affect the mass drag of blocks - the events are triggered for each block separately. Therefore, to solve this problem, you need to accumulate the blocks currently in the drag state, but the event block-changed is not suitable because of the granularity of changes.
graph.addEventListener('block-changed', () => { // listen for changes to one block only
// do something with the block
});Instead, I Instead of using events, I would suggest using the DragService state to calculate the list of dragged blocks. Here's an example: const lastDraggedBlocks = React.useRef<Array<TBlock>>([]);
useEffect(() => { // run this effect every time the graph changes
graph.dragService.state.subscribe(value => {
// at the end of a drag, update blocks in editor
if (!value?.isDragging) { // if no longer dragging
if (lastDraggedBlocks.current) { // check if we have any blocks
editorRef?.updateBlocks(...lastDragged); // update editor with blocks
lastDragged.current = []; // clear list
}
} else { // during drag
const blocks = value?.components?.filter(c => c instanceof TBlock); // get blocks from drag
lastDragged?.current = blocks?.map(b => b?.connectedState?.value); // add to list
// if only one block, update editor
if(blocks?.length === 1){
const state = blocks?.[0]?.connectedState.value; // get state of block
editor?.updateBlocks?.([state]) // update editor
editor.scrollTo?.(state?.id) // scroll to block
}
}
});
}, [graph])In this approach, it is easier to calculate the blocks in the drag state and correctly process the editor updates. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
freezes when selecting 10 000 blocks
Why it happens
findBlockPositionsMonacoperforms document search for each blockSolution
skip editor updates when updating multiple blocks editor highlighting only works for single selections