Skip to content

Commit cb334a0

Browse files
committed
fix: CodeEditor - find and replace - hide replace for readOnly mode
1 parent d31c659 commit cb334a0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Common/CodeEditor/Extensions/findAndReplace.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const FindReplace = ({ view, defaultQuery }: FindReplaceProps) => {
7777

7878
// CONSTANTS
7979
const isPreviousNextButtonDisabled = !matchesCount.count
80+
const isReadOnly = view.state.readOnly
8081

8182
// METHODS
8283
const sendQuery = ({
@@ -112,6 +113,12 @@ const FindReplace = ({ view, defaultQuery }: FindReplaceProps) => {
112113
setMatchesCount(getUpdatedSearchMatchesCount(defaultQuery, view))
113114
}, [view.state.doc.length])
114115

116+
useEffect(() => {
117+
if (isReadOnly && showReplace) {
118+
setShowReplace(false)
119+
}
120+
}, [isReadOnly])
121+
115122
const onNext = (e?: MouseEvent<HTMLButtonElement>) => {
116123
e?.preventDefault()
117124
e?.stopPropagation()
@@ -386,7 +393,7 @@ const FindReplace = ({ view, defaultQuery }: FindReplaceProps) => {
386393

387394
return (
388395
<div className="flexbox dc__align-items-center dc__gap-6">
389-
{!view.state.readOnly && renderReplaceShowButton()}
396+
{!isReadOnly && renderReplaceShowButton()}
390397
<div className="flexbox-col dc__gap-4">
391398
<div className="flexbox dc__align-items-center dc__gap-8">
392399
{renderFindField()}
@@ -425,7 +432,7 @@ export const codeEditorFindReplace = (view: EditorView): Panel => {
425432
findField?.select()
426433
}
427434

428-
const update = ({ transactions, docChanged }: ViewUpdate) => {
435+
const update = ({ transactions, changes }: ViewUpdate) => {
429436
transactions.forEach((tr) => {
430437
tr.effects.forEach((effect) => {
431438
if (effect.is(setSearchQuery)) {
@@ -434,7 +441,7 @@ export const codeEditorFindReplace = (view: EditorView): Panel => {
434441
})
435442
})
436443

437-
if (docChanged) {
444+
if (changes) {
438445
renderFindReplace()
439446
}
440447
}

0 commit comments

Comments
 (0)