Add summary: to character templates; fix two bugs that were hiding it

Add a summary: field (with a short explanatory comment) to
01_character_template.md, and fill the field in on the two shipped
examples, 01_protagonist.md and 02_antagonist.md. Documented in the
Story Bible README's "Adding a New Character" example and its new
"Automatic Linking in the Draft" section, and in the main README's
Story Bible docs.

While wiring this up against the real bundled template rather than a
hand-written test fixture, found two bugs that were silently defeating
last session's auto-linking feature for every project made from that
template:

- extract_from_frontmatter() only read a title: field for an item's
  name, but every bundled Story Bible template — character, location,
  lore, object, all of them — writes name:, never title:. Every real
  item's display name (and therefore everything matched against it in
  prose) was falling back to a garbled, uncapitalized filename guess
  instead. Now name: is read (title: still works too, for a sheet that
  uses that word instead).

- build_editor_job()'s fast path skipped straight to an unformatted
  run whenever there were no grammar/spelling issues and no active
  search — without checking whether there was a Story Bible reference
  to highlight. A name with no spelling issue of its own (which is
  most of them) never got its purple background, and with it no visible
  way to find the hover card that depends on it.

Both were invisible in the unit tests added last session because they
exercised find_references() directly against a hand-built index, never
through StoryBibleIndex::build() against real files, and the manual
smoke test happened to use a name ("Bixby") that the spell checker
flagged anyway — which incidentally kept the fast path from short-
circuiting. Added a disk-built-index test and a fast-path regression
test so both stay caught.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-19 11:32:56 -05:00
parent 0da52c3054
commit 229e2413c4
7 changed files with 134 additions and 18 deletions
+28 -1
View File
@@ -489,7 +489,7 @@ pub(super) fn build_editor_job(
let mut job = LayoutJob::default();
job.wrap.max_width = wrap_width;
if grammar.is_empty() && find.is_empty() {
if grammar.is_empty() && find.is_empty() && bible.is_empty() {
job.append(text, 0.0, TextFormat::simple(font_id, color));
return job;
}
@@ -809,6 +809,33 @@ pub(super) fn toggle_line_comment(
mod tests {
use super::*;
#[test]
fn a_bible_only_reference_is_not_skipped_by_the_grammar_find_fast_path() {
// build_editor_job short-circuits to one plain run when there's
// nothing to highlight — a regression check that it doesn't take
// that shortcut when the only thing to highlight is a Story Bible
// mention (no grammar issues, no active search), which used to
// mean the purple background — and the hover card that depends on
// it being visible to find — never appeared for a name with no
// spelling issue of its own.
let text = "Protagonist stood at the door.";
let job = build_editor_job(
text,
14.0,
egui::Color32::WHITE,
&[],
&[],
None,
&[(0, 11)], // "Protagonist"
f32::INFINITY,
);
let highlighted = job
.sections
.iter()
.any(|s| s.format.background != egui::Color32::default());
assert!(highlighted, "a bible-only reference must still be formatted");
}
#[test]
fn byte_to_char_is_the_inverse_of_char_to_byte() {
// "café!" — é is 2 bytes, so byte and char indices diverge after it.