Repository navigation
MUL-7926 SOUR-107: Focus the composer after selecting a starter #9132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Souredfish
wants to merge
5
commits into
multica-ai:main
Choose a base branch
from
Souredfish:agent/souredfish/SOUR-107-chat-starter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+168
−21
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0bd6d60
fix(mobile): focus composer after starter selection
31494d8
fix(mobile): refocus composer on subsequent triggers
e71743f
refactor(mobile): clarify focus layout gate
4e7b1d8
test(mobile): include composer focus regression cases
7716336
fix(mobile): preserve reply target after composer blur
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // @vitest-environment node | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| shouldCollapseAfterBlur, | ||
| shouldWaitForInputLayout, | ||
| } from "./composer-focus-trigger"; | ||
|
|
||
| describe("composer expand trigger focus", () => { | ||
| it("waits for native input layout when the first trigger expands the composer", () => { | ||
| expect(shouldWaitForInputLayout(false)).toBe(true); | ||
| }); | ||
|
|
||
| it("requests focus immediately for another starter selection while expanded", () => { | ||
| expect(shouldWaitForInputLayout(true)).toBe(false); | ||
| }); | ||
|
|
||
| it("requests focus immediately when the reply target changes while expanded", () => { | ||
| expect(shouldWaitForInputLayout(true)).toBe(false); | ||
| }); | ||
|
|
||
| it("does not let a delayed blur clear a reply target selected afterward", () => { | ||
| expect( | ||
| shouldCollapseAfterBlur({ | ||
| isEmpty: true, | ||
| isFocused: false, | ||
| triggerRevisionAtBlur: 3, | ||
| currentTriggerRevision: 4, | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it("collapses after blur only while the target is unchanged and empty", () => { | ||
| expect( | ||
| shouldCollapseAfterBlur({ | ||
| isEmpty: true, | ||
| isFocused: false, | ||
| triggerRevisionAtBlur: 3, | ||
| currentTriggerRevision: 3, | ||
| }), | ||
| ).toBe(true); | ||
| expect( | ||
| shouldCollapseAfterBlur({ | ||
| isEmpty: false, | ||
| isFocused: false, | ||
| triggerRevisionAtBlur: 3, | ||
| currentTriggerRevision: 3, | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /** Whether an expand trigger must wait for the TextInput's first native layout. */ | ||
| export function shouldWaitForInputLayout(isExpanded: boolean): boolean { | ||
| return !isExpanded; | ||
| } | ||
|
|
||
| /** Ignore delayed blur cleanup when the reply target changed in the meantime. */ | ||
| export function shouldCollapseAfterBlur(args: { | ||
| isEmpty: boolean; | ||
| isFocused: boolean; | ||
| triggerRevisionAtBlur: number; | ||
| currentTriggerRevision: number; | ||
| }): boolean { | ||
| return ( | ||
| args.isEmpty && | ||
| !args.isFocused && | ||
| args.triggerRevisionAtBlur === args.currentTriggerRevision | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // @vitest-environment node | ||
| import { afterEach, describe, expect, it } from "vitest"; | ||
| import { useReplyTargetStore } from "@/data/stores/reply-target-store"; | ||
| import { getReplyTargetComposerProps } from "./reply-target-composer"; | ||
|
|
||
| describe("reply target composer props", () => { | ||
| afterEach(() => useReplyTargetStore.getState().clear()); | ||
|
|
||
| it("updates the reply preview and focus trigger when the target changes", () => { | ||
| useReplyTargetStore.getState().setTarget({ | ||
| commentId: "comment-old", | ||
| actorName: "Old author", | ||
| preview: "Old comment preview", | ||
| }); | ||
| expect( | ||
| getReplyTargetComposerProps(useReplyTargetStore.getState().target), | ||
| ).toEqual({ | ||
| replyTarget: { actorName: "Old author", preview: "Old comment preview" }, | ||
| expandTrigger: "comment-old", | ||
| }); | ||
|
|
||
| useReplyTargetStore.getState().setTarget({ | ||
| commentId: "comment-new", | ||
| actorName: "New author", | ||
| preview: "New comment preview", | ||
| }); | ||
| expect( | ||
| getReplyTargetComposerProps(useReplyTargetStore.getState().target), | ||
| ).toEqual({ | ||
| replyTarget: { actorName: "New author", preview: "New comment preview" }, | ||
| expandTrigger: "comment-new", | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import type { ReplyTarget } from "@/data/stores/reply-target-store"; | ||
|
|
||
| /** Convert the active target into the preview and focus key consumed by the composer. */ | ||
| export function getReplyTargetComposerProps(target: ReplyTarget | null) { | ||
| return { | ||
| replyTarget: target | ||
| ? { actorName: target.actorName, preview: target.preview } | ||
| : null, | ||
| expandTrigger: target?.commentId ?? null, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.