mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
Ensure that invalid search regexp is correctly highlighted (#28724)
GitOrigin-RevId: f122e2ea649d8cbfa984ddad0b7424aa96bd015a
This commit is contained in:
@@ -37,6 +37,7 @@ import { debounce } from 'lodash'
|
||||
import { EditorSelection, EditorState } from '@codemirror/state'
|
||||
import { sendSearchEvent } from '@/features/event-tracking/search-events'
|
||||
import { FullProjectSearchButton } from './full-project-search-button'
|
||||
import { isInvalidRegExp } from '../utils/regexp'
|
||||
|
||||
const MATCH_COUNT_DEBOUNCE_WAIT = 100 // the amount of ms to wait before counting matches
|
||||
const MAX_MATCH_COUNT = 999 // the maximum number of matches to count
|
||||
@@ -253,8 +254,7 @@ const CodeMirrorSearchForm: FC<React.PropsWithChildren> = () => {
|
||||
<div className="ol-cm-search-controls">
|
||||
<span
|
||||
className={classnames('ol-cm-search-input-group', {
|
||||
'ol-cm-search-input-error':
|
||||
query.regexp && isInvalidRegExp(query.search),
|
||||
'ol-cm-search-input-error': query.regexp && isInvalidRegExp(query),
|
||||
})}
|
||||
>
|
||||
<OLFormControl
|
||||
@@ -495,15 +495,6 @@ const CodeMirrorSearchForm: FC<React.PropsWithChildren> = () => {
|
||||
)
|
||||
}
|
||||
|
||||
function isInvalidRegExp(source: string) {
|
||||
try {
|
||||
RegExp(source)
|
||||
return false
|
||||
} catch {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
export default CodeMirrorSearchForm
|
||||
|
||||
const buildPosition = debounce(
|
||||
|
||||
@@ -5,3 +5,12 @@ export const createRegExp = (searchQuery: SearchQuery) => {
|
||||
|
||||
return new RegExp(searchQuery.search, flags)
|
||||
}
|
||||
|
||||
export const isInvalidRegExp = (searchQuery: SearchQuery): boolean => {
|
||||
try {
|
||||
createRegExp(searchQuery)
|
||||
return false
|
||||
} catch {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import { FullProjectSearchModifiers } from './full-project-search-modifiers'
|
||||
import { isMac } from '@/shared/utils/os'
|
||||
import { PanelHeading } from '@/shared/components/panel-heading'
|
||||
import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
|
||||
import { createRegExp } from '../util/regexp'
|
||||
import { createRegExp } from '@/features/source-editor/utils/regexp'
|
||||
import { useEditorOpenDocContext } from '@/features/ide-react/context/editor-open-doc-context'
|
||||
import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-path'
|
||||
import { FullProjectSearchResults } from './full-project-search-results'
|
||||
|
||||
Reference in New Issue
Block a user