1- /* eslint max-lines: ["error", 350] */
1+ /* eslint max-lines: ["error", 400] */
2+ /* eslint max-lines-per-function: ["error", 180] */
3+ /* eslint max-statements: ["error", 25] */
24import {
35 useCallback ,
46 useEffect ,
@@ -9,6 +11,7 @@ import {
911import { useColorScheme } from "@mui/joy" ;
1012import * as monaco from "monaco-editor/esm/vs/editor/editor.api.js" ;
1113
14+ import useQueryStore from "../../stores/queryStore" ;
1215import useViewStore from "../../stores/viewStore" ;
1316import { Nullable } from "../../typings/common" ;
1417import {
@@ -187,6 +190,9 @@ const Editor = () => {
187190 const beginLineNumToLogEventNum = useViewStore ( ( state ) => state . beginLineNumToLogEventNum ) ;
188191 const logData = useViewStore ( ( state ) => state . logData ) ;
189192 const logEventNum = useViewStore ( ( state ) => state . logEventNum ) ;
193+ const queryString = useQueryStore ( ( state ) => state . queryString ) ;
194+ const queryIsCaseSensitive = useQueryStore ( ( state ) => state . queryIsCaseSensitive ) ;
195+ const queryIsRegex = useQueryStore ( ( state ) => state . queryIsRegex ) ;
190196
191197 const [ lineNum , setLineNum ] = useState < number > ( 1 ) ;
192198 const beginLineNumToLogEventNumRef = useRef < BeginLineNumToLogEventNumMap > (
@@ -195,6 +201,9 @@ const Editor = () => {
195201 const editorRef = useRef < Nullable < monaco . editor . IStandaloneCodeEditor > > ( null ) ;
196202 const isMouseDownRef = useRef < boolean > ( false ) ;
197203 const pageSizeRef = useRef ( getConfig ( CONFIG_KEY . PAGE_SIZE ) ) ;
204+ const searchDecorationsCollectionRef = useRef <
205+ Nullable < monaco . editor . IEditorDecorationsCollection >
206+ > ( null ) ;
198207
199208 /**
200209 * Sets `editorRef` and configures callbacks for mouse down detection.
@@ -271,6 +280,44 @@ const Editor = () => {
271280 beginLineNumToLogEventNumRef . current = beginLineNumToLogEventNum ;
272281 } , [ beginLineNumToLogEventNum ] ) ;
273282
283+ // On `logData`, `queryString`, `queryIsCaseSensitive`, or `queryIsRegex` update, highlight any
284+ // matches.
285+ useEffect ( ( ) => {
286+ if ( null === editorRef . current ) {
287+ return ;
288+ }
289+ searchDecorationsCollectionRef . current ?. clear ( ) ;
290+
291+ const matches = editorRef . current
292+ . getModel ( )
293+ ?. findMatches (
294+ queryString ,
295+ false ,
296+ queryIsRegex ,
297+ queryIsCaseSensitive ,
298+ null ,
299+ false ,
300+ Infinity
301+ ) ;
302+
303+ if ( "undefined" === typeof matches || 0 === matches . length ) {
304+ return ;
305+ }
306+ searchDecorationsCollectionRef . current = editorRef . current . createDecorationsCollection (
307+ matches . map ( ( { range} ) => ( {
308+ range : range ,
309+ options : {
310+ className : "findMatch" ,
311+ } ,
312+ } ) )
313+ ) ;
314+ } , [
315+ logData ,
316+ queryString ,
317+ queryIsCaseSensitive ,
318+ queryIsRegex ,
319+ ] ) ;
320+
274321 // On `logEventNum` update, update line number in the editor.
275322 useEffect ( ( ) => {
276323 if ( null === editorRef . current || isMouseDownRef . current ) {
0 commit comments