Files
pipelines/app/lib/features/changes/widgets/diff_highlight.dart
T
alan d407a72a06 Diff viewer: vim keys, scrolling, find in diff and an all-files view
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>
2026-11-21 18:13:08 +00:00

44 lines
1.3 KiB
Dart

import 'package:flutter/widgets.dart';
import '../domain/diff_search.dart';
/// The active diff search, handed down to the rendered patch lines: the query
/// they highlight, the current match drawn stronger and the key that match's
/// line carries so the page can scroll it into view.
class DiffHighlight extends InheritedWidget {
const DiffHighlight({
super.key,
required this.query,
required this.current,
required this.currentKey,
required super.child,
});
final String query;
final DiffMatch? current;
final GlobalKey currentKey;
bool get active => query.trim().isNotEmpty;
static DiffHighlight? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<DiffHighlight>();
@override
bool updateShouldNotify(DiffHighlight oldWidget) =>
query != oldWidget.query || current != oldWidget.current;
}
/// The index of the file a rendered patch belongs to in the viewed list, so a
/// line can tell whether the current match is on it.
class DiffFileIndex extends InheritedWidget {
const DiffFileIndex({super.key, required this.index, required super.child});
final int index;
static int? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<DiffFileIndex>()?.index;
@override
bool updateShouldNotify(DiffFileIndex oldWidget) => index != oldWidget.index;
}