Open a diff as a floating window
Diffs join the app's window system: Open in a window on a diff page or a chat diff card shows the same files, on the same file, in a draggable, resizable window with the full diff viewer (keys, search, all-files view). Offered only where floating windows show; a diff window's files live in memory, so it is not restored after a reload. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import 'diff_search_bar.dart';
|
||||
import 'diff_search_controller.dart';
|
||||
import 'file_diff_viewer.dart';
|
||||
import 'stacked_diff_view.dart';
|
||||
import '../windows/diff_windows.dart';
|
||||
|
||||
/// Whether diff pages show every file stacked (GitHub's Files changed) rather
|
||||
/// than one file at a time. Remembered for the rest of the session.
|
||||
@@ -29,20 +30,35 @@ Future<void> showFileDiffViewer(
|
||||
}) {
|
||||
final list = files == null || !files.contains(file) ? [file] : files;
|
||||
final page = FileDiffPage(files: list, initialIndex: list.indexOf(file));
|
||||
return Navigator.of(
|
||||
context,
|
||||
).push<void>(MaterialPageRoute<void>(builder: (_) => page));
|
||||
// The page may sit above the shell: carry the app's diff windows into it
|
||||
// so it can offer Open in a window.
|
||||
final windows = DiffWindowsScope.windowsOf(context);
|
||||
return Navigator.of(context).push<void>(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => windows == null
|
||||
? page
|
||||
: DiffWindowsScope(windows: windows, child: page),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// A diff's files as a page: one file at a time with previous/next, or every
|
||||
/// file stacked with collapsible headers. The keyboard steps between files
|
||||
/// (arrows, `h`/`l`), scrolls (arrows, `j`/`k`) and searches (`/`, `n`/`N`).
|
||||
class FileDiffPage extends StatefulWidget {
|
||||
const FileDiffPage({super.key, required this.files, this.initialIndex = 0});
|
||||
const FileDiffPage({
|
||||
super.key,
|
||||
required this.files,
|
||||
this.initialIndex = 0,
|
||||
this.inWindow = false,
|
||||
});
|
||||
|
||||
final List<FileChange> files;
|
||||
final int initialIndex;
|
||||
|
||||
/// Shown inside a floating window: no Back, and no Open in a window.
|
||||
final bool inWindow;
|
||||
|
||||
@override
|
||||
State<FileDiffPage> createState() => _FileDiffPageState();
|
||||
}
|
||||
@@ -157,6 +173,13 @@ class _FileDiffPageState extends State<FileDiffPage> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Leaves the page and shows the same files, on the same file, in a
|
||||
/// floating window.
|
||||
void _openInWindow(DiffWindows windows) {
|
||||
Navigator.of(context).maybePop();
|
||||
windows.open(widget.files, initialIndex: _index);
|
||||
}
|
||||
|
||||
void _toggleFile(int index) => setState(() {
|
||||
if (!_collapsed.remove(index)) _collapsed.add(index);
|
||||
});
|
||||
@@ -249,7 +272,18 @@ class _FileDiffPageState extends State<FileDiffPage> {
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: SegmentedBar(
|
||||
title: title,
|
||||
automaticallyImplyLeading: !widget.inWindow,
|
||||
actions: [
|
||||
if (!widget.inWindow)
|
||||
?switch (DiffWindowsScope.maybeOf(context)) {
|
||||
final windows? => IconButton(
|
||||
key: const ValueKey('diff-open-window'),
|
||||
tooltip: 'Open in a window',
|
||||
onPressed: () => _openInWindow(windows),
|
||||
icon: const Icon(Icons.open_in_new),
|
||||
),
|
||||
null => null,
|
||||
},
|
||||
IconButton(
|
||||
key: const ValueKey('diff-search-open'),
|
||||
tooltip: 'Find in diff (/)',
|
||||
|
||||
Reference in New Issue
Block a user