Skip to content

Commit 189a221

Browse files
author
Smartie
committed
Place navigation autofocus caret at restored draft end
Signed-off-by: Smartie <fb3185faacfc3760b6b4fe0085a8878d8dd537f7a7671c7d3184fe1aa1b04df4@buzz.block.builderlab.xyz>
1 parent f6c5e2e commit 189a221

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎src/features/messages/MessageComposer.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,13 @@ function Composer({
218218
previous &&
219219
(previous === document.activeElement ||
220220
(!previous.isConnected && document.activeElement === document.body))
221-
)
222-
input.current?.focus();
221+
) {
222+
const editor = input.current;
223+
if (!editor) return;
224+
const end = editor.value.length;
225+
editor.setSelectionRange(end, end);
226+
editor.focus();
227+
}
223228
}, []);
224229
const nonmembers = useNonmemberMentions(session, channelId, () =>
225230
input.current?.focus(),

‎tests/browser/composer-focus.spec.mjs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ test("selecting a channel or DM focuses its composer and retains drafts", async
2323
await expect(input).toBeFocused();
2424
if (index < 2) {
2525
await page.keyboard.type(`Draft for ${name}`);
26+
await expect(input).toHaveText(`Draft for ${name}`);
27+
} else {
28+
await expect(input).toHaveText(`Draft for ${name}`);
29+
await page.keyboard.type(" continued");
30+
await expect(input).toHaveText(`Draft for ${name} continued`);
2631
}
27-
await expect(input).toHaveText(`Draft for ${name}`);
2832
}
2933
const settings = page.getByRole("button", {
3034
name: "Channel settings",

0 commit comments

Comments
 (0)