@@ -77,6 +77,7 @@ const FindReplace = ({ view, defaultQuery }: FindReplaceProps) => {
77
77
78
78
// CONSTANTS
79
79
const isPreviousNextButtonDisabled = ! matchesCount . count
80
+ const isReadOnly = view . state . readOnly
80
81
81
82
// METHODS
82
83
const sendQuery = ( {
@@ -112,6 +113,12 @@ const FindReplace = ({ view, defaultQuery }: FindReplaceProps) => {
112
113
setMatchesCount ( getUpdatedSearchMatchesCount ( defaultQuery , view ) )
113
114
} , [ view . state . doc . length ] )
114
115
116
+ useEffect ( ( ) => {
117
+ if ( isReadOnly && showReplace ) {
118
+ setShowReplace ( false )
119
+ }
120
+ } , [ isReadOnly ] )
121
+
115
122
const onNext = ( e ?: MouseEvent < HTMLButtonElement > ) => {
116
123
e ?. preventDefault ( )
117
124
e ?. stopPropagation ( )
@@ -386,7 +393,7 @@ const FindReplace = ({ view, defaultQuery }: FindReplaceProps) => {
386
393
387
394
return (
388
395
< div className = "flexbox dc__align-items-center dc__gap-6" >
389
- { ! view . state . readOnly && renderReplaceShowButton ( ) }
396
+ { ! isReadOnly && renderReplaceShowButton ( ) }
390
397
< div className = "flexbox-col dc__gap-4" >
391
398
< div className = "flexbox dc__align-items-center dc__gap-8" >
392
399
{ renderFindField ( ) }
@@ -425,7 +432,7 @@ export const codeEditorFindReplace = (view: EditorView): Panel => {
425
432
findField ?. select ( )
426
433
}
427
434
428
- const update = ( { transactions, docChanged } : ViewUpdate ) => {
435
+ const update = ( { transactions, changes } : ViewUpdate ) => {
429
436
transactions . forEach ( ( tr ) => {
430
437
tr . effects . forEach ( ( effect ) => {
431
438
if ( effect . is ( setSearchQuery ) ) {
@@ -434,7 +441,7 @@ export const codeEditorFindReplace = (view: EditorView): Panel => {
434
441
} )
435
442
} )
436
443
437
- if ( docChanged ) {
444
+ if ( changes ) {
438
445
renderFindReplace ( )
439
446
}
440
447
}
0 commit comments