Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12084242b0 | ||
|
|
34f4646ccf |
No files matched your search
@@ -30,6 +30,7 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { flushSync } from "react-dom";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useDebouncedValue } from "@tanstack/react-pacer";
|
||||
import { projectSearchEntriesQueryOptions } from "~/lib/projectReactQuery";
|
||||
@@ -71,6 +72,7 @@ import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel";
|
||||
import { ComposerPlanFollowUpBanner } from "./ComposerPlanFollowUpBanner";
|
||||
import { resolveComposerMenuActiveItemId } from "./composerMenuHighlight";
|
||||
import { searchSlashCommandItems } from "./composerSlashCommandSearch";
|
||||
import { expandMobileComposerForKeyboard } from "./mobileComposerFocus";
|
||||
import {
|
||||
getComposerProviderState,
|
||||
renderProviderTraitsMenuContent,
|
||||
@@ -811,7 +813,6 @@ export const ChatComposer = memo(
|
||||
const composerMenuItemsRef = useRef<ComposerCommandItem[]>([]);
|
||||
const activeComposerMenuItemRef = useRef<ComposerCommandItem | null>(null);
|
||||
const composerBlurFrameRef = useRef<number | null>(null);
|
||||
const mobileComposerExpandFrameRef = useRef<number | null>(null);
|
||||
const mobileComposerExpandReleaseFrameRef = useRef<number | null>(null);
|
||||
const mobileComposerExpandInFlightRef = useRef(false);
|
||||
const dragDepthRef = useRef(0);
|
||||
@@ -1627,25 +1628,36 @@ export const ChatComposer = memo(
|
||||
[blurMobileComposerAfterSend, onSend, shouldBlurMobileComposerOnSubmit],
|
||||
);
|
||||
const expandMobileComposer = useCallback(() => {
|
||||
if (composerBlurFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(composerBlurFrameRef.current);
|
||||
composerBlurFrameRef.current = null;
|
||||
}
|
||||
if (mobileComposerExpandFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(mobileComposerExpandFrameRef.current);
|
||||
}
|
||||
if (mobileComposerExpandReleaseFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(mobileComposerExpandReleaseFrameRef.current);
|
||||
}
|
||||
mobileComposerExpandInFlightRef.current = true;
|
||||
setIsComposerFocused(true);
|
||||
mobileComposerExpandFrameRef.current = window.requestAnimationFrame(() => {
|
||||
mobileComposerExpandFrameRef.current = null;
|
||||
composerEditorRef.current?.focusAtEnd();
|
||||
mobileComposerExpandReleaseFrameRef.current = window.requestAnimationFrame(() => {
|
||||
mobileComposerExpandReleaseFrameRef.current = null;
|
||||
mobileComposerExpandInFlightRef.current = false;
|
||||
});
|
||||
expandMobileComposerForKeyboard({
|
||||
cancelPendingBlur: () => {
|
||||
if (composerBlurFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(composerBlurFrameRef.current);
|
||||
composerBlurFrameRef.current = null;
|
||||
}
|
||||
},
|
||||
cancelPendingRelease: () => {
|
||||
if (mobileComposerExpandReleaseFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(mobileComposerExpandReleaseFrameRef.current);
|
||||
mobileComposerExpandReleaseFrameRef.current = null;
|
||||
}
|
||||
},
|
||||
setExpandInFlight: (inFlight) => {
|
||||
mobileComposerExpandInFlightRef.current = inFlight;
|
||||
},
|
||||
commitExpandedState: () => {
|
||||
flushSync(() => {
|
||||
setIsComposerFocused(true);
|
||||
});
|
||||
},
|
||||
focusEditorAtEnd: () => {
|
||||
composerEditorRef.current?.focusAtEnd();
|
||||
},
|
||||
scheduleRelease: () => {
|
||||
mobileComposerExpandReleaseFrameRef.current = window.requestAnimationFrame(() => {
|
||||
mobileComposerExpandReleaseFrameRef.current = null;
|
||||
mobileComposerExpandInFlightRef.current = false;
|
||||
});
|
||||
},
|
||||
});
|
||||
}, []);
|
||||
|
||||
@@ -1825,9 +1837,6 @@ export const ChatComposer = memo(
|
||||
if (composerBlurFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(composerBlurFrameRef.current);
|
||||
}
|
||||
if (mobileComposerExpandFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(mobileComposerExpandFrameRef.current);
|
||||
}
|
||||
if (mobileComposerExpandReleaseFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(mobileComposerExpandReleaseFrameRef.current);
|
||||
}
|
||||
@@ -2063,7 +2072,10 @@ export const ChatComposer = memo(
|
||||
: "text-muted-foreground/60",
|
||||
!activePendingProgress?.activeQuestion?.multiSelect && "px-3 py-2",
|
||||
)}
|
||||
onPointerDown={(event) => event.preventDefault()}
|
||||
onPointerDown={(event) => {
|
||||
event.preventDefault();
|
||||
expandMobileComposer();
|
||||
}}
|
||||
onClick={expandMobileComposer}
|
||||
aria-label="Write custom answer"
|
||||
>
|
||||
@@ -2102,7 +2114,10 @@ export const ChatComposer = memo(
|
||||
? "text-foreground"
|
||||
: "text-muted-foreground/35",
|
||||
)}
|
||||
onPointerDown={(event) => event.preventDefault()}
|
||||
onPointerDown={(event) => {
|
||||
event.preventDefault();
|
||||
expandMobileComposer();
|
||||
}}
|
||||
onClick={expandMobileComposer}
|
||||
aria-label="Expand composer"
|
||||
>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { expandMobileComposerForKeyboard } from "./mobileComposerFocus";
|
||||
|
||||
describe("expandMobileComposerForKeyboard", () => {
|
||||
it("focuses after the expanded composer is committed and before release is scheduled", () => {
|
||||
const calls: string[] = [];
|
||||
|
||||
expandMobileComposerForKeyboard({
|
||||
cancelPendingBlur: vi.fn(() => calls.push("cancel-blur")),
|
||||
cancelPendingRelease: vi.fn(() => calls.push("cancel-release")),
|
||||
setExpandInFlight: vi.fn((inFlight) => calls.push(`in-flight:${inFlight}`)),
|
||||
commitExpandedState: vi.fn(() => calls.push("commit-expanded")),
|
||||
focusEditorAtEnd: vi.fn(() => calls.push("focus")),
|
||||
scheduleRelease: vi.fn(() => calls.push("schedule-release")),
|
||||
});
|
||||
|
||||
expect(calls).toEqual([
|
||||
"cancel-blur",
|
||||
"cancel-release",
|
||||
"in-flight:true",
|
||||
"commit-expanded",
|
||||
"focus",
|
||||
"schedule-release",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
export interface MobileComposerExpandOptions {
|
||||
cancelPendingBlur: () => void;
|
||||
cancelPendingRelease: () => void;
|
||||
setExpandInFlight: (inFlight: boolean) => void;
|
||||
commitExpandedState: () => void;
|
||||
focusEditorAtEnd: () => void;
|
||||
scheduleRelease: () => void;
|
||||
}
|
||||
|
||||
export function expandMobileComposerForKeyboard(options: MobileComposerExpandOptions) {
|
||||
options.cancelPendingBlur();
|
||||
options.cancelPendingRelease();
|
||||
options.setExpandInFlight(true);
|
||||
options.commitExpandedState();
|
||||
options.focusEditorAtEnd();
|
||||
options.scheduleRelease();
|
||||
}
|
||||
Reference in new issue
Block a user