Repository navigation
feat: pick emoji from a button in the commit and reply composers #252
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
Merged
xHeaven
merged 7 commits into
dev-null-sh:production
from
hbenabdallah:feat/emoji-picker
Oct 31, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f0de1de
feat: pick emoji from a button in the commit and reply composers
hbenabdallah 1c36d34
feat: reuse the reactions emoji picker in composers and insert where …
hbenabdallah 5b98325
fix: let Enter confirm an input method candidate in the emoji search
hbenabdallah 4cbe1b6
fix: ignore Safari's Enter that confirms an input method candidate in…
hbenabdallah 58182b9
fix: keep the caret where it was when an emoji does not fit
hbenabdallah b076b12
feat: put the emoji button inside the text box, bottom right
hbenabdallah d23e8c6
fix: put the caret back when an emoji replaces the same emoji
hbenabdallah 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,73 @@ | ||
| import { Smile } from 'lucide-react'; | ||
| import { useRef, useState } from 'react'; | ||
| import { ActionTooltip } from '@/components/action-tooltip'; | ||
| import { EmojiPicker } from '@/components/chat/message-reactions'; | ||
| import { buttonVariants } from '@/components/ui/button'; | ||
| import { | ||
| Popover, | ||
| PopoverContent, | ||
| PopoverTrigger, | ||
| } from '@/components/ui/popover'; | ||
| import { cn } from '@/lib/utils'; | ||
|
|
||
| const noReactions = new Set<string>(); | ||
|
|
||
| /** | ||
| * The reactions' emoji picker, for composers. The emoji is handed over once the picker has closed, so `onPick` can put | ||
| * the focus back in the textarea instead of on this button. | ||
| */ | ||
| export function EmojiPickerButton({ | ||
| disabled, | ||
| onPick, | ||
| className, | ||
| }: { | ||
| disabled?: boolean; | ||
| onPick: (emoji: string) => void; | ||
| className?: string; | ||
| }) { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const pickedEmoji = useRef<string | null>(null); | ||
|
|
||
| return ( | ||
| <Popover open={isOpen} onOpenChange={setIsOpen}> | ||
| <ActionTooltip label="Add emoji"> | ||
| <PopoverTrigger | ||
| type="button" | ||
| disabled={disabled} | ||
| aria-label="Add emoji" | ||
| className={cn( | ||
| buttonVariants({ variant: 'ghost', size: 'icon' }), | ||
| 'text-muted-foreground', | ||
| className, | ||
| )} | ||
| data-test="emoji-picker-button" | ||
| > | ||
| <Smile className="size-5" /> | ||
| </PopoverTrigger> | ||
| </ActionTooltip> | ||
| <PopoverContent | ||
| align="end" | ||
| collisionPadding={8} | ||
| className="flex h-[min(25rem,var(--radix-popover-content-available-height))] w-76 flex-col overflow-hidden rounded-lg p-0 shadow-[0_12px_32px_-12px_rgb(0_0_0/0.35)]" | ||
| onCloseAutoFocus={(event) => { | ||
| const emoji = pickedEmoji.current; | ||
|
|
||
| if (emoji !== null) { | ||
| event.preventDefault(); | ||
| pickedEmoji.current = null; | ||
| onPick(emoji); | ||
| } | ||
| }} | ||
| > | ||
| <EmojiPicker | ||
| usage={[]} | ||
| reacted={noReactions} | ||
| onPick={(emoji) => { | ||
| pickedEmoji.current = emoji; | ||
| setIsOpen(false); | ||
| }} | ||
| /> | ||
| </PopoverContent> | ||
| </Popover> | ||
| ); | ||
| } | ||
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,66 @@ | ||
| import type { RefObject } from 'react'; | ||
| import { useLayoutEffect, useRef } from 'react'; | ||
| import { insertAtSelection } from '@/lib/text-selection'; | ||
|
|
||
| /** | ||
| * Inserts a picked emoji where the caret was in the composer's textarea. A textarea keeps its selection while the | ||
| * picker has the focus, so this works whether the picker was opened with the pointer or the keyboard. Once React has | ||
| * written the new body, the focus goes back to the textarea with the caret right after the emoji. | ||
| */ | ||
| export function useEmojiInsertion({ | ||
| body, | ||
| updateBody, | ||
| textareaRef, | ||
| maxLength, | ||
| }: { | ||
| body: string; | ||
| updateBody: (body: string) => void; | ||
| textareaRef: RefObject<HTMLTextAreaElement | null>; | ||
| maxLength: number; | ||
| }): (emoji: string) => void { | ||
| const caret = useRef<number | null>(null); | ||
|
|
||
| useLayoutEffect(() => { | ||
| const element = textareaRef.current; | ||
|
|
||
| if (caret.current === null || element === null) { | ||
| return; | ||
| } | ||
|
|
||
| element.focus(); | ||
| element.setSelectionRange(caret.current, caret.current); | ||
| caret.current = null; | ||
| }, [body, textareaRef]); | ||
|
|
||
| return (emoji) => { | ||
| const element = textareaRef.current; | ||
| const inserted = insertAtSelection(body, element, emoji, maxLength); | ||
|
|
||
| if (inserted === null) { | ||
| // Focusing a restored draft moves a caret at its start to the end, so the selection is put back after. | ||
| if (element !== null) { | ||
| const { selectionStart, selectionEnd } = element; | ||
|
|
||
| element.focus(); | ||
| element.setSelectionRange(selectionStart, selectionEnd); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| // An emoji picked over the same emoji leaves the body as it was, so React skips the effect: return here. | ||
| if (inserted.value === body) { | ||
| caret.current = null; | ||
|
|
||
| if (element !== null) { | ||
| element.focus(); | ||
| element.setSelectionRange(inserted.caret, inserted.caret); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| caret.current = inserted.caret; | ||
| updateBody(inserted.value); | ||
| }; | ||
| } |
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,25 @@ | ||
| export type TextSelection = Pick< | ||
| HTMLTextAreaElement, | ||
| 'selectionStart' | 'selectionEnd' | ||
| >; | ||
|
|
||
| /** | ||
| * Inserts the text over the selection, or at the end without one. Null when the result would be longer than | ||
| * `maxLength` characters, the same cap the textarea puts on typing. | ||
| */ | ||
| export function insertAtSelection( | ||
| value: string, | ||
| selection: TextSelection | null, | ||
| text: string, | ||
| maxLength: number, | ||
| ): { value: string; caret: number } | null { | ||
| const start = selection?.selectionStart ?? value.length; | ||
| const end = selection?.selectionEnd ?? value.length; | ||
| const next = value.slice(0, start) + text + value.slice(end); | ||
|
|
||
| if (Array.from(next).length > maxLength) { | ||
| return null; | ||
| } | ||
|
|
||
| return { value: next, caret: start + text.length }; | ||
| } |
Oops, something went wrong.
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.