Skip to content

Improve user message editing behavior by preventing mode switch when text is selected; enhance button styling for better usability#104

Open
FranciscoMoretti wants to merge 1 commit intomainfrom
dont-edit-on-selection
Open

Improve user message editing behavior by preventing mode switch when text is selected; enhance button styling for better usability#104
FranciscoMoretti wants to merge 1 commit intomainfrom
dont-edit-on-selection

Conversation

@FranciscoMoretti
Copy link
Owner

@FranciscoMoretti FranciscoMoretti commented Mar 5, 2026

Summary by Sourcery

Prevent user messages from switching to edit mode when text is selected and make message content selectable in view mode for improved usability.

Enhancements:

  • Allow selecting text in user messages while in view mode.
  • Guard the edit-mode toggle so clicking while text is selected no longer enters edit mode.

Summary by cubic

Stop switching to edit mode when a user clicks a message with text selected, so selecting and copying works as expected.
Also enable text selection in view mode by adding the select-text class to the message button.

Written for commit 74f09ed. Summary will update on new commits.

…text is selected; enhance button styling for better usability
@vercel
Copy link

vercel bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sparka Ready Ready Preview, Comment Mar 5, 2026 8:20pm

Request Review

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts user message editing so clicking while text is selected no longer switches to edit mode, and tweaks the message content button styling to allow text selection while preserving existing hover behavior.

Flow diagram for message content click handler decision

flowchart TD
  A[User clicks message content button] --> B[Get current selection using window.getSelection]
  B --> C{Does selection exist and contain text?}
  C -- Yes --> D[Do nothing<br>Stay in view mode]
  C -- No --> E[Call setMode with value edit]
  E --> F[Component re-renders in edit mode]
  D --> G[User can copy or interact with selected text]
Loading

File-Level Changes

Change Details Files
Update message content button behavior to prevent entering edit mode when text is selected and allow text selection styling.
  • Add select-text to the message content button classes to explicitly allow text selection
  • Guard the edit mode toggle handler to early-return when there is a non-empty window.getSelection() value before calling setMode("edit")
apps/chat/components/user-message.tsx

Possibly linked issues

  • #(not provided): Yes. PR implements the window.getSelection()?.toString() guard exactly as requested and adjusts the message button behavior.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Using window.getSelection()?.toString() at the page level will block editing whenever any text on the page is selected; consider scoping the check to selections within this message element (e.g., inspecting getSelection().anchorNode/focusNode ancestry) so other-page selections don’t affect edit behavior.
  • The inline click handler is getting a bit more complex; extracting it into a small named function (e.g., handleMessageClick) would improve readability and make the selection logic easier to extend if needed.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using `window.getSelection()?.toString()` at the page level will block editing whenever *any* text on the page is selected; consider scoping the check to selections within this message element (e.g., inspecting `getSelection().anchorNode`/`focusNode` ancestry) so other-page selections don’t affect edit behavior.
- The inline click handler is getting a bit more complex; extracting it into a small named function (e.g., `handleMessageClick`) would improve readability and make the selection logic easier to extend if needed.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/chat/components/user-message.tsx">

<violation number="1" location="apps/chat/components/user-message.tsx:81">
P2: The edit-mode guard checks global document selection, so text selected anywhere on the page can incorrectly block entering edit mode for this message.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment on lines +81 to +84
onClick={() => {
if (window.getSelection()?.toString()) return;
setMode("edit");
}}
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 5, 2026

Choose a reason for hiding this comment

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

P2: The edit-mode guard checks global document selection, so text selected anywhere on the page can incorrectly block entering edit mode for this message.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/chat/components/user-message.tsx, line 81:

<comment>The edit-mode guard checks global document selection, so text selected anywhere on the page can incorrectly block entering edit mode for this message.</comment>

<file context>
@@ -76,9 +76,12 @@ const PureUserMessage = ({
+              className="block cursor-pointer select-text text-left transition-opacity hover:opacity-80"
               data-testid="message-content"
-              onClick={() => setMode("edit")}
+              onClick={() => {
+                if (window.getSelection()?.toString()) return;
+                setMode("edit");
</file context>
Suggested change
onClick={() => {
if (window.getSelection()?.toString()) return;
setMode("edit");
}}
onClick={(event) => {
const selection = window.getSelection();
if (
selection &&
!selection.isCollapsed &&
event.currentTarget.contains(selection.anchorNode)
)
return;
setMode("edit");
}}
Fix with Cubic

Copy link
Owner Author

Choose a reason for hiding this comment

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

@cursor fix

Copy link

Choose a reason for hiding this comment

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

Please finish setting up background agents. Go to Cursor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant