Skip to content

Commit 11b0479

Browse files
committed
fix: select all text when an editor is auto-focused
1 parent b6f4bfd commit 11b0479

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

apps/builder/app/builder/shared/code-editor-base.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,20 @@ export const EditorContent = ({
289289

290290
useEffect(() => {
291291
if (autoFocus) {
292-
viewRef.current?.focus();
292+
// Select all text when editor is focused
293+
const view = viewRef.current;
294+
if (!view) {
295+
return;
296+
}
297+
view.focus();
298+
requestAnimationFrame(() => {
299+
const doc = view.state.doc;
300+
const transaction = view.state.update({
301+
selection: { anchor: 0, head: doc.length },
302+
scrollIntoView: true,
303+
});
304+
view.dispatch(transaction);
305+
});
293306
}
294307
}, [autoFocus]);
295308

0 commit comments

Comments
 (0)