Skip to content

Commit

Permalink
chore: remove hover hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
HerringtonDarkholme committed Mar 10, 2024
1 parent b737803 commit a7549be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 36 deletions.
18 changes: 4 additions & 14 deletions src/webview/SearchSidebar/SearchResultList/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ const styles = stylex.create({
listStyle: 'none',
display: 'flex',
flexDirection: 'row',
// see https://github.com/facebook/stylex/issues/373
width: '0',
overflow: 'hidden',
},
action: {
Expand All @@ -42,12 +40,10 @@ const styles = stylex.create({
})

interface ActionsProps {
className: string
match: DisplayResult
}

export function MatchActions({ className: parent, match }: ActionsProps) {
const { className: local } = stylex.props(styles.list)
export function MatchActions({ match }: ActionsProps) {
const onClick = useCallback(() => {
acceptChangeAndRefresh({
filePath: match.file,
Expand All @@ -63,7 +59,7 @@ export function MatchActions({ className: parent, match }: ActionsProps) {
dismissOneMatch(match)
}, [match])
return (
<ul className={`${local} ${parent}`} role="toolbar">
<ul {...stylex.props(styles.list)} role="toolbar">
{/* VSCode supports shortcut Replace (⇧⌘1)*/}
{match.replacement ? (
<li {...stylex.props(styles.action)} onClick={onClick}>
Expand All @@ -79,17 +75,11 @@ export function MatchActions({ className: parent, match }: ActionsProps) {
}

interface FileActionsProps {
className: string
filePath: string
hasReplace: boolean
}

export function FileActions({
className: parent,
filePath,
hasReplace,
}: FileActionsProps) {
const { className: local } = stylex.props(styles.list)
export function FileActions({ filePath, hasReplace }: FileActionsProps) {
const onClick = useCallback(
(e: MouseEvent<HTMLLIElement>) => {
e.stopPropagation()
Expand All @@ -105,7 +95,7 @@ export function FileActions({
[filePath],
)
return (
<ul className={`${local} ${parent}`} role="toolbar">
<ul {...stylex.props(styles.list)} role="toolbar">
{/* VSCode supports shortcut Replace (⇧⌘1)*/}
{hasReplace && (
<li {...stylex.props(styles.action)} onClick={onClick}>
Expand Down
29 changes: 15 additions & 14 deletions src/webview/SearchSidebar/SearchResultList/MatchList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CodeBlock } from './CodeBlock'
import { MatchActions } from './Actions'
import type { DisplayResult } from '../../../types'
import { useHover } from 'react-use'

import { memo } from 'react'
import * as stylex from '@stylexjs/stylex'
Expand All @@ -13,14 +14,21 @@ const styles = stylex.create({
':hover': {
background: 'var( --vscode-list-hoverBackground)',
},
// a hack to avoid setHover state, see also Actions.tsx
// https://github.com/facebook/stylex/issues/373
':hover > .actions': {
width: 'auto',
},
},
})

function OneMatch({ match }: { match: DisplayResult }) {
const [hoverable] = useHover(hovered => {
return (
<li {...stylex.props(styles.codeItem)}>
<CodeBlock match={match} />
{hovered && <MatchActions match={match} />}
</li>
)
})
return hoverable
}

interface CodeBlockListProps {
matches: DisplayResult[]
}
Expand All @@ -30,15 +38,8 @@ export const MatchList = memo(({ matches }: CodeBlockListProps) => {
{matches?.map(match => {
const { file, range } = match
const { byteOffset } = range
return (
<li
{...stylex.props(styles.codeItem)}
key={file + byteOffset.start + byteOffset.end}
>
<CodeBlock match={match} />
<MatchActions className="actions" match={match} />
</li>
)
const key = file + byteOffset.start + byteOffset.end
return <OneMatch key={key} match={match} />
})}
</>
)
Expand Down
9 changes: 1 addition & 8 deletions src/webview/SearchSidebar/SearchResultList/TreeHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ const styles = stylex.create({
':hover': {
background: 'var( --vscode-list-hoverBackground)',
},
':hover > .actions': {
width: 'auto',
},
},
scrolled: {
boxShadow: 'var(--vscode-scrollbar-shadow) 0 0 6px',
Expand Down Expand Up @@ -70,11 +67,7 @@ export default function TreeHeader({
</div>
<FileLink filePath={filePath} />
{hovered ? (
<FileActions
className="actions"
filePath={filePath}
hasReplace={hasReplace}
/>
<FileActions filePath={filePath} hasReplace={hasReplace} />
) : (
<VSCodeBadge {...stylex.props(styles.badge)}>
{matches.length}
Expand Down

0 comments on commit a7549be

Please sign in to comment.