File tree Expand file tree Collapse file tree 2 files changed +7
-8
lines changed
components/diff-filtering Expand file tree Collapse file tree 2 files changed +7
-8
lines changed Original file line number Diff line number Diff line change 11<script lang =" ts" >
22 import { getFileStatusProps , MultiFileDiffViewerState } from " $lib/diff-viewer.svelte" ;
33 import { Button , Dialog , ToggleGroup } from " bits-ui" ;
4- import { tryCompileRegex , type TryCompileRegexFailure } from " $lib/util" ;
4+ import { tryCompileRegex } from " $lib/util" ;
55 import { FILE_STATUSES } from " $lib/github.svelte" ;
66 import { slide } from " svelte/transition" ;
77 import { type FilePathFilterMode } from " $lib/components/diff-filtering/index.svelte" ;
1111
1212 let newFilePathFilterElement: HTMLInputElement | undefined = $state ();
1313 let newFilePathFilterInput = $state (" " );
14- let newFilePathFilterInputResult = $derived .by (() => {
15- if (newFilePathFilterInput === " " ) {
16- return { success: false , error: " No input provided" , input: " " } satisfies TryCompileRegexFailure ;
17- }
18- return tryCompileRegex (newFilePathFilterInput );
19- });
14+ let newFilePathFilterInputResult = $derived (tryCompileRegex (newFilePathFilterInput ));
2015 $effect (() => {
2116 if (newFilePathFilterElement && newFilePathFilterInputResult .success ) {
2217 newFilePathFilterElement .setCustomValidity (" " );
Original file line number Diff line number Diff line change @@ -425,7 +425,11 @@ export type TryCompileRegexSuccess = { success: true; regex: RegExp; input: stri
425425export type TryCompileRegexFailure = { success : false ; error : string ; input : string } ;
426426export type TryCompileRegexResult = TryCompileRegexSuccess | TryCompileRegexFailure ;
427427
428- export function tryCompileRegex ( pattern : string ) : TryCompileRegexResult {
428+ export function tryCompileRegex ( pattern : string , options ?: { allowEmpty ?: boolean } ) : TryCompileRegexResult {
429+ const allowEmpty = options ?. allowEmpty ?? false ;
430+ if ( pattern === "" && ! allowEmpty ) {
431+ return { success : false , error : "Pattern cannot be empty" , input : pattern } ;
432+ }
429433 try {
430434 return { success : true , regex : new RegExp ( pattern ) , input : pattern } ;
431435 } catch ( e ) {
You can’t perform that action at this time.
0 commit comments