Fact labels from the line above; whole search results clickable
Paul's ?explain=facts screenshot showed every number on his Office page
falling back to the heading. Notion's soft line breaks put "The office
phone number is:" on one line and the number on the next.
- A value that starts its own line, bar a list marker, takes its label
from the nearest line above that ends in a separator. Same-indent value
lines are skipped, so a list under one label carries it.
- Rule 2's protections hold one line up:
- list scope by indent;
- the earlier-span rule;
- the label's own characters;
- one total maxLookback, with a line beyond it counted as over-long
(NoBox);
- headings stop the search.
- On his page, "office" narrows to exactly one number.
- Paul asked for the whole result to be clickable. search.js follows the
title's link on a plain click anywhere in a result, but never for a
drag, an existing selection or a double-click. Cmd/Ctrl/Shift opens a
new tab. Without the script, only the title is a link.
Reviewed by GPT-6 Astra (REQUEST CHANGES): the first version broke rule
2's protections and blocked text selection with an overlay. Both fixed;
all surviving mutations are built and red. TestAModelResponseIsCheapToProcess
and TestLabellingIsNotQuadratic fail under this machine's load on
unmodified main too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Squashed from fix/fact-label-line-above into main.
8 files changed,
+483
−1
Makefile+1 −1docs/superpowers/specs/2026-09-03-memoria-design.md+23 −0internal/memoria/fact/fact.go+143 −0internal/memoria/fact/fact_test.go+135 −0internal/memoria/narrow_test.go+15 −0internal/memoria/static/memoria.css+9 −0internal/memoria/static/search.js+39 −0internal/memoriatest/resultlink_browser_test.go+118 −0
CI passed — run details
diff --git a/Makefile b/Makefile| index f5e8085..0828b9e 100644 |
| --- a/Makefile |
| +++ b/Makefile |
| @@ -120,7 +120,7 @@ ci: vet fmt-check test migration-check |
| # Mac from the Playwright cache. |
| RASTRILLO_CHROME ?= $(firstword $(wildcard $(HOME)/Library/Caches/ms-playwright/chromium-*/chrome-mac*/Chromium.app/Contents/MacOS/Chromium)) |
| browser: |
| - RASTRILLO_CHROME="$(RASTRILLO_CHROME)" CGO_ENABLED=0 go test -tags browser -count=1 -run 'OnTap|ProductionCSP|NoSidewaysScroll|SettlesADeferredBox' ./internal/memoriatest/ |
| + RASTRILLO_CHROME="$(RASTRILLO_CHROME)" CGO_ENABLED=0 go test -tags browser -count=1 -run 'OnTap|ProductionCSP|NoSidewaysScroll|SettlesADeferredBox|WholeResultIsALink' ./internal/memoriatest/ |
| .PHONY: credits |
| credits: |
diff --git a/docs/superpowers/specs/2026-09-03-memoria-design.md b/docs/superpowers/specs/2026-09-03-memoria-design.md| index cd4d546..e3ed558 100644 |
| --- a/docs/superpowers/specs/2026-09-03-memoria-design.md |
| +++ b/docs/superpowers/specs/2026-09-03-memoria-design.md |
| @@ -3334,6 +3334,29 @@ span's position in the chunk text: |
| trimmed every Unicode space and format character, and review found |
| that it lost tab separators, borrowed labels across line separators, |
| and stripped a label's own bidi controls. |
| + **A value that starts its own line takes its label from the line |
| + above (2026-10-26).** This is what Paul's live Office page needed. |
| + Notion's soft line breaks put "The office phone number is:" on one line |
| + and the number on the next, so every number fell back to the heading. |
| + The search snippet joins lines with spaces, which hid this, and the |
| + invisible-gap rule above was a wrong first guess. The rule applies only |
| + when nothing but a list marker comes before the value on its own line. |
| + It takes the nearest non-blank line above, skipping lines that are |
| + only a value (so every number in a list under one label carries it). |
| + It stops at a heading, and it uses that line only if it ends in a |
| + separator, which is rule 2 applied one line up. Every protection rule 2 |
| + has on one line holds one line up, because review found the first |
| + version broke each of them: |
| + - **List scope.** The label line may not be indented deeper than the |
| + value. A value line at a different indent belongs to another list, |
| + so the search stops there instead of skipping it. |
| + - **The earlier-span rule.** A recognised value on the label line ends |
| + the label, so `Phone: <number> -` labels nothing below it. |
| + - **The label's own characters stay.** Only spaces are trimmed at its |
| + start. |
| + - **The total lookback is maxLookback.** A label line that begins |
| + beyond it is treated as over-long (rule 4): no box, rather than a |
| + truncated label or the heading in its place. |
| 3. **Empty after the separator → fall through.** A markdown bullet is the |
| case: the chunker keeps lines verbatim, so `- +353 1 547 7854` gives a |
| run of `-`, which "ends in a separator" and yields nothing. Two such |
diff --git a/internal/memoria/fact/fact.go b/internal/memoria/fact/fact.go| index effef6e..a10d052 100644 |
| --- a/internal/memoria/fact/fact.go |
| +++ b/internal/memoria/fact/fact.go |
| @@ -840,6 +840,7 @@ func labelOf(text string, start int, spans [][2]int, heading, title string) (str |
| // stray BOM. Only this trailing gap: the label's own characters, |
| // bidi controls included, are the document's and stay (2026-10-26). |
| run := strings.TrimRightFunc(text[b:start], isGap) |
| + onItsOwnLine := firstOnLine(text, b, run) |
| // A leading list marker is markup. The pattern needs a space after |
| // the marker and run is already trimmed on the right, so whatever it |
| // matches has something after it: a bare bullet — "- +353 1 547 |
| @@ -864,12 +865,154 @@ func labelOf(text string, start int, spans [][2]int, heading, title string) (str |
| return lbl, true, false |
| } |
| } |
| + // The value starts its own line: its label, if the document wrote |
| + // one, is the line above (2026-10-26). Notion's soft line breaks put |
| + // "The office phone number is:" on one line and the number on the |
| + // next — Paul's live Office page, where every number fell to the |
| + // heading. Only when nothing but a list marker sits before the value |
| + // on its line, so a value mid-line never borrows a label from above. |
| + if onItsOwnLine { |
| + if lbl, ok, noBox := labelAbove(text, b, spans); ok { |
| + return lbl, true, noBox |
| + } |
| + } |
| if heading != "" { |
| return heading, false, false |
| } |
| return title, false, false |
| } |
| +// firstOnLine reports whether the value whose run begins at b is the |
| +// first thing on its line, bar a list marker: b is a line start (the |
| +// sentence rule found a newline and no earlier value moved it) and the run |
| +// holds at most a marker. Decided before the marker is stripped. Called |
| +// directly by its test, because labelAbove would reject most of what this |
| +// refuses anyway, and a guard reachable only through that is not one |
| +// anything can show failing. |
| +func firstOnLine(text string, b int, run string) bool { |
| + return (b == 0 || text[b-1] == '\n') && isBareMarker(strings.TrimFunc(run, isGap)) |
| +} |
| + |
| +// isBareMarker is an empty prefix, or one list marker and nothing else. |
| +func isBareMarker(s string) bool { |
| + return s == "" || bareMarker.MatchString(s) |
| +} |
| + |
| +var bareMarker = regexp.MustCompile(`^(?:[-*+•>]|[0-9]{1,3}[.)])(?:[ \x{00A0}]+\[[ xX]\])?$`) |
| + |
| +// labelAbove finds a value's label on the lines above it, when the value |
| +// is the first thing on its line (ls is that line's start). |
| +// |
| +// It takes the nearest non-blank line above that is not itself only a |
| +// value, if that line ends in a separator. Lines that are only a value, |
| +// at the same indent as this one, are siblings and are skipped, so every |
| +// number in |
| +// |
| +// We also have the following unused phone numbers: |
| +// +353 (0)1 598 5125 |
| +// +353 (0)1 515 7175 |
| +// |
| +// carries the line that introduces them. Everything rule 2 protects on |
| +// one line holds one line up (review, 2026-10-26): |
| +// - list scope: the label line must not be indented deeper than the |
| +// value, and a value line at a different indent is another list's, |
| +// so the search stops there rather than borrowing across it; |
| +// - the earlier-span rule: a recognised value on the label line ends |
| +// the label there, so "Phone: <number1> -" labels nothing below it; |
| +// - the label's own characters stay: only spaces are trimmed at its |
| +// start, and only gaps at its end; |
| +// - it looks back no further than maxLookback in total, and stops at a |
| +// heading. |
| +func labelAbove(text string, ls int, spans [][2]int) (string, bool, bool) { |
| + floor := ls - maxLookback |
| + if floor < 0 { |
| + floor = 0 |
| + } |
| + want := indent(text[ls:]) |
| + end := ls - 1 // the newline that ends the line above |
| + for end >= floor && end > 0 { |
| + start := strings.LastIndexByte(text[floor:end], '\n') + 1 + floor |
| + line := text[start:end] |
| + // The line begins beyond the lookback, so its true start is not |
| + // in view. If it is the label line, the document wrote a label |
| + // longer than can be shown: rule 4, no box for this kind, rather |
| + // than a truncated label or the heading in its place. |
| + straddles := start == floor && floor > 0 && text[floor-1] != '\n' |
| + end = start - 1 |
| + if strings.TrimFunc(line, isGap) == "" { |
| + continue |
| + } |
| + in := indent(line) |
| + if valueOnly(text, start, start+len(line), spans) { |
| + if in == want { |
| + continue |
| + } |
| + return "", false, false |
| + } |
| + if in > want { |
| + return "", false, false |
| + } |
| + body := strings.TrimLeftFunc(line, unicode.IsSpace) |
| + if strings.HasPrefix(body, "#") { |
| + return "", false, false |
| + } |
| + if m := listMarker.FindStringIndex(body); m != nil { |
| + body = body[m[1]:] |
| + } |
| + // The earlier-span rule, on the label line. |
| + if e := lastSpanEndBefore(spans, start+len(line)); e > start { |
| + body = text[e : start+len(line)] |
| + } |
| + body = strings.TrimRightFunc(body, isGap) |
| + r, size := utf8.DecodeLastRuneInString(body) |
| + if size == 0 || !isSeparator(r) { |
| + return "", false, false |
| + } |
| + lbl := strings.TrimSpace(body[:len(body)-size]) |
| + switch { |
| + case lbl == "": |
| + return "", false, false |
| + case straddles, utf8.RuneCountInString(lbl) > MaxLabel: |
| + return lbl, true, true |
| + default: |
| + return lbl, true, false |
| + } |
| + } |
| + return "", false, false |
| +} |
| + |
| +// indent is the width of a line's leading spaces and tabs. |
| +func indent(line string) int { |
| + n := 0 |
| + for _, r := range line { |
| + if r != ' ' && r != '\t' && r != '\u00a0' { |
| + break |
| + } |
| + n++ |
| + } |
| + return n |
| +} |
| + |
| +// valueOnly reports whether text[ls:le] is a list marker, one recognised |
| +// span, and nothing else but gaps and a trailing comma or semicolon. |
| +// spans are sorted by end, so this is a binary search, not a scan: a |
| +// chunk can hold tens of thousands of facts. |
| +func valueOnly(text string, ls, le int, spans [][2]int) bool { |
| + i := sort.Search(len(spans), func(i int) bool { return spans[i][1] > ls }) |
| + for ; i < len(spans) && spans[i][0] < le; i++ { |
| + sp := spans[i] |
| + if sp[0] < ls || sp[1] > le { |
| + continue |
| + } |
| + before := strings.TrimFunc(text[ls:sp[0]], isGap) |
| + after := strings.TrimRightFunc(strings.TrimFunc(text[sp[1]:le], isGap), func(r rune) bool { return r == ',' || r == ';' }) |
| + if isBareMarker(before) && strings.TrimFunc(after, isGap) == "" { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| // lastSpanEndBefore returns the end of the latest span finishing at or |
| // before at. spans must be sorted by END — see the sort in Scan. |
| func lastSpanEndBefore(spans [][2]int, at int) int { |
diff --git a/internal/memoria/fact/fact_test.go b/internal/memoria/fact/fact_test.go| index b3d221b..8a4bc0d 100644 |
| --- a/internal/memoria/fact/fact_test.go |
| +++ b/internal/memoria/fact/fact_test.go |
| @@ -3,6 +3,7 @@ package fact |
| import ( |
| "reflect" |
| "sort" |
| + "strconv" |
| "strings" |
| "testing" |
| "time" |
| @@ -848,3 +849,137 @@ func TestTheGapRuleKeepsWhatIsNotAGap(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// A value on its own line takes its label from the line above (2026-10-26). |
| +// |
| +// Paul's live Office page: Notion's soft line breaks put "The office phone |
| +// number is:" on one line and the number on the next, so every number on |
| +// the page fell back to the heading and the box never appeared. The search |
| +// snippet joins lines with spaces, which is why it looked like one line. |
| +func TestALabelOnTheLineAbove(t *testing.T) { |
| + long := strings.Repeat("x", MaxLabel+1) |
| + for _, c := range []struct { |
| + name, text string |
| + labels []string |
| + own []bool |
| + }{ |
| + {"soft break", "The office phone number is:\n+353 (0)1 547 7854", |
| + []string{"The office phone number is"}, []bool{true}}, |
| + {"Notion bullet, child bullet", "- The office phone number is:\n - +353 (0)1 547 7854", |
| + []string{"The office phone number is"}, []bool{true}}, |
| + {"a blank line between", "Office:\n\n- +353 (0)1 547 7854", |
| + []string{"Office"}, []bool{true}}, |
| + {"every value in a list under one label", |
| + "We also have the following unused phone numbers:\n+353 (0)1 598 5125\n+353 (0)1 515 7175,\n+353 (0)1 534 6069", |
| + []string{"We also have the following unused phone numbers", "We also have the following unused phone numbers", "We also have the following unused phone numbers"}, |
| + []bool{true, true, true}}, |
| + {"the line above does not end in a separator", "Ring us any time\n+353 (0)1 547 7854", |
| + []string{"Contact"}, []bool{false}}, |
| + {"a heading is not a label", "## Office:\n+353 (0)1 547 7854", |
| + []string{"Contact"}, []bool{false}}, |
| + {"a value mid-line never borrows", "Office:\nCall +353 (0)1 547 7854", |
| + []string{"Contact"}, []bool{false}}, |
| + {"a labelled value above is not a label", "Phone: +353 (0)1 547 7854\n+353 (0)1 598 1234", |
| + []string{"Phone", "Contact"}, []bool{true, false}}, |
| + } { |
| + got := Scan(c.text, "Contact", "Tito", []Kind{Phone}) |
| + if len(got) != len(c.labels) { |
| + t.Fatalf("%s: Scan found %d, want %d", c.name, len(got), len(c.labels)) |
| + } |
| + for i, f := range got { |
| + if f.Label != c.labels[i] || f.Own != c.own[i] { |
| + t.Errorf("%s [%d]: label = %q own = %v, want %q own = %v", c.name, i, f.Label, f.Own, c.labels[i], c.own[i]) |
| + } |
| + } |
| + } |
| + got := Scan(long+":\n+353 (0)1 547 7854", "Contact", "Tito", []Kind{Phone}) |
| + if len(got) != 1 || !got[0].NoBox { |
| + t.Errorf("an over-long label above: %+v, want NoBox", got) |
| + } |
| +} |
| + |
| +// firstOnLine, called directly: see its comment for why. |
| +// |
| +// MUTATION-TESTED 2026-10-26, each reverted: the line-start half removed |
| +// → "after a sentence"; the bare-marker half removed → "after words". |
| +func TestFirstOnLine(t *testing.T) { |
| + for _, c := range []struct { |
| + name, text string |
| + b int |
| + run string |
| + want bool |
| + }{ |
| + {"start of text", "+353", 0, "", true}, |
| + {"after a newline", "Office:\n+353", 8, "", true}, |
| + {"after a newline and a marker", "Office:\n- +353", 8, "- ", true}, |
| + {"after a sentence", "Call us. +353", 9, "", false}, |
| + {"after words", "Office:\nCall +353", 8, "Call ", false}, |
| + } { |
| + if got := firstOnLine(c.text, c.b, c.run); got != c.want { |
| + t.Errorf("%s: firstOnLine = %v, want %v", c.name, got, c.want) |
| + } |
| + } |
| +} |
| + |
| +// Everything rule 2 protects on one line holds one line up. GPT-6 Astra's |
| +// review (2026-10-26) found the first version of labelAbove broke each of |
| +// these, and that several of its guards could be removed unseen. |
| +// |
| +// MUTATION-TESTED 2026-10-26, each reverted: valueOnly ignoring prose |
| +// before the value → "prose before a value above"; the total lookback |
| +// bound removed → "beyond the lookback"; an over-long label's text |
| +// dropped while NoBox stays → "over-long above"; indentation ignored → |
| +// "another list's value"; the earlier-span rule removed → "a value ends |
| +// the label line"; leading bidi trimmed → "bidi above"; a straddling |
| +// label line treated as an ordinary one → "a label line beyond the |
| +// lookback is over-long, not truncated". |
| +func TestALabelAboveKeepsRuleTwosProtections(t *testing.T) { |
| + long := strings.Repeat("x", MaxLabel+1) |
| + var many strings.Builder |
| + many.WriteString("Office:\n") |
| + for i := 0; i < 30; i++ { |
| + many.WriteString("+353 (0)1 547 " + strconv.Itoa(1000+i) + "\n") |
| + } |
| + // A label line that begins beyond the lookback: twenty sibling |
| + // values use most of the window, so only the line's tail is in view. |
| + var straddle strings.Builder |
| + straddle.WriteString(strings.Repeat("This is the number for the shared kitchen on the third floor ", 2) + "Office:\n") |
| + for i := 0; i < 20; i++ { |
| + straddle.WriteString("+353 (0)1 547 " + strconv.Itoa(2000+i) + "\n") |
| + } |
| + for _, c := range []struct { |
| + name, text string |
| + at int // which found value to check |
| + label string |
| + own, noBox bool |
| + }{ |
| + {"bidi above", "\u202eeciffO\u202c:\n+353 (0)1 547 7854", 0, "\u202eeciffO\u202c", true, false}, |
| + {"a value ends the label line", "Phone: +353 (0)1 547 7854 -\n+353 (0)1 598 1234", 1, "Contact", false, false}, |
| + {"another list's value", "- Unused phone numbers:\n - +353 (0)1 547 7854\n- +353 (0)1 598 1234", 1, "Contact", false, false}, |
| + {"a nested value under its parent", "- Unused phone numbers:\n - +353 (0)1 547 7854\n- +353 (0)1 598 1234", 0, "Unused phone numbers", true, false}, |
| + {"prose before a value above", "Office:\nCall +353 (0)1 547 7854\n+353 (0)1 598 1234", 1, "Contact", false, false}, |
| + {"over-long above", long + ":\n+353 (0)1 547 7854", 0, long, true, true}, |
| + {"beyond the lookback", many.String(), 29, "Contact", false, false}, |
| + {"within the lookback", many.String(), 1, "Office", true, false}, |
| + {"a label line beyond the lookback is over-long, not truncated", straddle.String(), 19, |
| + "", true, true}, |
| + } { |
| + got := Scan(c.text, "Contact", "Tito", []Kind{Phone}) |
| + if c.at >= len(got) { |
| + t.Fatalf("%s: Scan found %d, want at least %d", c.name, len(got), c.at+1) |
| + } |
| + f := got[c.at] |
| + if c.label == "" && c.noBox { |
| + // Only the state is pinned: the label text is the visible |
| + // tail, which no reader is shown. |
| + if !f.NoBox || !f.Own { |
| + t.Errorf("%s: own = %v noBox = %v (label %q), want own and noBox", c.name, f.Own, f.NoBox, f.Label) |
| + } |
| + continue |
| + } |
| + if f.Label != c.label || f.Own != c.own || f.NoBox != c.noBox { |
| + t.Errorf("%s: label = %q own = %v noBox = %v, want %q own = %v noBox = %v", |
| + c.name, f.Label, f.Own, f.NoBox, c.label, c.own, c.noBox) |
| + } |
| + } |
| +} |
diff --git a/internal/memoria/narrow_test.go b/internal/memoria/narrow_test.go| index 096c76f..b637e04 100644 |
| --- a/internal/memoria/narrow_test.go |
| +++ b/internal/memoria/narrow_test.go |
| @@ -166,6 +166,21 @@ func TestGate40NarrowingPicksExactlyOneOverTheCap(t *testing.T) { |
| one(t, searchFacts(t, s, "what is the office phone number?"), "+353 (0)1 547 7854", phone(3, "office")) |
| }) |
| + // Paul's live Office page as it is stored, 2026-10-26: Notion's soft |
| + // line breaks put each label on one line and its numbers on the next. |
| + // ?explain=facts showed every number falling to the heading. |
| + t.Run("labels on the line above", func(t *testing.T) { |
| + live := "## Office Address\n\n" + |
| + "- Turn the knob\nThe office phone number is:\n+353 (0)1 547 7854\n" + |
| + "We also have the following unused phone numbers:\n+353 (0)1 598 5125\n+353 (0)1 515 7175\n+353 (0)1 534 6069" |
| + s := factCorpus(t, visible(), [][3]string{{"o", "Office", live}}) |
| + p := searchFacts(t, s, "office phone number") |
| + one(t, p, "+353 (0)1 547 7854", phone(3, "office")) |
| + if p.Facts[0].Label != "The office phone number is" { |
| + t.Errorf("label = %q, want the line above", p.Facts[0].Label) |
| + } |
| + }) |
| + |
| t.Run("under the cap nothing changes", func(t *testing.T) { |
| s := page(t, "## Office\n\nOffice phone: +353 (0)1 547 0001\n\nReception: +353 (0)1 547 0002\n\nSales: +353 (0)1 547 0003") |
| p := searchFacts(t, s, "office phone") |
diff --git a/internal/memoria/static/memoria.css b/internal/memoria/static/memoria.css| index 185bd6d..fc2f20a 100644 |
| --- a/internal/memoria/static/memoria.css |
| +++ b/internal/memoria/static/memoria.css |
| @@ -256,6 +256,15 @@ html { scrollbar-gutter: stable; } |
| [rst-results] { list-style: none; margin: 0; padding: 0; } |
| [rst-result] { border-top: 1px solid var(--rst-line); padding: 1.1rem 0; } |
| +/* The whole result opens it (Paul, 2026-10-26). search.js does the |
| + * clicking and marks the list once it can; without the script the title |
| + * is the link, as ever. Not a stretched overlay: that made snippet text |
| + * impossible to select (review, 2026-10-26). */ |
| +[rst-results-clickable] [rst-result] { cursor: pointer; } |
| +@media (hover: hover) { |
| + [rst-results-clickable] [rst-result] { border-radius: var(--rst-radius-sm, 6px); margin-inline: -0.75rem; padding-inline: 0.75rem; } |
| + [rst-results-clickable] [rst-result]:hover { background: var(--rst-surface-2, var(--rst-line)); } |
| +} |
| [rst-result]:first-child { border-top: 0; } |
| /* The document's ancestry in its source, above the title. Sits above |
| rather than below because it is read as a location — "Handbook › |
diff --git a/internal/memoria/static/search.js b/internal/memoria/static/search.js| index 95710b2..0261329 100644 |
| --- a/internal/memoria/static/search.js |
| +++ b/internal/memoria/static/search.js |
| @@ -405,3 +405,42 @@ |
| } |
| }); |
| })(); |
| + |
| +/* The whole result opens it (Paul, 2026-10-26: "Can the whole segment be |
| + clickable rather than just the title?"). A click anywhere on a result |
| + follows its title's link, unless the click was selecting text: a drag |
| + that moved, a selection left on the page, or a double-click: the first |
| + click waits briefly and then goes nowhere if a selection has appeared, |
| + which is what a double-click leaves. Cmd, Ctrl or Shift |
| + opens a new tab, as they do on a link. Links and controls inside a |
| + result keep their own clicks. The title stays the one real link, so |
| + keyboard and screen-reader use is unchanged, and without this script |
| + only the title is clickable. */ |
| +(function () { |
| + "use strict"; |
| + var WAIT_MS = 220; |
| + var downAt = null; |
| + document.documentElement.setAttribute("rst-results-clickable", ""); |
| + function selecting() { |
| + return !!(window.getSelection && String(window.getSelection())); |
| + } |
| + document.addEventListener("mousedown", function (e) { |
| + downAt = [e.clientX, e.clientY]; |
| + }); |
| + document.addEventListener("click", function (e) { |
| + if (e.button !== 0 || !e.target.closest) return; |
| + var row = e.target.closest("[rst-result]"); |
| + if (!row || e.target.closest("a, button, input, select, textarea, label")) return; |
| + var link = row.querySelector("[rst-result-title]"); |
| + if (!link) return; |
| + if (e.detail > 1 || selecting()) return; |
| + if (downAt && (Math.abs(e.clientX - downAt[0]) > 4 || Math.abs(e.clientY - downAt[1]) > 4)) return; |
| + if (e.metaKey || e.ctrlKey || e.shiftKey) { |
| + window.open(link.href, "_blank", "noopener"); |
| + return; |
| + } |
| + setTimeout(function () { |
| + if (!selecting()) window.location.assign(link.href); |
| + }, WAIT_MS); |
| + }); |
| +})(); |
diff --git a/internal/memoriatest/resultlink_browser_test.go b/internal/memoriatest/resultlink_browser_test.go| new file mode 100644 |
| index 0000000..2c56ed8 |
| --- /dev/null |
| +++ b/internal/memoriatest/resultlink_browser_test.go |
| @@ -0,0 +1,118 @@ |
| +//go:build browser |
| + |
| +// The whole result opens it (Paul, 2026-10-26: "Can the whole segment be |
| +// clickable rather than just the title?"), without taking away text |
| +// selection in the snippet (review, 2026-10-26: a stretched overlay made |
| +// a double-click select nothing). Run with `make browser`. |
| +// |
| +// MUTATION-TESTED 2026-10-26, each reverted: the click handler removed → |
| +// "clicking the second result's snippet left the page at …"; the |
| +// destination taken from the first result → "went to …/documents/2#p0, |
| +// want the second result's document"; the selection check when the wait |
| +// ends removed → "a double-click to select a word left the page". A |
| +// dblclick listener and a second-click cancel were each mutated away and |
| +// stayed green beside that check, so both were deleted. |
| +package memoriatest |
| + |
| +import ( |
| + "context" |
| + "io" |
| + "log/slog" |
| + "net/http" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/rastrillo/rastrillo/db" |
| + "amadan.net/rastrillo/rastrillo/harness" |
| + "github.com/chromedp/chromedp" |
| + |
| + memoria "amadan.net/oficina/memoria/internal/memoria" |
| +) |
| + |
| +func TestTheWholeResultIsALink(t *testing.T) { |
| + rig := harness.New(t, func(origin string) http.Handler { |
| + logger := slog.New(slog.NewTextHandler(io.Discard, nil)) |
| + d, err := db.Open(filepath.Join(t.TempDir(), "app.db"), logger) |
| + if err != nil { |
| + t.Fatalf("db.Open: %v", err) |
| + } |
| + t.Cleanup(func() { d.Close() }) |
| + mux, a, err := memoria.AppForTest(d, origin, testDEK(t), logger) |
| + if err != nil { |
| + t.Fatalf("AppForTest: %v", err) |
| + } |
| + for _, doc := range [][2]string{ |
| + {"Office", "## Office Maintenance\n\nAlan Brady works for the management agency and can be contacted any weekday."}, |
| + {"Kitchen", "## Supplies\n\nThe agency restocks the kitchen every Monday morning before nine."}, |
| + } { |
| + if _, err := a.Store().Ingest(context.Background(), memoria.IngestSpec{ |
| + Source: "upload", Key: doc[0], Title: doc[0], Body: doc[1], |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + return mux |
| + }) |
| + run := func(what string, actions ...chromedp.Action) { |
| + t.Helper() |
| + ctx, cancel := context.WithTimeout(rig.Context(), 20*time.Second) |
| + defer cancel() |
| + if err := chromedp.Run(ctx, actions...); err != nil { |
| + t.Fatalf("%s: %v", what, err) |
| + } |
| + } |
| + search := rig.Origin + "/?q=agency" |
| + |
| + // Each result opens its own document: the second's snippet goes to |
| + // the second's title link, not the first's. |
| + var want, at string |
| + run("click the second result", |
| + chromedp.Navigate(search), |
| + chromedp.WaitVisible(`[rst-result]:nth-child(2) [rst-result-snippet]`, chromedp.ByQuery), |
| + chromedp.AttributeValue(`[rst-result]:nth-child(2) [rst-result-title]`, "href", &want, nil, chromedp.ByQuery), |
| + chromedp.Click(`[rst-result]:nth-child(2) [rst-result-snippet]`, chromedp.ByQuery), |
| + chromedp.Sleep(800*time.Millisecond), |
| + chromedp.Location(&at), |
| + ) |
| + if !strings.Contains(at, "/documents/") { |
| + t.Fatalf("clicking the second result's snippet left the page at %s", at) |
| + } |
| + if !strings.HasSuffix(at, want) { |
| + t.Errorf("went to %s, want the second result's document %s", at, want) |
| + } |
| + |
| + // A double-click selects a word and goes nowhere. |
| + var picked string |
| + run("double-click a word", |
| + chromedp.Navigate(search), |
| + chromedp.WaitVisible(`[rst-result-snippet]`, chromedp.ByQuery), |
| + // A real double-click is two clicks: the first with a click |
| + // count of one, then the second with two. chromedp's DoubleClick |
| + // sends only the second, which skips the very path under test. |
| + chromedp.Click(`[rst-result-snippet] mark`, chromedp.ByQuery), |
| + chromedp.DoubleClick(`[rst-result-snippet] mark`, chromedp.ByQuery), |
| + chromedp.Sleep(800*time.Millisecond), |
| + chromedp.Evaluate(`String(window.getSelection())`, &picked), |
| + chromedp.Location(&at), |
| + ) |
| + if strings.Contains(at, "/documents/") { |
| + t.Errorf("a double-click to select a word left the page for %s", at) |
| + } |
| + if strings.TrimSpace(picked) == "" { |
| + t.Error("a double-click selected nothing") |
| + } |
| + |
| + // Outside a result, a click is just a click. |
| + run("click the heading", |
| + chromedp.Navigate(search), |
| + chromedp.WaitVisible(`h2`, chromedp.ByQuery), |
| + chromedp.Click(`h2`, chromedp.ByQuery), |
| + chromedp.Sleep(800*time.Millisecond), |
| + chromedp.Location(&at), |
| + ) |
| + if strings.Contains(at, "/documents/") { |
| + t.Errorf("a click on the heading left the page for %s", at) |
| + } |
| +} |