Skip to content

Commit c0a89b6

Browse files
Merge pull request #11283 from gitbutlerapp/dont-autofocus
Don't autofocus
2 parents ecc9845 + f8f27ff commit c0a89b6

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

apps/desktop/src/components/BranchList.svelte

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import { BASE_BRANCH_SERVICE } from '$lib/baseBranch/baseBranchService.svelte';
1616
import { MoveBranchDzHandler } from '$lib/branches/dropHandler';
1717
import { CLAUDE_CODE_SERVICE } from '$lib/codegen/claude';
18+
import { focusClaudeInput } from '$lib/codegen/focusClaudeInput';
1819
import { currentStatus } from '$lib/codegen/messages';
1920
import { projectDisableCodegen } from '$lib/config/config';
2021
import { REORDER_DROPZONE_FACTORY } from '$lib/dragging/stackingReorderDropzoneManager';
@@ -331,15 +332,7 @@
331332
if (!stackId) return;
332333
laneState?.selection.set({ branchName, codegen: true, previewOpen: true });
333334
setTimeout(() => {
334-
// This is a hacky way, but we need the job done until we
335-
// can figure out a good way of autofocusing text inputs,
336-
// without too many of them firing at the wrong times.
337-
const element = document.querySelector(
338-
`[data-id="${stackId}"] .ContentEditable__root`
339-
);
340-
if (element instanceof HTMLElement) {
341-
element?.focus();
342-
}
335+
focusClaudeInput(stackId);
343336
}, 100);
344337
}}
345338
/>

apps/desktop/src/components/codegen/CodegenInput.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@
258258
initialText={value}
259259
{onChange}
260260
onKeyDown={handleEditorKeyDown}
261+
autoFocus={false}
261262
>
262263
{#snippet plugins()}
263264
<FilePlugin
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function focusClaudeInput(stackId: string) {
2+
// This is a hacky way, but we need the job done until we
3+
// can figure out a good way of autofocusing text inputs,
4+
// without too many of them firing at the wrong times.
5+
const element = document.querySelector(`[data-id="${stackId}"] .ContentEditable__root`);
6+
if (element instanceof HTMLElement) {
7+
element?.focus();
8+
}
9+
}

apps/desktop/src/lib/stacks/createAiStack.svelte.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { focusClaudeInput } from '$lib/codegen/focusClaudeInput';
12
import { STACK_SERVICE } from '$lib/stacks/stackService.svelte';
23
import { UI_STATE } from '$lib/state/uiState.svelte';
34
import { sleep } from '$lib/utils/sleep';
@@ -26,6 +27,10 @@ export function useCreateAiStack(projectId: Reactive<string>) {
2627

2728
const lane = uiState.lane(stack.id);
2829
lane.selection.set({ codegen: true, branchName: stack.heads[0]?.name, previewOpen: true });
30+
31+
// I strongly dislike this sleep
32+
await sleep(50);
33+
focusClaudeInput(stack.id);
2934
}
3035

3136
return { createAiStack };

0 commit comments

Comments
 (0)