Make the AI assistant aware of the editor's highlighted text - #187
Merged
Merged
Conversation
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
marked this pull request as ready for review
September 10, 2026 06:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
getSelection/getSelectedText/onSelectionChangeAPIs) 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.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.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 existingedit_section/edit_note(amend) actions for "expand"/"rewrite" requests — no new plan-action type needed.{{selected text}}placeholder is switched to the same editor-backed read, fixing a related bug where it depended onwindow.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
currentNoteTextfield.Test plan
tsc --noEmit/npm run build— cleannpm run test— 143 tests passingedit_section/edit_note{{selected text}}— confirm it resolves correctly🤖 Generated with Claude Code
https://claude.ai/code/session_017F4Asw3f6r3656qoKnvhn9
Generated by Claude Code