Skip to content

Commit a7549be

Browse files
chore: remove hover hacks
1 parent b737803 commit a7549be

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

src/webview/SearchSidebar/SearchResultList/Actions.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ const styles = stylex.create({
1515
listStyle: 'none',
1616
display: 'flex',
1717
flexDirection: 'row',
18-
// see https://github.com/facebook/stylex/issues/373
19-
width: '0',
2018
overflow: 'hidden',
2119
},
2220
action: {
@@ -42,12 +40,10 @@ const styles = stylex.create({
4240
})
4341

4442
interface ActionsProps {
45-
className: string
4643
match: DisplayResult
4744
}
4845

49-
export function MatchActions({ className: parent, match }: ActionsProps) {
50-
const { className: local } = stylex.props(styles.list)
46+
export function MatchActions({ match }: ActionsProps) {
5147
const onClick = useCallback(() => {
5248
acceptChangeAndRefresh({
5349
filePath: match.file,
@@ -63,7 +59,7 @@ export function MatchActions({ className: parent, match }: ActionsProps) {
6359
dismissOneMatch(match)
6460
}, [match])
6561
return (
66-
<ul className={`${local} ${parent}`} role="toolbar">
62+
<ul {...stylex.props(styles.list)} role="toolbar">
6763
{/* VSCode supports shortcut Replace (⇧⌘1)*/}
6864
{match.replacement ? (
6965
<li {...stylex.props(styles.action)} onClick={onClick}>
@@ -79,17 +75,11 @@ export function MatchActions({ className: parent, match }: ActionsProps) {
7975
}
8076

8177
interface FileActionsProps {
82-
className: string
8378
filePath: string
8479
hasReplace: boolean
8580
}
8681

87-
export function FileActions({
88-
className: parent,
89-
filePath,
90-
hasReplace,
91-
}: FileActionsProps) {
92-
const { className: local } = stylex.props(styles.list)
82+
export function FileActions({ filePath, hasReplace }: FileActionsProps) {
9383
const onClick = useCallback(
9484
(e: MouseEvent<HTMLLIElement>) => {
9585
e.stopPropagation()
@@ -105,7 +95,7 @@ export function FileActions({
10595
[filePath],
10696
)
10797
return (
108-
<ul className={`${local} ${parent}`} role="toolbar">
98+
<ul {...stylex.props(styles.list)} role="toolbar">
10999
{/* VSCode supports shortcut Replace (⇧⌘1)*/}
110100
{hasReplace && (
111101
<li {...stylex.props(styles.action)} onClick={onClick}>

src/webview/SearchSidebar/SearchResultList/MatchList.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CodeBlock } from './CodeBlock'
22
import { MatchActions } from './Actions'
33
import type { DisplayResult } from '../../../types'
4+
import { useHover } from 'react-use'
45

56
import { memo } from 'react'
67
import * as stylex from '@stylexjs/stylex'
@@ -13,14 +14,21 @@ const styles = stylex.create({
1314
':hover': {
1415
background: 'var( --vscode-list-hoverBackground)',
1516
},
16-
// a hack to avoid setHover state, see also Actions.tsx
17-
// https://github.com/facebook/stylex/issues/373
18-
':hover > .actions': {
19-
width: 'auto',
20-
},
2117
},
2218
})
2319

20+
function OneMatch({ match }: { match: DisplayResult }) {
21+
const [hoverable] = useHover(hovered => {
22+
return (
23+
<li {...stylex.props(styles.codeItem)}>
24+
<CodeBlock match={match} />
25+
{hovered && <MatchActions match={match} />}
26+
</li>
27+
)
28+
})
29+
return hoverable
30+
}
31+
2432
interface CodeBlockListProps {
2533
matches: DisplayResult[]
2634
}
@@ -30,15 +38,8 @@ export const MatchList = memo(({ matches }: CodeBlockListProps) => {
3038
{matches?.map(match => {
3139
const { file, range } = match
3240
const { byteOffset } = range
33-
return (
34-
<li
35-
{...stylex.props(styles.codeItem)}
36-
key={file + byteOffset.start + byteOffset.end}
37-
>
38-
<CodeBlock match={match} />
39-
<MatchActions className="actions" match={match} />
40-
</li>
41-
)
41+
const key = file + byteOffset.start + byteOffset.end
42+
return <OneMatch key={key} match={match} />
4243
})}
4344
</>
4445
)

src/webview/SearchSidebar/SearchResultList/TreeHeader.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ const styles = stylex.create({
2222
':hover': {
2323
background: 'var( --vscode-list-hoverBackground)',
2424
},
25-
':hover > .actions': {
26-
width: 'auto',
27-
},
2825
},
2926
scrolled: {
3027
boxShadow: 'var(--vscode-scrollbar-shadow) 0 0 6px',
@@ -70,11 +67,7 @@ export default function TreeHeader({
7067
</div>
7168
<FileLink filePath={filePath} />
7269
{hovered ? (
73-
<FileActions
74-
className="actions"
75-
filePath={filePath}
76-
hasReplace={hasReplace}
77-
/>
70+
<FileActions filePath={filePath} hasReplace={hasReplace} />
7871
) : (
7972
<VSCodeBadge {...stylex.props(styles.badge)}>
8073
{matches.length}

0 commit comments

Comments
 (0)