Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: add dispose notifier to editor state
  • Loading branch information
LucasXu0 committed Oct 1, 2023
commit 51488dc459ead6bd50ef2a3e8439023305b773d8
8 changes: 8 additions & 0 deletions example/lib/pages/desktop_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class _DesktopEditorState extends State<DesktopEditor> {
commandShortcuts = _buildCommandShortcuts();
}

@override
void dispose() {
editorScrollController.dispose();
editorState.dispose();

super.dispose();
}

@override
void reassemble() {
super.reassemble();
Expand Down
4 changes: 4 additions & 0 deletions lib/src/editor/find_replace_menu/find_menu_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class FindReplaceMenu implements FindReplaceService {
editorState.service.scrollService?.enable();
}

editorState.onDispose.removeListener(dismiss);

_findReplaceMenuEntry?.remove();
_findReplaceMenuEntry = null;

Expand All @@ -59,6 +61,8 @@ class FindReplaceMenu implements FindReplaceService {
return;
}

editorState.onDispose.addListener(dismiss);

_findReplaceMenuEntry = OverlayEntry(
builder: (context) {
return Positioned(
Expand Down
10 changes: 10 additions & 0 deletions lib/src/editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ class EditorState {
Timer? _debouncedSealHistoryItemTimer;
final bool _enableCheckIntegrity = false;

// the value of the notifier is meaningless, just for triggering the callbacks.
final ValueNotifier<int> onDispose = ValueNotifier(0);

void dispose() {
_observer.close();
_debouncedSealHistoryItemTimer?.cancel();
onDispose.value += 1;
onDispose.dispose();
}

/// Apply the transaction to the state.
///
/// The options can be used to determine whether the editor
Expand Down