fix(PatchHelper): Make find and match more responsive
This commit is contained in:
		
							parent
							
								
									d43731833a
								
							
						
					
					
						commit
						eac8a026a6
					
				
					 1 changed files with 4 additions and 14 deletions
				
			
		|  | @ -306,20 +306,16 @@ function PatchHelper() { | ||||||
|     }, [parsedFind, match, replacement]); |     }, [parsedFind, match, replacement]); | ||||||
| 
 | 
 | ||||||
|     function onFindChange(v: string) { |     function onFindChange(v: string) { | ||||||
|         setFindError(void 0); |  | ||||||
|         setFind(v); |         setFind(v); | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     function onFindBlur() { |  | ||||||
|         try { |         try { | ||||||
|             let parsedFind = find as string | RegExp; |             let parsedFind = v as string | RegExp; | ||||||
|             if (/^\/.+?\/$/.test(find)) parsedFind = new RegExp(find.slice(1, -1)); |             if (/^\/.+?\/$/.test(v)) parsedFind = new RegExp(v.slice(1, -1)); | ||||||
| 
 | 
 | ||||||
|             setFindError(void 0); |             setFindError(void 0); | ||||||
|             setFind(find); |  | ||||||
|             setParsedFind(parsedFind); |             setParsedFind(parsedFind); | ||||||
| 
 | 
 | ||||||
|             if (find.length) { |             if (v.length) { | ||||||
|                 findCandidates({ find: parsedFind, setModule, setError: setFindError }); |                 findCandidates({ find: parsedFind, setModule, setError: setFindError }); | ||||||
|             } |             } | ||||||
|         } catch (e: any) { |         } catch (e: any) { | ||||||
|  | @ -328,15 +324,11 @@ function PatchHelper() { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function onMatchChange(v: string) { |     function onMatchChange(v: string) { | ||||||
|         setMatchError(void 0); |  | ||||||
|         setMatch(v); |         setMatch(v); | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     function onMatchBlur() { |  | ||||||
|         try { |         try { | ||||||
|             new RegExp(match); |             new RegExp(v); | ||||||
|             setMatchError(void 0); |             setMatchError(void 0); | ||||||
|             setMatch(match); |  | ||||||
|         } catch (e: any) { |         } catch (e: any) { | ||||||
|             setMatchError((e as Error).message); |             setMatchError((e as Error).message); | ||||||
|         } |         } | ||||||
|  | @ -357,7 +349,6 @@ function PatchHelper() { | ||||||
|                 type="text" |                 type="text" | ||||||
|                 value={find} |                 value={find} | ||||||
|                 onChange={onFindChange} |                 onChange={onFindChange} | ||||||
|                 onBlur={onFindBlur} |  | ||||||
|                 error={findError} |                 error={findError} | ||||||
|             /> |             /> | ||||||
| 
 | 
 | ||||||
|  | @ -366,7 +357,6 @@ function PatchHelper() { | ||||||
|                 type="text" |                 type="text" | ||||||
|                 value={match} |                 value={match} | ||||||
|                 onChange={onMatchChange} |                 onChange={onMatchChange} | ||||||
|                 onBlur={onMatchBlur} |  | ||||||
|                 error={matchError} |                 error={matchError} | ||||||
|             /> |             /> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue