fix(webui): focus restored drafts before setting mention selection
This commit is contained in:
1 parent
78ae5ff94f
commit
3a14935eb1
2 files changed
+14
-2
No files matched your search
@@ -44,7 +44,10 @@ export function useComposerMentionInput({
|
|||||||
}, [inputRef]);
|
}, [inputRef]);
|
||||||
|
|
||||||
const selectRaw = useCallback((start: number, end = start) => {
|
const selectRaw = useCallback((start: number, end = start) => {
|
||||||
inputRef.current?.setSelectionRange(
|
const el = inputRef.current;
|
||||||
|
// Focus first: removing a queued prompt's edit button can reset a blurred selection.
|
||||||
|
el?.focus();
|
||||||
|
el?.setSelectionRange(
|
||||||
mentionTextOffset(textRef.current, start, "toDisplay", "start"),
|
mentionTextOffset(textRef.current, start, "toDisplay", "start"),
|
||||||
mentionTextOffset(textRef.current, end, "toDisplay", "end"),
|
mentionTextOffset(textRef.current, end, "toDisplay", "end"),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2981,10 +2981,19 @@ describe("ThreadComposer", () => {
|
|||||||
fireEvent.keyDown(input, { key: "Enter" });
|
fireEvent.keyDown(input, { key: "Enter" });
|
||||||
|
|
||||||
const editButton = screen.getByRole("button", { name: "Edit guidance" });
|
const editButton = screen.getByRole("button", { name: "Edit guidance" });
|
||||||
fireEvent.click(editButton);
|
const textarea = input as HTMLTextAreaElement;
|
||||||
|
const setSelection = textarea.setSelectionRange.bind(textarea);
|
||||||
|
const focusedSelections: boolean[] = [];
|
||||||
|
vi.spyOn(textarea, "setSelectionRange").mockImplementation((start, end, direction) => {
|
||||||
|
focusedSelections.push(document.activeElement === textarea);
|
||||||
|
setSelection(start, end, direction);
|
||||||
|
});
|
||||||
|
await userEvent.click(editButton);
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(input).toHaveFocus();
|
expect(input).toHaveFocus();
|
||||||
});
|
});
|
||||||
|
expect(focusedSelections).toEqual([true]);
|
||||||
|
expect(textarea.selectionStart).toBe("rough follow-up".length);
|
||||||
expect(input).toHaveValue("rough follow-up");
|
expect(input).toHaveValue("rough follow-up");
|
||||||
expect(screen.queryByRole("group", { name: "Queued guidance" })).not.toBeInTheDocument();
|
expect(screen.queryByRole("group", { name: "Queued guidance" })).not.toBeInTheDocument();
|
||||||
fireEvent.change(input, { target: { value: "polished follow-up" } });
|
fireEvent.change(input, { target: { value: "polished follow-up" } });
|
||||||
|
|||||||
Reference in new issue
Block a user