Skip to content

Commit 74c17a2

Browse files
feat: delete results from list
fix #166
1 parent 3283f8b commit 74c17a2

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

src/webview/SearchSidebar/SearchResultList/Actions.tsx

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import type { DisplayResult } from '../../../types'
33
import {
44
acceptChangeAndRefresh,
55
acceptFileChanges,
6+
dismissOneMatch,
7+
dismissOneFile,
68
} from '../../hooks/useSearch'
79

810
import * as stylex from '@stylexjs/stylex'
9-
import { VscReplace, VscReplaceAll } from 'react-icons/vsc'
11+
import { VscReplace, VscReplaceAll, VscClose } from 'react-icons/vsc'
1012

1113
const styles = stylex.create({
1214
list: {
@@ -33,7 +35,7 @@ const styles = stylex.create({
3335
marginLeft: '0.4em',
3436
},
3537
':last-child': {
36-
marginRight: '0.4em',
38+
marginRight: '0.2em',
3739
},
3840
},
3941
})
@@ -56,14 +58,20 @@ export function MatchActions({ className: parent, match }: ActionsProps) {
5658
],
5759
})
5860
}, [match])
59-
if (!match.replacement) {
60-
return null
61-
}
61+
const onDismiss = useCallback(() => {
62+
dismissOneMatch(match)
63+
}, [match])
6264
return (
6365
<ul className={`${local} ${parent}`} role="toolbar">
6466
{/* VSCode supports shortcut Replace (⇧⌘1)*/}
65-
<li {...stylex.props(styles.action)} onClick={onClick}>
66-
<VscReplace role="button" title="Replace" tabIndex={0} />
67+
{match.replacement ? (
68+
<li {...stylex.props(styles.action)} onClick={onClick}>
69+
<VscReplace role="button" title="Replace" tabIndex={0} />
70+
</li>
71+
) : null}
72+
{/* VSCode supports shortcut Dismiss (⌘Backspace)*/}
73+
<li {...stylex.props(styles.action)} onClick={onDismiss}>
74+
<VscClose role="button" title="Dismiss" tabIndex={0} />
6775
</li>
6876
</ul>
6977
)
@@ -88,14 +96,24 @@ export function FileActions({
8896
},
8997
[filePath],
9098
)
91-
if (!hasReplace) {
92-
return null
93-
}
99+
const onDismiss = useCallback(
100+
(e: MouseEvent<HTMLLIElement>) => {
101+
e.stopPropagation()
102+
dismissOneFile(filePath)
103+
},
104+
[filePath],
105+
)
94106
return (
95107
<ul className={`${local} ${parent}`} role="toolbar">
96108
{/* VSCode supports shortcut Replace (⇧⌘1)*/}
97-
<li {...stylex.props(styles.action)} onClick={onClick}>
98-
<VscReplaceAll role="button" title="Replace All" tabIndex={0} />
109+
{hasReplace && (
110+
<li {...stylex.props(styles.action)} onClick={onClick}>
111+
<VscReplaceAll role="button" title="Replace All" tabIndex={0} />
112+
</li>
113+
)}
114+
{/* VSCode supports shortcut Dismiss (⌘Backspace)*/}
115+
<li {...stylex.props(styles.action)} onClick={onDismiss}>
116+
<VscClose role="button" title="Dismiss" tabIndex={0} />
99117
</li>
100118
</ul>
101119
)

src/webview/hooks/useSearch.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,18 @@ export function acceptFileChanges(filePath: string) {
185185
})),
186186
})
187187
}
188+
189+
export function dismissOneMatch(match: DisplayResult) {
190+
for (const group of grouped) {
191+
if (group[0] !== match.file) {
192+
continue
193+
}
194+
group[1] = group[1].filter(m => m !== match)
195+
}
196+
grouped = [...grouped]
197+
notify()
198+
}
199+
export function dismissOneFile(filePath: string) {
200+
grouped = grouped.filter(g => g[0] !== filePath)
201+
notify()
202+
}

0 commit comments

Comments
 (0)