8bd219e636
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>
78 lines
2.4 KiB
Dart
78 lines
2.4 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'chat_find_highlight.dart';
|
|
import 'chat_link_launcher.dart';
|
|
import 'chat_link_spans.dart';
|
|
import 'chat_links.dart';
|
|
import 'chat_transcript_selection.dart';
|
|
|
|
/// Plain selectable text with its bare links made tappable: the operator's
|
|
/// own message keeps every character exactly as typed (no markdown), and its
|
|
/// `http(s)://`/`www.` runs, in `` `code` `` too, become links. Text without a
|
|
/// link stays a plain [SelectableText] outside a shared transcript document.
|
|
class ChatLinkText extends StatefulWidget {
|
|
const ChatLinkText(this.text, {super.key});
|
|
|
|
final String text;
|
|
|
|
@override
|
|
State<ChatLinkText> createState() => _ChatLinkTextState();
|
|
}
|
|
|
|
class _ChatLinkTextState extends State<ChatLinkText> {
|
|
late final ChatLinkSpans _links = ChatLinkSpans(
|
|
onChanged: () => setState(() {}),
|
|
);
|
|
late List<ChatTextLink> _found = findTextLinks(widget.text);
|
|
|
|
@override
|
|
void didUpdateWidget(ChatLinkText oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (widget.text != oldWidget.text) _found = findTextLinks(widget.text);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_links.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
final _textKey = GlobalKey();
|
|
|
|
/// The text with find's matches painted behind it; it renders verbatim,
|
|
/// so a match's offsets are the rendered characters'.
|
|
@override
|
|
Widget build(BuildContext context) => ChatFindHighlight(
|
|
text: widget.text,
|
|
rects: (start, end, box) =>
|
|
chatFindPlainRects(_textKey.currentContext, start, end, box),
|
|
child: KeyedSubtree(key: _textKey, child: _text(context)),
|
|
);
|
|
|
|
Widget _text(BuildContext context) {
|
|
final text = widget.text;
|
|
if (_found.isEmpty) {
|
|
return ChatTranscriptSelectionScope.maybeOf(context) == null
|
|
? SelectableText(text)
|
|
: Text(text);
|
|
}
|
|
final spans = <InlineSpan>[];
|
|
var at = 0;
|
|
for (final link in _found) {
|
|
if (link.start > at) {
|
|
spans.add(TextSpan(text: text.substring(at, link.start)));
|
|
}
|
|
spans.add(
|
|
_links.link(context, link.target, [
|
|
TextSpan(text: text.substring(link.start, link.end)),
|
|
], onOpen: (uri) => unawaited(openChatLink(context, uri))),
|
|
);
|
|
at = link.end;
|
|
}
|
|
if (at < text.length) spans.add(TextSpan(text: text.substring(at)));
|
|
return _links.selectionArea(context, Text.rich(TextSpan(children: spans)));
|
|
}
|
|
}
|