Skip to content

Make the AI assistant aware of the editor's highlighted text - #187

Merged
davior merged 1 commit into
mainfrom
claude/note-editor-highlight-access-k8cbcb
Sep 10, 2026
Merged

davior merged 1 commit into
mainfrom
claude/note-editor-highlight-access-k8cbcb

Conversation

@davior

@davior davior commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Summary

Today the AI assistant panel only ever sees the whole open note (or folder/children, depending on the context-scope picker) — never which part of it, if any, the user has physically highlighted. This adds that awareness:

  • The AI panel now reads the note editor's live text selection (BlockNote's getSelection/getSelectedText/onSelectionChange APIs) and, when non-empty, folds it into the request as a clearly-labelled, volatile excerpt sent alongside the note body — so "what does this mean?" or "expand on the highlighted section" resolves to the actual highlight instead of the whole note.
  • Works even when context scope is set to "none" (no full note attached) — the highlighted excerpt alone is still sent.
  • A small dismissible chip ("Using selection: “…”") shows above the compose box whenever a selection is live, so the behavior is visible and the user can opt out for a given message.
  • The selection is read from the editor's own selection state (not window.getSelection()), which is why it survives the user clicking into the AI panel's own chat input to type their question — it only clears once they click/type back inside the editor.
  • The static system prompt (PLAN_INSTRUCTIONS) gained a short rule telling the model how to interpret the excerpt: answer in-place for "what does this mean?"-style questions, or use the existing edit_section/edit_note (amend) actions for "expand"/"rewrite" requests — no new plan-action type needed.
  • Recipes' {{selected text}} placeholder is switched to the same editor-backed read, fixing a related bug where it depended on window.getSelection() and could go stale/empty once focus moved to the recipe picker.

No backend changes: the browser assembles the full request body already, so the excerpt just rides inside the existing volatile currentNoteText field.

Test plan

  • tsc --noEmit / npm run build — clean
  • npm run test — 143 tests passing
  • Manual: highlight a phrase in a note, open the AI panel, confirm the "Using selection" chip appears
  • Manual: ask "What does this mean?" — confirm the answer addresses the highlighted phrase specifically
  • Manual: ask "Expand on the highlighted section" — confirm the plan targets that content via edit_section/edit_note
  • Manual: click elsewhere in the editor to deselect, ask again — confirm it falls back to full note context
  • Manual: dismiss the chip via × and send — confirm the excerpt is excluded
  • Manual: run a Recipe using {{selected text}} — confirm it resolves correctly

🤖 Generated with Claude Code

https://claude.ai/code/session_017F4Asw3f6r3656qoKnvhn9


Generated by Claude Code

The AI panel now reads the note editor's current text selection (via
BlockNote's getSelection/getSelectedText/onSelectionChange) and includes
it as a labelled, volatile excerpt alongside the note body, so "what does
this mean?" or "expand on the highlighted section" resolves to the actual
highlight instead of just the whole note. A dismissible chip shows what's
currently being used. The Recipes {{selected text}} placeholder is
switched to the same editor-backed read, fixing its previous reliance on
window.getSelection(), which could go stale once focus left the editor.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017F4Asw3f6r3656qoKnvhn9
@davior
davior marked this pull request as ready for review September 10, 2026 06:19
@davior
davior merged commit 72a692f into main Sep 10, 2026
2 checks passed
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.

2 participants