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:
@@ -5,6 +5,7 @@ import 'package:flutter/rendering.dart';
|
||||
|
||||
import 'chat_transcript_selection.dart';
|
||||
import 'chat_code_hover.dart';
|
||||
import 'chat_find_highlight.dart';
|
||||
import '../../../../ui/text/monospace.dart';
|
||||
import 'chat_link_launcher.dart';
|
||||
import 'chat_link_spans.dart';
|
||||
@@ -110,7 +111,7 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
// The text is built once and never restyled while speaking; the
|
||||
// spoken word is painted behind it, so nothing shifts or rewraps.
|
||||
final rendered = _rendered ??= _buildRendered(context);
|
||||
return CustomPaint(
|
||||
final spoken = CustomPaint(
|
||||
key: _paintKey,
|
||||
painter: SpokenWordPainter(
|
||||
anchor: _paintKey,
|
||||
@@ -121,6 +122,13 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
),
|
||||
child: rendered,
|
||||
);
|
||||
// Find's matches are painted the same way, behind the text.
|
||||
return ChatFindHighlight(
|
||||
text: widget.text,
|
||||
rects: (start, end, box) =>
|
||||
spokenWordRects(_segments, (start: start, end: end), box),
|
||||
child: spoken,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -252,6 +260,7 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
],
|
||||
);
|
||||
case MarkdownCode(language: final language, code: final code):
|
||||
final codeKey = _codeSegment(code);
|
||||
_skipCodeBlock(code);
|
||||
final labelStyle = _roleStyle(
|
||||
context,
|
||||
@@ -267,6 +276,7 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
child: ChatTranscriptHorizontalScrollView(
|
||||
label: 'code block',
|
||||
child: Text.rich(
|
||||
key: codeKey,
|
||||
TextSpan(
|
||||
children: _linked(
|
||||
context,
|
||||
@@ -283,6 +293,27 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Records where a code block's text renders, character for character
|
||||
/// from its place in the source, so find can highlight matches in it.
|
||||
GlobalKey _codeSegment(String code) {
|
||||
if (_textCount == _textKeys.length) _textKeys.add(GlobalKey());
|
||||
final key = _textKeys[_textCount++];
|
||||
final start = code.isEmpty ? -1 : widget.text.indexOf(code, _sourceCursor);
|
||||
if (start >= 0) {
|
||||
_segments.add(
|
||||
MarkdownSpokenSegment(
|
||||
key,
|
||||
start,
|
||||
start + code.length,
|
||||
0,
|
||||
code.length,
|
||||
List<int>.generate(code.length, (index) => start + index),
|
||||
),
|
||||
);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
void _skipCodeBlock(String code) {
|
||||
_sourceCursor = fencedCodeSpan(
|
||||
widget.text,
|
||||
|
||||
Reference in New Issue
Block a user