Skip to content

Commit

Permalink
[3595] Only update the selection when it really changes
Browse files Browse the repository at this point in the history
Bug: #3595
Signed-off-by: Pierre-Charles David <[email protected]>
  • Loading branch information
pcdavid authored and sbegaudeau committed Jun 10, 2024
1 parent fb35c38 commit 5592666
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
- https://github.com/eclipse-sirius/sirius-web/issues/3552[#3552] [core] Rewrite EObjectIdManager using lower-level code for performance
- https://github.com/eclipse-sirius/sirius-web/issues/3555[#3555] [core] Avoid costly recomputations in RepresentationMigrationService
- https://github.com/eclipse-sirius/sirius-web/issues/3558[#3558] [core] Avoid all representation migration overhead when not needed
- https://github.com/eclipse-sirius/sirius-web/issues/3595[#3595] [core] Avoid re-rendering the workbench when the selection does not really change

== v2024.5.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 Obeo.
* Copyright (c) 2023, 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -32,7 +32,21 @@ export const SelectionContextProvider = ({ initialSelection, children }: Selecti
});

const setSelection = useCallback((selection: Selection) => {
setState((prevState) => ({ ...prevState, selection }));
setState((prevState) => {
const prevSelectionKey = prevState.selection.entries
.map((entry) => entry.id)
.sort()
.join(':');
const newSelectionKey = selection.entries
.map((entry) => entry.id)
.sort()
.join(':');
if (prevSelectionKey !== newSelectionKey) {
return { ...prevState, selection };
} else {
return prevState;
}
});
}, []);

return (
Expand Down

0 comments on commit 5592666

Please sign in to comment.