@@ -78,6 +78,21 @@ childPort.onMessage('error', event => {
7878 notify ( )
7979} )
8080
81+ childPort . onMessage ( 'refreshSearchResult' , event => {
82+ if ( event . id !== id ) {
83+ return
84+ }
85+ const { fileName, updatedResults } = event
86+ const temp = new Map ( grouped )
87+ if ( updatedResults . length === 0 ) {
88+ temp . delete ( fileName )
89+ } else {
90+ temp . set ( fileName , updatedResults )
91+ }
92+ grouped = [ ...temp . entries ( ) ]
93+ notify ( )
94+ } )
95+
8196function groupBy ( matches : DisplayResult [ ] ) {
8297 const groups = new Map < string , DisplayResult [ ] > ( )
8398 for ( const match of matches ) {
@@ -99,6 +114,18 @@ function merge(newEntries: Map<string, DisplayResult[]>) {
99114 return [ ...temp . entries ( ) ]
100115}
101116
117+ function updateResult ( newEntries : Map < string , DisplayResult [ ] > ) {
118+ // first, clone the old map for react
119+ for ( const [ fileName , results ] of newEntries ) {
120+ if ( results . length === 0 ) {
121+ temp . delete ( fileName )
122+ } else {
123+ temp . set ( fileName , results )
124+ }
125+ }
126+ return [ ...temp . entries ( ) ]
127+ }
128+
102129// version is for react to update view
103130let version = 114514
104131function subscribe ( onChange : ( ) => void ) : ( ) => void {
@@ -143,22 +170,11 @@ export const useSearchResult = () => {
143170}
144171export { postSearch }
145172
146- function clearOneFile ( file : string ) {
147- const pairs = grouped . find ( n => n [ 0 ] === file )
148- if ( ! pairs ) {
149- return
150- }
151- pairs [ 1 ] = [ ]
152- grouped = grouped . slice ( )
153- notify ( )
154- }
155-
156173export function acceptChangeAndRefresh ( args : {
157174 filePath : string
158175 replacement : string
159176 range : RangeInfo
160177} ) {
161- clearOneFile ( args . filePath )
162178 commitChange ( {
163179 id,
164180 ...queryInFlight ,
0 commit comments