Skip to content

Navigation Menu

Sign in
Sign up

[Outlook] Use selected email text as input instead of full body - #2039

Draft
manzke wants to merge 1 commit into
main from
claude/charming-fermat-cbzy96
Draft

[Outlook] Use selected email text as input instead of full body #2039
manzke wants to merge 1 commit into
main from
claude/charming-fermat-cbzy96

Conversation

@manzke

@manzke manzke commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #1448.

When a user highlights text inside an email, the Outlook add-in now uses just the selection as the message context instead of always injecting the full email body.

  • outlookMailContext.js: adds getSelectedDataAsync(item) (soft-fails to null, never rejects) and includes selectedText in the mail-context snapshot. Adds fetchCurrentSelectedText() for a fresh, pre-send re-read — Office.js has no "selection changed" event, so a snapshot taken on mount can go stale the moment the user changes their highlight.
  • buildChatApiMessages.js: combineUserTextWithEmailContext now accepts currentSelectedText and prefers it over currentBodyText when non-empty; falls back to the body otherwise (unchanged behavior when there's no selection).
  • useOutlookMailContextSnapshot.js: adds a useSelection toggle (defaults to true, resets on email change like includeBody). buildSnapshotOverride() is now async and re-reads the live selection right before send.
  • useOfficeChatAdapter.js: threads ctx.selectedText through to combineUserTextWithEmailContext.
  • OfficeMailContextBanner.jsx / OfficeContextStrip.jsx: shows "Using selected text (N chars)" with a one-click "Use full email instead" toggle (and the reverse), and updates the collapsed summary line.
  • OfficeChatPanel.jsx: forwards the new toggle and includes selection text in the live token-count estimate.

Scope: mail-only (matches the issue's acceptance criteria) — pinned/multi-selected emails and appointment (calendar) items are unaffected and always use their full body.

Acceptance criteria

  • Highlighting text in the email and opening the add-in produces a prompt that uses only the selection.
  • With no selection, behavior is identical to today (full body used).
  • The user can override the default per message (one-click toggle in the context banner).
  • Selection text is refreshed when the user re-runs (re-read fresh right before send).
  • Works in read mode; compose-mode behavior is unchanged (falls back gracefully — getSelectedDataAsync not present → null).

Test plan

  • npx jest --config tests/config/jest.config.js tests/unit/client — 153/153 passing, including new/updated coverage in outlook-mail-context.test.jsx, office-build-chat-api-messages.test.jsx, and use-outlook-mail-context-snapshot.test.jsx.
  • npx eslint on all changed files — no errors (pre-existing unrelated warnings only).
  • npx prettier --write on all changed files — no changes needed.
  • Manual verification in an actual Outlook taskpane (not possible in this environment) — please confirm the "Use selection" / "Use full email instead" toggle behaves as expected in a live Outlook host, including compose mode.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TTJ57JJa6dWa8HTZrhV5kS


Generated by Claude Code

Adds a getSelectedDataAsync reader to outlookMailContext.js, threads
selectedText through the mail-context snapshot and combineUserTextWithEmailContext
(selection takes precedence over the full body when non-empty), and refreshes
the selection right before send since Office.js has no selection-changed event.
The context banner shows a one-click "Use full email instead" / "Use selection"
toggle. Closes #1448.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TTJ57JJa6dWa8HTZrhV5kS 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

documentation Improvements or additions to documentation frontend

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Outlook] Use selected email text as input instead of full body

2 participants

AltStyle によって変換されたページ (->オリジナル) /