mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #6915] [MERGED] feat(chat): add selected message text to a lorebook #7382
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#7382
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6915
Author: @SpicyMarinara
Created: 9/30/2026
Status: ✅ Merged
Merged: 9/30/2026
Merged by: @SpicyMarinara
Base:
staging← Head:feat/selection-lorebook-entry📝 Commits (6)
1bd4b08feat(chat): add selected message text to a lorebook42e6a7efix(ui): return focus to where it was when a context menu closes02c289dfix(ui): keep context menu focus handling opt-in9f2a240fix(chat): ignore lorebook picks while an entry is being created9639f03Merge remote-tracking branch 'origin/staging' into feat/selection-lorebook-entryffed1b7Merge branch 'staging' into feat/selection-lorebook-entry📊 Changes
9 files changed (+317 additions, -23 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)➕
e2e/selection-lorebook-entry.e2e.ts(+91 -0)📝
packages/client/src/components/chat/ChatArea.tsx(+7 -1)➕
packages/client/src/components/chat/SelectionLorebookButton.tsx(+151 -0)📝
packages/client/src/components/lorebooks/LorebookEditor.tsx(+16 -5)📝
packages/client/src/components/ui/ContextMenu.tsx(+26 -5)📝
packages/client/src/hooks/use-editor-sections.ts(+17 -11)📝
packages/client/src/localization/locales/en.json(+3 -0)📝
packages/client/src/stores/ui.store.ts(+5 -1)📄 Description
Closes #6899
Why this change
Adding a lorebook entry for something that just came up in a chat means leaving the chat, opening Lorebooks, picking the book, adding an entry and typing its name. The request (NovelAI and SillyTavern extensions have the same idea) is to select the text and get a new entry already named after it. The maintainer asked about mobile; the reporter proposed a small plus button that appears on selection, since phones already show their own selection menu.
What changed
Add to lorebook button (
SelectionLorebookButton, mounted once inChatArea). It appears under a selection of up to 200 characters, the entry-name limit, inside any chat message, in every mode, on desktop and mobile.Lorebook picker: the existing
ContextMenulists lorebooks, with the chat's own lorebooks first. Choosing one creates the entry through the existinguseCreateLorebookEntry, with the same defaults as the editor's Add entry. The selection becomes both the entry's name and its keyword, and content is left for the user.Opening the lorebook:
openLorebookDetail(id, { initialTab: "entries", entryId })opens the lorebook, and the editor calls its existingjumpToEntryonce, so the entry opens expanded.Keeping the entry in view:
useEditorSectionskept re-anchoring to its first section whenever content grew, so a new entry opened this way was scrolled back out of view. The hook now returns the same anchored scroll for any element (scrollToElement), andjumpToEntryuses it. Jumping to an entry from a lint warning or test result benefits too.ContextMenu: scrolls when the list is taller than the screen, closes only when the page behind it scrolls (not when the menu itself does), and shows a focus style. A new opt-inautoFocusprop focuses the first item and returns focus on close. Only the new button uses it, and only when opened from the keyboard; existing menus keep their focus behaviour, and phones don't get focus handed back to the composer. The button stays mounted while its picker is open, so Escape returns focus to it.No duplicates: picks are ignored while an entry is being created, so a slow request can't produce a duplicate entry.
Localization: three English keys under
chat.selectionLorebook.*. The CHANGELOG entry is included.Test:
e2e/selection-lorebook-entry.e2e.tsruns on desktop Chromium, mobile Chromium and mobile WebKit, tapping on mobile. It selects "Silver Keep" in a message, adds it to a lorebook that already has 30 entries, and checks:On desktop it also checks the keyboard path: Enter opens the picker with focus inside, and Escape returns focus to the button. With
jumpToEntryreverted to plainscrollIntoView, the test fails with the entry out of view.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
Agent-run results (not substitutes for the checklist above):
pnpm checkpasses.pnpm smoke:uipasses 7/7.9f2a2405b.To check by hand:
ContextMenuusers) and confirm their menus still open, act and close as before.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)The CHANGELOG entry is included. No
docs/pages changed.UI evidence (if applicable)
Desktop Chromium and mobile WebKit screenshots, in light and dark mode, were captured from this branch: the selection button, the picker, and the new entry open in the editor. Uploading them from the agent session wasn't permitted, so they're available from the author.
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.