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

Fixed flickering #116

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/client/vanilla/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ function Editor({ standaloneServer = false }) {

// update border
const isTopHalf = isElementTopHalf(component, e)
component.style.setProperty(`border-${isTopHalf ? 'top' : 'bottom'}`, '4px solid cornflowerblue')
component.style.setProperty(`border-${!isTopHalf ? 'top' : 'bottom'}`, '')
component.style.setProperty(
'box-shadow',
isTopHalf ? ' 0px 6px 0px -2px cornflowerblue inset' : '0px -6px 0px -2px cornflowerblue inset',
)

// update hovered component
if (component.isEqualNode(hoveredComponent)) return
Expand All @@ -320,15 +322,15 @@ function Editor({ standaloneServer = false }) {
const removeBorders = () => {
const components = getComponents()
components.forEach((c: HTMLDivElement) => {
c.style.setProperty('border-top', '')
c.style.setProperty('border-bottom', '')
c.style.setProperty('box-shadow', '')
})
}

// NOTE this trigger more times than it should
const onCanvasDragLeave = () => {
setHoveredComponent(null)
removeBorders()
const onCanvasDragLeave = (e: React.DragEvent<HTMLElement>) => {
if (!canvasRef.current?.contains(e.target as HTMLElement)) {
setHoveredComponent(null)
removeBorders()
}
}

const getComponents = (): HTMLDivElement[] => {
Expand Down
Loading