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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: select text when opening find/replace (#1516)
H. Eugene51fcb7ee0eea
diff --git a/frontend/src/components/find-replace/find-replace.tsx b/frontend/src/components/find-replace/find-replace.tsxindex bfccb6399f..05d2e2a1d1 100644--- a/frontend/src/components/find-replace/find-replace.tsx+++ b/frontend/src/components/find-replace/find-replace.tsx@@ -4,7 +4,7 @@ import {openFindReplacePanel,} from "@/core/codemirror/find-replace/state";import { useAtom } from "jotai";-import React, { useEffect, useState } from "react";+import React, { useEffect, useState, useRef } from "react";import { Input } from "../ui/input";import { Button } from "../ui/button";import {@@ -42,6 +42,7 @@ export const FindReplace: React.FC = () => {count: number;position: Map<EditorView, Map<string, number>>;}>();+ const findInputRef = useRef<HTMLInputElement>(null);useHotkey("cell.findAndReplace", () => {// if already open and focused, fallback to default behavior@@ -52,6 +53,13 @@ export const FindReplace: React.FC = () => {return openFindReplacePanel();});+ useEffect(() => {+ if (state.isOpen && findInputRef.current) {+ findInputRef.current.focus(); // Focus the input+ findInputRef.current.select(); // Select all text in the input+ }+ }, [state.isOpen]); // Depend on isOpen to trigger when the panel opens+useEffect(() => {if (!state.isOpen) {clearGlobalSearchQuery();@@ -118,6 +126,7 @@ export const FindReplace: React.FC = () => {<div className="flex items-center gap-3"><div className="flex flex-col flex-2 gap-2 w-[55%]"><Input+ ref={findInputRef} // Attach the ref heredata-testid="find-input"value={state.findText}autoFocus={true}diff --git a/frontend/src/core/codemirror/language/__tests__/utils.test.ts b/frontend/src/core/codemirror/language/__tests__/utils.test.tsindex 2e26a27f80..e9237443e4 100644--- a/frontend/src/core/codemirror/language/__tests__/utils.test.ts+++ b/frontend/src/core/codemirror/language/__tests__/utils.test.ts@@ -100,7 +100,7 @@ describe("splitEditor", () => {const result2 = splitEditor(mockEditor);expect(result2.beforeCursorCode).toEqual(- "print('Hello')\nprint('Goodbye')",+ "print('Hello')\nprint('Goodbye')");expect(result2.afterCursorCode).toEqual("");});diff --git a/frontend/src/core/codemirror/language/markdown.ts b/frontend/src/core/codemirror/language/markdown.tsindex 614ad63f31..ea41bea019 100644--- a/frontend/src/core/codemirror/language/markdown.ts+++ b/frontend/src/core/codemirror/language/markdown.ts@@ -26,7 +26,7 @@ const quoteKinds = [];// explode into all combinationsconst pairs = prefixKinds.flatMap((prefix) =>- quoteKinds.map(([start, end]) => [prefix + start, end]),+ quoteKinds.map(([start, end]) => [prefix + start, end]));const regexes = pairs.map(@@ -35,7 +35,7 @@ const regexes = pairs.map([start,new RegExp(`^mo\\.md\\(\\s*${start}(.*)${end}\\s*\\)$`, "s"),- ] as const,+ ] as const);/**@@ -155,7 +155,7 @@ export class MarkdownLanguageAdapter implements LanguageAdapter {function splitQuotePrefix(quote: string): [PrefixKind, string] {// start with the longest prefixconst prefixKindsByLength = [...prefixKinds].sort(- (a, b) => b.length - a.length,+ (a, b) => b.length - a.length);for (const prefix of prefixKindsByLength) {if (quote.startsWith(prefix)) {@@ -218,7 +218,7 @@ const emojiCompletionSource: CompletionSource = async (context) => {// everything works fine, except for autocompletion of emojisconst getEmojiList = once(async (): Promise<Completion[]> => {const emojiList = await fetch(- "https://unpkg.com/[email protected]/dist/emoji-en-US.json",+ "https://unpkg.com/[email protected]/dist/emoji-en-US.json").then((res) => res.json() as unknown as Record<string, string[]>);return Object.entries(emojiList).map(([emoji, names]) => ({