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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -709,6 +709,25 @@ JsonMap? probeReply(JsonMap request) {
|
||||
// The app must send exactly the browser's SearchRequest body; anything
|
||||
// else is answered with a visible refusal so the capture cannot pass.
|
||||
final search = request['search'];
|
||||
if (search is Map && search['scope'] is String) {
|
||||
// Find in chat: every occurrence in history not loaded yet.
|
||||
final session = '${search['scope']}'.replaceFirst('chat:', '');
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'search_results',
|
||||
'search_results': {
|
||||
'query': search['query'],
|
||||
'kind': 'chat',
|
||||
'results': chatScrollScopedHits(
|
||||
session,
|
||||
'${search['cursor'] ?? ''}',
|
||||
'${search['query'] ?? ''}',
|
||||
search['case_sensitive'] == true,
|
||||
),
|
||||
'cap': 200,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (search is! Map ||
|
||||
search.length != 3 ||
|
||||
search['query'] is! String ||
|
||||
|
||||
Reference in New Issue
Block a user