fix(app): read views after queued writes, reload on write failure

- Page and journal views read through the write queue after the previous
  view's pending saves, so they never load stale text.
- A failed write reloads the current view and shows a message instead of
  leaving blocks on temporary ids; inserts also trigger reconciliation.
- Completion replaces the query range, not up to the caret, and closes
  when the caret moves away.
- Renaming a page reloads it so rewritten links are not overwritten.
- Dropping below an expanded parent lands as its first child, where the
  indicator is drawn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Opus 5.5 committed 2026-10-21 04:08:36 +02:00
1 parent fce7526fcf
commit 5e25db3e24
9 files changed
+102 -29

No files matched your search

+5 -1
View File
@@ -49,7 +49,11 @@ class _JournalsViewState extends State<JournalsView> {
final app = AppScope.read(context);
try {
final before = _days.isEmpty ? null : _days.last.view.page.journalDate;
final views = await app.backend.journals(before: before, limit: _batch);
if (_days.isEmpty) await WidgetsBinding.instance.endOfFrame;
final views = await app.queue.run(
() => app.backend.journals(before: before, limit: _batch),
report: false,
);
if (!mounted) return;
setState(() {
for (final v in views) {
+11 -6
View File
@@ -41,12 +41,15 @@ class _PageScreenState extends State<PageScreen> {
final app = AppScope.read(context);
try {
final t = widget.target;
PageData? v;
if (t.id != null) {
v = await app.backend.page(t.id!);
} else {
v = await app.backend.openPage(t.title!);
}
// Read after the previous view's pending saves (flushed when it is disposed at the
// end of this frame) have reached the core.
await WidgetsBinding.instance.endOfFrame;
final v = await app.queue.run(
() => t.id != null
? app.backend.page(t.id!)
: app.backend.openPage(t.title!).then<PageData?>((p) => p),
report: false,
);
if (!mounted) return;
if (v == null) {
setState(() => _error = 'This page no longer exists.');
@@ -228,6 +231,8 @@ class _TitleFieldState extends State<_TitleField> {
await app.queue.run(() => app.backend.renamePage(widget.page.id, title));
_committed = title;
app.renamed(widget.page.id, title);
// The core rewrote links in other blocks, possibly on this page: reload them.
app.reload();
} catch (e) {
_text.text = _committed;
messenger.showSnackBar(SnackBar(content: Text('Rename failed: $e')));
+13 -1
View File
@@ -27,6 +27,18 @@ class _ShellState extends State<Shell> {
final app = AppScope.of(context);
final colors = context.colors;
final route = app.route;
final error = app.writeError;
if (error != null) {
app.writeError = null;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Could not save a change; reloaded. ($error)'),
),
);
});
}
return CallbackShortcuts(
bindings: {
const SingleActivator(LogicalKeyboardKey.keyK, control: true): () =>
@@ -96,7 +108,7 @@ class _ShellState extends State<Shell> {
),
Expanded(
child: KeyedSubtree(
key: ValueKey(route),
key: ValueKey((route, app.generation)),
child: switch (route) {
JournalsRoute() => const JournalsView(),
TimelineRoute() => const TimelineView(),