Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: allow to replace with empty, and reset matches after replace (#3559)

Shahmir Varqhae0047af677d6
diff --git a/frontend/src/components/find-replace/find-replace.tsx b/frontend/src/components/find-replace/find-replace.tsx
index 63e892eff3..9fbd0c7f24 100644
--- a/frontend/src/components/find-replace/find-replace.tsx
+++ b/frontend/src/components/find-replace/find-replace.tsx
@@ -56,6 +56,12 @@ export const FindReplace: React.FC = () => {
return openFindReplacePanel();
});
+ const resetMatches = () => {
+ const matches = getMatches();
+ // False count means an invalid regex
+ setMatches(matches === false ? undefined : matches);
+ };
+
useEffect(() => {
if (state.isOpen && findInputRef.current) {
findInputRef.current.focus(); // Focus the input
@@ -75,9 +81,7 @@ export const FindReplace: React.FC = () => {
return;
}
- const matches = getMatches();
- // False count means an invalid regex
- setMatches(matches === false ? undefined : matches);
+ resetMatches();
setGlobalSearchQuery();
}, [
// Re-search when any of these change
@@ -205,8 +209,10 @@ export const FindReplace: React.FC = () => {
size="xs"
variant="outline"
className="h-6 text-xs"
- onClick={() => replaceNext()}
- disabled={state.findText === "" || state.replaceText === ""}
+ onClick={() => {
+ replaceNext() && resetMatches();
+ }}
+ disabled={state.findText === ""}
>
Replace Next
</Button>
@@ -220,6 +226,7 @@ export const FindReplace: React.FC = () => {
if (!undo) {
return;
}
+ resetMatches();
// Show toast with undo button
const { dismiss } = toast({
@@ -235,7 +242,7 @@ export const FindReplace: React.FC = () => {
),
});
}}
- disabled={state.findText === "" || state.replaceText === ""}
+ disabled={state.findText === ""}
>
Replace All
</Button>