snippetAround returns a trimmed, single-line window of content centered on the first occurrence of term, capped to keep search output compact.
(content, lowerContent, term string)
| 285 | // snippetAround returns a trimmed, single-line window of content centered on |
| 286 | // the first occurrence of term, capped to keep search output compact. |
| 287 | func snippetAround(content, lowerContent, term string) string { |
| 288 | const window = 120 |
| 289 | idx := strings.Index(lowerContent, term) |
| 290 | if idx < 0 { |
| 291 | idx = 0 |
| 292 | } |
| 293 | start := idx - window/2 |
| 294 | if start < 0 { |
| 295 | start = 0 |
| 296 | } |
| 297 | end := idx + window/2 |
| 298 | if end > len(content) { |
| 299 | end = len(content) |
| 300 | } |
| 301 | s := strings.TrimSpace(strings.ReplaceAll(content[start:end], "\n", " ")) |
| 302 | if start > 0 { |
| 303 | s = "…" + s |
| 304 | } |
| 305 | if end < len(content) { |
| 306 | s += "…" |
| 307 | } |
| 308 | return s |
| 309 | } |
| 310 | |
| 311 | // ForkSession creates a copy of an existing session with a new name. |
| 312 | // The forked session is an independent copy — changes to either session don't affect the other. |
no outgoing calls