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

+11 -7
View File
@@ -165,7 +165,9 @@ class _BlockRowState extends State<BlockRow> {
if (p.dy < box.size.height / 2) {
d = _Drop.before;
} else {
d = p.dx > contentX + 28 ? _Drop.child : _Drop.after;
// Below an expanded parent the gap is above its first child: drop there.
final expandedParent = widget.hasChildren && !n.collapsed;
d = expandedParent || p.dx > contentX + 28 ? _Drop.child : _Drop.after;
}
if (d != _drop) setState(() => _drop = d);
}
@@ -561,12 +563,7 @@ class _BlockEditorState extends State<BlockEditor> {
void _accept(int i) {
final q = _query;
if (q == null || i >= _items.length) return;
final v = applyCompletion(
_text.text,
_text.selection.baseOffset,
q,
_items[i],
);
final v = applyCompletion(_text.text, q, _items[i]);
_closeCompletion();
_text.value = v;
_last = v;
@@ -643,6 +640,13 @@ class _BlockEditorState extends State<BlockEditor> {
_closeCompletion();
return KeyEventResult.handled;
}
// Moving the caret elsewhere ends the completion.
if (key == LogicalKeyboardKey.arrowLeft ||
key == LogicalKeyboardKey.arrowRight ||
key == LogicalKeyboardKey.home ||
key == LogicalKeyboardKey.end) {
_closeCompletion();
}
}
if (key == LogicalKeyboardKey.enter ||
+9 -3
View File
@@ -82,15 +82,21 @@ CompletionQuery? detectCompletion(String text, int caret) {
return best;
}
/// Text after accepting `item` for `q` with the caret at `caret`.
/// Text after accepting `item` for `q` (replacing the query text, wherever the caret is).
TextEditingValue applyCompletion(
String text,
int caret,
CompletionQuery q,
CompletionItem item,
) {
final end = q.start + q.query.length;
if (end > text.length || text.substring(q.start, end) != q.query) {
return TextEditingValue(
text: text,
selection: TextSelection.collapsed(offset: text.length),
);
}
final head = text.substring(0, q.start);
var tail = text.substring(caret);
var tail = text.substring(end);
switch (q.kind) {
case CompletionKind.page:
if (tail.startsWith(']]')) tail = tail.substring(2);