Chat: find in chat (Ctrl+F / Cmd+F)

A find bar over the transcript: query, Match case, n of N (counted from
the newest), Enter for an older match and Shift+Enter for a newer one.
Matches are painted over the rendered text, code blocks included, without
restyling it; the current match is scrolled into view. Matches in history
not loaded yet come from the server's chat:<id>-scoped search and are
reached by loading older pages. Esc closes and returns to the composer.
The key is the pane's, so a focused terminal keeps Ctrl+F. Fixture answers
scoped searches for captures; cheatsheet lists the key. The scoped search
matches the query as typed, spaces included, like the client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 00:41:39 +00:00
parent 32c9c6b1df
commit 8bd219e636
14 changed files with 1581 additions and 126 deletions
+39
View File
@@ -310,3 +310,42 @@ void chatScrollStream(String sessionId, void Function(JsonMap frame) emit) {
});
});
}
/// A scoped find-in-chat search (`scope: chat:<id>`) the way
/// `internal/server/search_chat_scoped.go` answers it: every occurrence in
/// the text parts of the history before [cursor] ("0|older" for the page
/// `?older=1` holds back), newest message first.
List<JsonMap> chatScrollScopedHits(
String sessionId,
String cursor,
String query,
bool caseSensitive,
) {
if (!_older || !cursor.endsWith('|older') || query.trim().isEmpty) {
return const [];
}
final pattern = RegExp(RegExp.escape(query), caseSensitive: caseSensitive);
final hits = <JsonMap>[];
for (var i = -1; i >= -20; i--) {
final message = _message(sessionId, i);
final parts = message['parts'] as List;
for (var part = 0; part < parts.length; part++) {
final body = parts[part] as Map;
if (body['type'] != 'text') continue;
for (final match in pattern.allMatches('${body['text']}')) {
hits.add({
'kind': 'chat',
'target': 'chat:$sessionId',
'chat': {
'session_id': sessionId,
'message_id': message['id'],
'part': part,
'offset': match.start,
'length': match.end - match.start,
},
});
}
}
}
return hits;
}