Skip to content

Conversation

@pilgrimlyieu
Copy link
Contributor

What this PR does

Before this PR:

After this PR:

Fixes #9908

This PR introduces a utility function getSelectedText to consistently extract selected text for proper handling of KaTeX formulas. The function is integrated across several components to replace direct usage of window.getSelection()?.toString(), ensuring more reliable and feature-rich text selection. Comprehensive unit tests are also added to verify its behavior for plain text, inline and display KaTeX, and mixed content.

Why we need it and why it was done in this way

The following tradeoffs were made:

The following alternatives were considered:

Links to places where the discussion took place:

Breaking changes

If this PR introduces breaking changes, please describe the changes and the impact on users.

Special notes for your reviewer

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note

NONE
@pilgrimlyieu
Copy link
Contributor Author

@claude review

@DeJeune DeJeune requested a review from Copilot October 24, 2025 07:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a centralized utility function getSelectedText to handle text selection across the application with special support for KaTeX formulas. The function extracts LaTeX source code from KaTeX elements and wraps them with appropriate delimiters ($ for inline, $$ for display mode), ensuring mathematical formulas are preserved in their original LaTeX format when selected.

Key changes:

  • Added getSelectedText utility function in src/renderer/src/utils/selection.ts with KaTeX-aware text extraction
  • Comprehensive test suite covering plain text, inline KaTeX, display KaTeX, and mixed content scenarios
  • Integrated the utility across components (Chat.tsx, RichEditor/index.tsx, ContextMenu/index.tsx) replacing direct window.getSelection()?.toString() calls

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/renderer/src/utils/selection.ts New utility function for extracting selected text with KaTeX formula handling
src/renderer/src/utils/tests/selection.test.ts Comprehensive unit tests for the getSelectedText utility
src/renderer/src/pages/home/Chat.tsx Integrated getSelectedText for search functionality
src/renderer/src/components/RichEditor/index.tsx Replaced window.getSelection() calls with getSelectedText utility
src/renderer/src/components/ContextMenu/index.tsx Updated context menu to use getSelectedText utility

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@0xfullex 0xfullex added the needs-triage require initial review and categorization label Oct 29, 2025
@MurphyLo
Copy link
Contributor

MurphyLo commented Nov 1, 2025

Note

This comment was translated by Claude.

Hope it can be merged before the next release 🥳


Original Content

希望能在下次发版前合并🥳

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

Labels

needs-triage require initial review and categorization

3 participants