-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consistent border radii for navigator selection (#5928)
**Problem:** Selected rows in the navigator have inconsistent / potato border radii applied to pretty much any selected row. Moreover, the children selection also does not have any border radius. **Fix:** Contiguous regions of selection now share just 4 rounded corners. This is done with a hook which is used on both the regular and the condensed navigator rows, so they share all the underlying logic to figure out which element should have `borderRadius` applied or not. Note: there's a reasonable chance there will be corner (pun intended) cases here and there, but it feels decently solid. <img width="926" alt="Screenshot 2024-06-13 at 4 08 41 PM" src="https://github.com/concrete-utopia/utopia/assets/1081051/eee83821-3302-46e5-a98d-9d1f4bd9e6bc"> **Manual Tests:** I hereby swear that: - [x] I opened a hydrogen project and it loaded - [x] I could navigate to various routes in Preview mode Fixes #5927
- Loading branch information
Showing
3 changed files
with
156 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
77 changes: 77 additions & 0 deletions
77
editor/src/components/navigator/navigator-item/use-navigator-selection-bounds-for-entry.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React from 'react' | ||
import * as EP from '../../../core/shared/element-path' | ||
import type { NavigatorEntry } from '../../editor/store/editor-state' | ||
import { Substores, useEditorState } from '../../editor/store/store-hook' | ||
import { isRegulaNavigatorRow } from '../navigator-row' | ||
|
||
export function useNavigatorSelectionBoundsForEntry( | ||
navigatorEntry: NavigatorEntry, | ||
selected: boolean, | ||
childComponentCount: number, | ||
): { | ||
isTopOfSelection: boolean | ||
isBottomOfSelection: boolean | ||
} { | ||
const selectedViews = useEditorState( | ||
Substores.selectedViews, | ||
(store) => store.editor.selectedViews, | ||
'useNavigatorSelectionBoundsCheck selectedViews', | ||
) | ||
|
||
const navigatorRowsPaths = useEditorState( | ||
Substores.derived, | ||
(store) => { | ||
return store.derived.navigatorRows.map((row) => | ||
isRegulaNavigatorRow(row) ? row.entry.elementPath : row.entries[0].elementPath, | ||
) | ||
}, | ||
'useNavigatorSelectionBoundsCheck navigatorRowsPaths', | ||
) | ||
|
||
const collapsedViews = useEditorState( | ||
Substores.navigator, | ||
(store) => { | ||
return store.editor.navigator.collapsedViews | ||
}, | ||
'useNavigatorSelectionBoundsCheck collapsedViews', | ||
) | ||
|
||
return React.useMemo(() => { | ||
const index = navigatorRowsPaths.findIndex((view) => | ||
EP.pathsEqual(view, navigatorEntry.elementPath), | ||
) | ||
|
||
const previous = index > 0 ? navigatorRowsPaths.at(index - 1) : null | ||
const next = index < navigatorRowsPaths.length - 1 ? navigatorRowsPaths.at(index + 1) : null | ||
|
||
const isDangling = | ||
childComponentCount === 0 || collapsedViews.includes(navigatorEntry.elementPath) | ||
|
||
const isTopOfSelection = | ||
previous == null || | ||
(!selectedViews.some( | ||
(view) => | ||
EP.pathsEqual(view, previous) || | ||
EP.isDescendantOf(EP.parentPath(navigatorEntry.elementPath), view) || | ||
EP.isDescendantOf(previous, view), | ||
) && | ||
selected) | ||
|
||
const isBottomOfSelection = | ||
next == null || | ||
((!selected || isDangling) && | ||
!selectedViews.some((view) => EP.pathsEqual(view, next) || EP.isDescendantOf(next, view))) | ||
|
||
return { | ||
isTopOfSelection: isTopOfSelection, | ||
isBottomOfSelection: isBottomOfSelection, | ||
} | ||
}, [ | ||
navigatorRowsPaths, | ||
navigatorEntry, | ||
selectedViews, | ||
selected, | ||
childComponentCount, | ||
collapsedViews, | ||
]) | ||
} |