Skip to content

fix(ui): correct emoji extraction logic using regex #12749

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
wants to merge 6 commits into
base: canary
Choose a base branch
from

Conversation

NorkzYT
Copy link
Contributor

@NorkzYT NorkzYT commented Jun 8, 2025

fix.ui.-correct.emoji-extraction-logic-using-regex.mp4

This PR solves the issue where a majority of emoji's are unable to become the document or folders icon.

The regex used is below with the test string of a variety of emoji's:
https://regex101.com/r/0anB6Z/1

Summary by CodeRabbit

  • Bug Fixes

    • Improved emoji extraction to better handle a wider variety of emoji combinations at the start of text.
  • Tests

    • Expanded test coverage for emoji extraction, including additional cases for single and combined emojis followed by digits, and updated negative test scenarios.

NorkzYT added 2 commits June 7, 2025 22:14
…dentify and return emoji from the input string

test(extract-emoji-icon): update test case to reflect the correct emoji extraction behavior and expected output
…con function to ensure correct emoji extraction and handling of plain text
Copy link
Contributor

graphite-app bot commented Jun 8, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@graphite-app graphite-app bot requested review from a team June 8, 2025 02:25
@github-actions github-actions bot added test Related to test cases app:core labels Jun 8, 2025
Copy link

coderabbitai bot commented Jun 8, 2025

Warning

Rate limit exceeded

@NorkzYT has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 13 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8e2eeb2 and 523f7f1.

📒 Files selected for processing (1)
  • packages/frontend/core/src/utils/extract-emoji-icon.ts (1 hunks)

Walkthrough

The changes expand the test coverage for the extractEmojiIcon utility function by introducing additional cases with various emoji and digit combinations. The function's implementation is updated to use a broader regular expression for emoji detection and minor logic adjustments to improve emoji extraction accuracy, while maintaining the same function signature.

Changes

File(s) Change Summary
packages/frontend/core/src/utils/extract-emoji-icon.ts Updated emoji detection logic to use a broader regex and improved extraction logic.
packages/frontend/core/src/utils/tests/extract-emoji-icon.spec.ts Expanded test suite with more cases for emoji and digit combinations; updated negative test case.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant extractEmojiIcon

    Caller->>extractEmojiIcon: Call with input string
    extractEmojiIcon->>extractEmojiIcon: Reset regex index
    extractEmojiIcon->>extractEmojiIcon: Execute emoji regex on input
    alt Match at start of string
        extractEmojiIcon->>extractEmojiIcon: Find emoji cluster boundary
        extractEmojiIcon->>Caller: Return {emoji, rest}
    else No match at start
        extractEmojiIcon->>Caller: Return {emoji: null, rest: input}
    end
Loading

Poem

In the land of code where emojis play,
Extracting hearts and planes in a clever way.
With regex renewed and tests in tow,
The icon’s revealed with a bunny’s glow.
Digits and symbols, all neatly apart—
A hop, a skip, and a Unicode heart!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@NorkzYT
Copy link
Contributor Author

NorkzYT commented Jun 8, 2025

Perhaps in the future there can be a built-in pop-up that you can select Emoji's, Icons, and an Upload function as well.
Similar to what Notion has which is shown below:

image
image
image

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/frontend/core/src/utils/__tests__/extract-emoji-icon.spec.ts (1)

5-30: Consider adding edge case tests for the broader regex pattern.

While the current test coverage is good, consider adding tests for Unicode characters that might be falsely matched by the broad regex pattern to ensure the function behaves correctly.

Add these additional test cases to verify edge cases:

+  expect(extractEmojiIcon('©️test')).toEqual({
+    emoji: '©️',
+    rest: 'test',
+  });
+
+  expect(extractEmojiIcon('®️test')).toEqual({
+    emoji: '®️',
+    rest: 'test',
+  });
+
+  // Test potential false positives from broad Unicode range
+  expect(extractEmojiIcon('†test')).toEqual({
+    emoji: null,
+    rest: '†test',
+  });
+
+  expect(extractEmojiIcon('√test')).toEqual({
+    emoji: null,
+    rest: '√test',
+  });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 115496a and 8e2eeb2.

📒 Files selected for processing (2)
  • packages/frontend/core/src/utils/__tests__/extract-emoji-icon.spec.ts (1 hunks)
  • packages/frontend/core/src/utils/extract-emoji-icon.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/frontend/core/src/utils/__tests__/extract-emoji-icon.spec.ts (1)
packages/frontend/core/src/utils/extract-emoji-icon.ts (1)
  • extractEmojiIcon (4-19)
🔇 Additional comments (3)
packages/frontend/core/src/utils/extract-emoji-icon.ts (1)

11-12: Good choice using slice() over substring().

Using slice() is the modern preferred approach over substring() as it has more predictable behavior with negative indices and is generally more intuitive.

packages/frontend/core/src/utils/__tests__/extract-emoji-icon.spec.ts (2)

11-24: Excellent test coverage for emoji extraction scenarios.

The new test cases effectively cover:

  • Variation selector emojis (❤️, ➡️, ✈️) with trailing text
  • Different emoji categories (heart, arrow, transport)
  • Proper separation of emoji from following content

26-28: Good negative test case update.

The updated test case with 'plain text' clearly validates that non-emoji strings are handled correctly, ensuring no false positive extraction occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app:core test Related to test cases
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants