Skip to content

Commit 31ecb84

Browse files
feat: add indent guide styling
1 parent da83a78 commit 31ecb84

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/extension/webview.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class SearchSidebarProvider implements vscode.WebviewViewProvider {
8585
<html lang="en">
8686
<head>
8787
<meta charset="UTF-8">
88-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8988
<link href="${stylesResetUri}" rel="stylesheet"">
9089
<link href="${stylesMainUri}" rel="stylesheet"">
9190
<link href="${stylexUri}" rel="stylesheet"">

src/webview/SearchSidebar/SearchResultList/TreeItem.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import TreeHeader from './TreeHeader'
22
import type { DisplayResult } from '../../../types'
33
import { MatchList } from './MatchList'
44
import { memo } from 'react'
5-
import { useToggleResult, useStickyShadow } from './useListState'
5+
import { useToggleResult, useStickyShadow, useActiveFile } from './useListState'
66
import * as stylex from '@stylexjs/stylex'
77

88
const styles = stylex.create({
@@ -16,11 +16,17 @@ const styles = stylex.create({
1616
top: '22px',
1717
bottom: 0,
1818
left: '13px', // left 16px - translateX 3px
19-
width: '1px',
19+
width: 0.6, // for retina screen, non-retina screen will round it to 1px
2020
backgroundColor: 'var(--vscode-tree-inactiveIndentGuidesStroke)',
2121
transition: '0.1s opacity linear',
2222
},
2323
},
24+
activeIndent: {
25+
'::before': {
26+
backgroundColor: 'var(--vscode-tree-indentGuidesStroke)',
27+
opacity: 1,
28+
},
29+
},
2430
})
2531

2632
interface TreeItemProps {
@@ -32,7 +38,11 @@ const TreeItem = ({ className, matches }: TreeItemProps) => {
3238
const filePath = matches[0].file
3339
const [isExpanded, toggleIsExpanded] = useToggleResult(filePath)
3440
const { isScrolled, ref } = useStickyShadow(filePath)
35-
const props = stylex.props(styles.treeItem)
41+
const isTreeActive = useActiveFile(matches)
42+
const props = stylex.props(
43+
styles.treeItem,
44+
isTreeActive && styles.activeIndent,
45+
)
3646

3747
return (
3848
<div className={`${className} ${props.className}`} style={props.style}>

src/webview/SearchSidebar/SearchResultList/useListState.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,20 @@ type ActiveItem = DisplayResult | DisplayResult[]
7979

8080
let activeItem: ActiveItem | null = null
8181
const refreshers: WeakMap<ActiveItem, (b: boolean) => void> = new WeakMap()
82+
const activeFiles: Map<DisplayResult[], (b: boolean) => void> = new Map()
8283

8384
function setActive(item: ActiveItem) {
8485
if (activeItem) {
8586
refreshers.get(activeItem)?.(false)
8687
}
8788
refreshers.get(item)?.(true)
8889
activeItem = item
90+
for (const [matches, update] of activeFiles) {
91+
update(isActiveFile(matches))
92+
}
8993
}
9094

95+
// is a match/file actively selected
9196
export function useActiveItem(item: ActiveItem) {
9297
const [active, forceUpdate] = useBoolean(activeItem === item)
9398
useEffect(() => {
@@ -101,3 +106,19 @@ export function useActiveItem(item: ActiveItem) {
101106
}, [item])
102107
return [active, set] as const
103108
}
109+
110+
function isActiveFile(matches: DisplayResult[]) {
111+
return matches === activeItem || matches.some(f => f === activeItem)
112+
}
113+
114+
// tell if a file is active (has a selected match or file itself selected)
115+
export function useActiveFile(matches: DisplayResult[]) {
116+
const [active, forceUpdate] = useBoolean(isActiveFile(matches))
117+
useEffect(() => {
118+
activeFiles.set(matches, forceUpdate)
119+
return () => {
120+
activeFiles.delete(matches)
121+
}
122+
}, [matches, forceUpdate])
123+
return active
124+
}

0 commit comments

Comments
 (0)