Skip to content

Commit

Permalink
Fix applying edited content immediately after state restore
Browse files Browse the repository at this point in the history
See #126
  • Loading branch information
amake committed Dec 21, 2024
1 parent eb56523 commit b4b5ac2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/src/pages/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:orgro/src/restoration.dart';
import 'package:orgro/src/timestamps.dart';
import 'package:orgro/src/util.dart';

const _kRestoreAfterTextKey = 'restore_after_text';

class EditorPage extends StatefulWidget {
const EditorPage({
required this.text,
Expand Down Expand Up @@ -40,7 +42,10 @@ class _EditorPageState extends State<EditorPage> with RestorationMixin {
_controller = FullyRestorableTextEditingController(text: widget.text)
..addListener(() {
if (_controller.value.text != _after) {
setState(() => _after = _controller.value.text);
setState(() {
_after = _controller.value.text;
bucket?.write(_kRestoreAfterTextKey, _after);
});
}
});
_undoController = UndoHistoryController();
Expand All @@ -52,6 +57,9 @@ class _EditorPageState extends State<EditorPage> with RestorationMixin {
@override
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
registerForRestoration(_controller, 'controller');

if (!initialRestore) return;
_after = bucket?.read<String>(_kRestoreAfterTextKey);
}

@override
Expand Down

0 comments on commit b4b5ac2

Please sign in to comment.