feat(app): hubs, types and tags UI, themes, key bindings and slash commands

Settings screen (themes incl. Sweet, rebindable shortcuts), rich text escapes,
page sidebar with the local graph, sortable All pages, tree view changes and the
Type/Tags rows in the page header. Docs updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Sonnet 5.5 committed 2026-10-26 02:45:22 +01:00
1 parent e18fd2c27e
commit 88ef4a97a5
32 files changed
+5431 -375

No files matched your search

+106 -18
View File
@@ -2,6 +2,9 @@ import 'package:flutter/material.dart';
import '../backend/graph_backend.dart';
import '../graph/network_canvas.dart';
import '../theme/theme.dart';
import 'keymap.dart';
import 'settings.dart';
import 'write_queue.dart';
sealed class AppRoute {
@@ -20,12 +23,15 @@ class AllPagesRoute extends AppRoute {
const AllPagesRoute();
}
class SettingsRoute extends AppRoute {
const SettingsRoute();
}
enum GraphMode {
network('Network', Icons.hub_outlined),
local('Local', Icons.adjust_rounded),
brain('Synapses', Icons.bolt_outlined),
clusters('Clusters', Icons.bubble_chart_outlined),
tree('Namespaces', Icons.account_tree_outlined),
tree('Tree', Icons.account_tree_outlined),
timeline('Timeline', Icons.timeline_rounded);
const GraphMode(this.label, this.icon);
@@ -54,10 +60,56 @@ class PageTarget extends AppRoute {
/// page, so a framework (Riverpod, Bloc) would add a dependency and indirection without
/// paying for itself; rebuilds are scoped with `ListenableBuilder`.
class AppState extends ChangeNotifier {
AppState(this.backend, {WriteQueue? queue})
AppState(this.backend, {WriteQueue? queue, SettingsStore? settings})
: refs = BlockRefCache(backend),
queue = queue ?? WriteQueue() {
queue = queue ?? WriteQueue(),
_settings = settings ?? MemorySettings() {
this.queue.onError = _writeFailed;
final saved = _settings.load();
final id = saved['theme'];
if (id is String && (id == autoThemeId || themeById(id) != null)) {
themeId = id;
}
final keys = saved['keys'];
keymap = Keymap(
keys is Map
? {for (final e in keys.entries) '${e.key}': '${e.value}'}
: {},
);
}
final SettingsStore _settings;
/// Key bindings (defaults plus the user's overrides).
late final Keymap keymap;
/// Selected theme id (`auto` follows the system).
String themeId = autoThemeId;
void _saveSettings() {
_settings.save({'theme': themeId, 'keys': keymap.toJson()});
}
void setTheme(String id) {
themeId = id;
_saveSettings();
notifyListeners();
}
/// Binds `combo` to `action`; returns the action already using it (nothing changes then).
AppAction? bindKey(AppAction action, Combo combo) {
final owner = keymap.bind(action, combo);
if (owner == null) {
_saveSettings();
notifyListeners();
}
return owner;
}
void resetKey(AppAction? action) {
action == null ? keymap.resetAll() : keymap.reset(action);
_saveSettings();
notifyListeners();
}
final GraphBackend backend;
@@ -67,7 +119,6 @@ class AppState extends ChangeNotifier {
AppRoute _route = const JournalsRoute();
final _back = <AppRoute>[];
final _forward = <AppRoute>[];
ThemeMode themeMode = ThemeMode.system;
final List<PageBrief> recent = [];
/// Node positions shared by the graph views (stable layouts across modes and filters).
@@ -79,6 +130,17 @@ class AppState extends ChangeNotifier {
/// Bumped to make the current view reload from the core (failed writes, renames).
int generation = 0;
/// Hubs expanded in the sidebar tree (kept here so it survives sidebar rebuilds).
final expandedHubs = <String>{};
/// Right sidebar of the page editor (local graph + related pages); collapsed by default.
bool pageSidebar = false;
void togglePageSidebar() {
pageSidebar = !pageSidebar;
notifyListeners();
}
/// Last write error, shown once by the shell.
String? writeError;
@@ -107,6 +169,25 @@ class AppState extends ChangeNotifier {
notifyListeners();
}
/// Points the current route and any history entry that opens `oldTitle` at the page `id`,
/// without pushing history (the page was renamed or converted, so its old title no longer
/// exists and opening it would create an empty duplicate).
void replaceWithId(String id, String oldTitle) {
final key = oldTitle.toLowerCase();
AppRoute fix(AppRoute r) =>
r is PageTarget && r.id == null && r.title!.toLowerCase() == key
? PageTarget(id: id)
: r;
if (_route is PageTarget) _route = PageTarget(id: id);
for (final l in [_back, _forward]) {
for (var i = 0; i < l.length; i++) {
l[i] = fix(l[i]);
}
}
generation++;
notifyListeners();
}
void back() {
if (_back.isEmpty) return;
_forward.add(_route);
@@ -132,15 +213,19 @@ class AppState extends ChangeNotifier {
queue.run(() => backend.recordVisit(from, page.id)).ignore();
}
recent.removeWhere((p) => p.id == page.id);
recent.insert(
0,
PageBrief(
id: page.id,
title: page.title,
isJournal: page.journalDate != null,
),
);
if (recent.length > 12) recent.removeLast();
// Hubs are folders, not pages: they never show up in recents.
if (!page.isHub) {
recent.insert(
0,
PageBrief(
id: page.id,
title: page.title,
isJournal: page.journalDate != null,
isHub: false,
),
);
if (recent.length > 12) recent.removeLast();
}
notifyListeners();
}
@@ -148,8 +233,10 @@ class AppState extends ChangeNotifier {
Future<void> loadRecent() async {
final pages = await backend.listPages(limit: 8);
for (final p in pages) {
if (!recent.any((r) => r.id == p.id)) {
recent.add(PageBrief(id: p.id, title: p.title, isJournal: false));
if (!p.isHub && !recent.any((r) => r.id == p.id)) {
recent.add(
PageBrief(id: p.id, title: p.title, isJournal: false, isHub: p.isHub),
);
}
}
notifyListeners();
@@ -162,14 +249,15 @@ class AppState extends ChangeNotifier {
id: id,
title: title,
isJournal: recent[i].isJournal,
isHub: recent[i].isHub,
);
}
notifyListeners();
}
/// Top-bar shortcut: flips between the light and dark Paper themes.
void toggleTheme(Brightness current) {
themeMode = current == Brightness.dark ? ThemeMode.light : ThemeMode.dark;
notifyListeners();
setTheme(current == Brightness.dark ? 'paper' : 'paper-dark');
}
}
+151
View File
@@ -0,0 +1,151 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
/// A key plus modifiers. Ctrl also matches Cmd on macOS.
@immutable
class Combo {
const Combo(
this.key, {
this.ctrl = false,
this.shift = false,
this.alt = false,
});
final LogicalKeyboardKey key;
final bool ctrl;
final bool shift;
final bool alt;
/// `ctrl+shift+<keyId>`: stable across platforms and keyboard layouts.
String encode() =>
'${ctrl ? 'ctrl+' : ''}${shift ? 'shift+' : ''}${alt ? 'alt+' : ''}${key.keyId}';
static Combo? decode(String s) {
final parts = s.split('+');
final id = int.tryParse(parts.last);
if (id == null) return null;
final mods = parts.sublist(0, parts.length - 1);
if (mods.any((m) => m != 'ctrl' && m != 'shift' && m != 'alt')) return null;
return Combo(
LogicalKeyboardKey.findKeyByKeyId(id) ?? LogicalKeyboardKey(id),
ctrl: mods.contains('ctrl'),
shift: mods.contains('shift'),
alt: mods.contains('alt'),
);
}
/// A key that is only a modifier cannot be bound on its own.
bool get isModifierOnly => const {
'Control Left',
'Control Right',
'Shift Left',
'Shift Right',
'Alt Left',
'Alt Right',
'Meta Left',
'Meta Right',
}.contains(key.keyLabel);
String get label {
final k = key.keyLabel.isEmpty ? 'Key ${key.keyId}' : key.keyLabel;
return [if (ctrl) 'Ctrl', if (shift) 'Shift', if (alt) 'Alt', k].join('+');
}
@override
bool operator ==(Object other) =>
other is Combo &&
other.key == key &&
other.ctrl == ctrl &&
other.shift == shift &&
other.alt == alt;
@override
int get hashCode => Object.hash(key, ctrl, shift, alt);
}
/// Everything that can be bound to a key. `editor` actions apply inside a focused block;
/// the others anywhere in the app.
enum AppAction {
quickSwitcher('Quick switcher', false),
journals('Journals', false),
graph('Graph view', false),
timeline('Timeline', false),
sidebar('Toggle sidebar', false),
pageSidebar('Toggle graph sidebar', false),
settings('Settings', false),
back('Back', false),
forward('Forward', false),
bold('Bold', true),
italic('Italic', true),
strike('Strikethrough', true),
highlight('Highlight', true),
code('Inline code', true),
link('Page link', true);
const AppAction(this.label, this.editor);
final String label;
final bool editor;
Combo get defaultCombo => switch (this) {
quickSwitcher => Combo(LogicalKeyboardKey.keyK, ctrl: true),
journals => Combo(LogicalKeyboardKey.keyJ, ctrl: true, shift: true),
graph => Combo(LogicalKeyboardKey.keyG, ctrl: true, shift: true),
timeline => Combo(LogicalKeyboardKey.keyT, ctrl: true, shift: true),
sidebar => Combo(LogicalKeyboardKey.backslash, ctrl: true),
pageSidebar => Combo(LogicalKeyboardKey.backslash, ctrl: true, shift: true),
settings => Combo(LogicalKeyboardKey.comma, ctrl: true),
back => Combo(LogicalKeyboardKey.arrowLeft, alt: true),
forward => Combo(LogicalKeyboardKey.arrowRight, alt: true),
bold => Combo(LogicalKeyboardKey.keyB, ctrl: true),
italic => Combo(LogicalKeyboardKey.keyI, ctrl: true),
strike => Combo(LogicalKeyboardKey.keyS, ctrl: true, shift: true),
highlight => Combo(LogicalKeyboardKey.keyH, ctrl: true, shift: true),
code => Combo(LogicalKeyboardKey.keyE, ctrl: true),
link => Combo(LogicalKeyboardKey.keyL, ctrl: true),
};
}
/// Default bindings plus the user's overrides. Combos are unique across all actions; binding
/// one that another action holds is refused (the caller shows which one).
class Keymap {
Keymap([Map<String, String> overrides = const {}]) {
for (final e in overrides.entries) {
final action = AppAction.values.asNameMap()[e.key];
final combo = Combo.decode(e.value);
if (action != null && combo != null) _custom[action] = combo;
}
}
final _custom = <AppAction, Combo>{};
Combo of(AppAction a) => _custom[a] ?? a.defaultCombo;
bool isCustom(AppAction a) => _custom.containsKey(a);
/// The action bound to `c`, if any.
AppAction? actionFor(Combo c, {bool? editor}) {
for (final a in AppAction.values) {
if ((editor == null || a.editor == editor) && of(a) == c) return a;
}
return null;
}
/// Binds `c` to `a`. Returns the action that already holds `c`, leaving the map unchanged.
AppAction? bind(AppAction a, Combo c) {
final owner = actionFor(c);
if (owner != null && owner != a) return owner;
if (c == a.defaultCombo) {
_custom.remove(a);
} else {
_custom[a] = c;
}
return null;
}
void reset(AppAction a) => _custom.remove(a);
void resetAll() => _custom.clear();
Map<String, String> toJson() => {
for (final e in _custom.entries) e.key.name: e.value.encode(),
};
}
+42
View File
@@ -0,0 +1,42 @@
import 'dart:convert';
import 'dart:io';
/// Where user preferences (theme, key bindings) are kept between runs.
abstract class SettingsStore {
Map<String, dynamic> load();
void save(Map<String, dynamic> data);
}
/// Keeps nothing (tests, previews).
class MemorySettings implements SettingsStore {
Map<String, dynamic> data = {};
@override
Map<String, dynamic> load() => data;
@override
void save(Map<String, dynamic> d) => data = d;
}
/// A small JSON file; unreadable or corrupt files just mean defaults.
class FileSettings implements SettingsStore {
FileSettings(this.path);
final String path;
@override
Map<String, dynamic> load() {
try {
final v = jsonDecode(File(path).readAsStringSync());
return v is Map<String, dynamic> ? v : {};
} catch (_) {
return {};
}
}
@override
void save(Map<String, dynamic> data) {
try {
File(path).writeAsStringSync(jsonEncode(data));
} catch (_) {}
}
}