Fix 'style panel doesn't always disappear if you switch to the hand/laser tools' (#2886)

We had some bad logic in `useRelevantStyles` explicitly allowing an
opacity-slider to be rendered at all times when there is at least one
shape selected.

This shouldn't be the case when the editor is in non-shape-focused tools
like the move tool and the laser pointer tool. I refactored the hook
slightly to make it easier to express the correct logic. See the comment
for a more detailed description.

### Change Type

- [x] `patch` — Bug fix


[^1]: publishes a `patch` release, for devDependencies use `internal`
[^2]: will not publish a new version


### Release Notes

- Fixes an bug causing the opacity slider to show up in the move tool
and laser pointer tool.
This commit is contained in:
David Sheldrick 2024-02-20 15:09:45 +00:00 committed by GitHub
parent 9b65b0e20f
commit 3e12b27728
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 30 additions and 25 deletions

View file

@ -7168,19 +7168,17 @@ export class Editor extends EventEmitter<TLEventMap> {
*
* @internal
*/
private _selectionSharedStyles = computed<ReadonlySharedStyleMap>(
'_selectionSharedStyles',
() => {
const selectedShapes = this.getSelectedShapes()
@computed
private _getSelectionSharedStyles(): ReadonlySharedStyleMap {
const selectedShapes = this.getSelectedShapes()
const sharedStyles = new SharedStyleMap()
for (const selectedShape of selectedShapes) {
this._extractSharedStyles(selectedShape, sharedStyles)
}
return sharedStyles
const sharedStyles = new SharedStyleMap()
for (const selectedShape of selectedShapes) {
this._extractSharedStyles(selectedShape, sharedStyles)
}
)
return sharedStyles
}
/** @internal */
getStyleForNextShape<T>(style: StyleProp<T>): T {
@ -7213,7 +7211,7 @@ export class Editor extends EventEmitter<TLEventMap> {
// If we're in selecting and if we have a selection, return the shared styles from the
// current selection
if (this.isIn('select') && this.getSelectedShapeIds().length > 0) {
return this._selectionSharedStyles.get()
return this._getSelectionSharedStyles()
}
// If the current tool is associated with a shape, return the styles for that shape.