Files
clide/lib/kernel/src/recent_files.dart
T
jpmschweitzerandClaude Opus 4.8 0c7a6e86d5 add quick-open fuzzy file finder (Ctrl/Cmd+P)
A file picker overlay over the whole workspace, distinct from the
command palette. QuickOpenController holds the file list + a
subsequence fuzzy filter; the overlay loads the list via files.walk on
open, shows RecentFilesService entries on an empty query, and opens the
selection through a shared openWorkspaceFile helper (.md → markdown
reader bus, else editor.open) that the files panel now also routes
through, so recents stay in sync from every open site.

Bound to ctrl+p / meta+p with `when: !palette.open` so it never
collides with the palette's ctrl+p navigation; in-overlay arrows/enter/
escape reuse the palette's keymap-driven model via quickOpen.* intents.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-31 20:19:21 +02:00

36 lines
1.1 KiB
Dart

/// A bounded, most-recent-first list of repo-relative file paths opened
/// this session. Backs the quick-open overlay's empty-query state
/// (T-51). In-memory only — recents reset per app run, matching the
/// session-scoped "recently opened within a workspace" convention.
library;
import 'package:flutter/foundation.dart';
class RecentFilesService extends ChangeNotifier {
RecentFilesService({this.cap = 20});
/// Maximum number of paths retained; the oldest fall off the end.
final int cap;
final List<String> _paths = [];
/// Most-recent-first snapshot of the retained paths.
List<String> get paths => List.unmodifiable(_paths);
/// Record [path] as the most-recently opened file: moves an existing
/// entry to the front (no duplicates) and trims to [cap].
void push(String path) {
if (path.isEmpty) return;
_paths.remove(path);
_paths.insert(0, path);
if (_paths.length > cap) _paths.removeRange(cap, _paths.length);
notifyListeners();
}
void clear() {
if (_paths.isEmpty) return;
_paths.clear();
notifyListeners();
}
}