d407a72a06
Left/right and h/l step between files (or headers in the all-files view), up/down and j/k scroll, / opens find-in-diff (highlighted matches across every file, n/N or Enter/Shift+Enter to move, Escape to close), and a top-bar toggle switches between one file at a time and every file stacked with collapsible headers, like a pull request's Files changed tab. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
3.2 KiB
Dart
103 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
/// The find-in-diff field `/` opens: the query, "3 of 12", previous and next
|
|
/// match, and close. Enter goes to the next match, Shift+Enter to the
|
|
/// previous one, Escape closes.
|
|
class DiffSearchBar extends StatelessWidget {
|
|
const DiffSearchBar({
|
|
super.key,
|
|
required this.controller,
|
|
required this.focusNode,
|
|
required this.position,
|
|
required this.count,
|
|
required this.onChanged,
|
|
required this.onNext,
|
|
required this.onPrevious,
|
|
required this.onClose,
|
|
});
|
|
|
|
final TextEditingController controller;
|
|
final FocusNode focusNode;
|
|
|
|
/// The current match, counted from 1; 0 when there is none.
|
|
final int position;
|
|
final int count;
|
|
final ValueChanged<String> onChanged;
|
|
final VoidCallback onNext;
|
|
final VoidCallback onPrevious;
|
|
final VoidCallback onClose;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final summary = controller.text.isEmpty
|
|
? ''
|
|
: count == 0
|
|
? 'No matches'
|
|
: '$position of $count';
|
|
return Material(
|
|
elevation: 3,
|
|
borderRadius: BorderRadius.circular(28),
|
|
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
|
child: Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 4, 4),
|
|
child: Row(
|
|
children: [
|
|
const Icon(Icons.search),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: CallbackShortcuts(
|
|
bindings: {
|
|
const SingleActivator(LogicalKeyboardKey.enter, shift: true):
|
|
onPrevious,
|
|
const SingleActivator(LogicalKeyboardKey.escape): onClose,
|
|
},
|
|
child: TextField(
|
|
key: const ValueKey('diff-search-field'),
|
|
controller: controller,
|
|
focusNode: focusNode,
|
|
autofocus: true,
|
|
decoration: const InputDecoration(
|
|
hintText: 'Find in diff',
|
|
border: InputBorder.none,
|
|
isDense: true,
|
|
),
|
|
onChanged: onChanged,
|
|
onSubmitted: (_) {
|
|
onNext();
|
|
focusNode.requestFocus();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
if (summary.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
child: Text(
|
|
summary,
|
|
key: const ValueKey('diff-search-summary'),
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
),
|
|
IconButton(
|
|
tooltip: 'Previous match',
|
|
onPressed: count == 0 ? null : onPrevious,
|
|
icon: const Icon(Icons.keyboard_arrow_up),
|
|
),
|
|
IconButton(
|
|
tooltip: 'Next match',
|
|
onPressed: count == 0 ? null : onNext,
|
|
icon: const Icon(Icons.keyboard_arrow_down),
|
|
),
|
|
IconButton(
|
|
tooltip: 'Close search',
|
|
onPressed: onClose,
|
|
icon: const Icon(Icons.close),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|