Skip to content

Commit

Permalink
Fix performance of pen tool
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Oct 12, 2023
1 parent 511ef7c commit 7d6c6e8
Show file tree
Hide file tree
Showing 5 changed files with 416 additions and 404 deletions.
2 changes: 1 addition & 1 deletion FLUTTER_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.16.0-7.0.pre
3.16.0-0.1.pre
10 changes: 8 additions & 2 deletions app/lib/bloc/document_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class DocumentBloc extends ReplayBloc<DocumentEvent, DocumentState> {
);
});
on<ElementsCreated>((event, emit) async {
final current = state;
var current = state;
if (current is! DocumentLoadSuccess) return;
if (!(current.embedding?.editable ?? true)) return;
var data = current.data;
Expand Down Expand Up @@ -168,6 +168,12 @@ class DocumentBloc extends ReplayBloc<DocumentEvent, DocumentState> {
.onRenderersCreated(current.page, renderers)) {
refresh();
}
if (current != state) {
final next = state;
if (next is! DocumentLoadSuccess) return;
data = next.data;
current = next;
}
return _saveState(
emit,
current.copyWith(
Expand All @@ -176,7 +182,7 @@ class DocumentBloc extends ReplayBloc<DocumentEvent, DocumentState> {
content: (List.from(current.page.content)
..addAll(elements)))),
renderers);
}, transformer: sequential());
});
on<ElementsChanged>((event, emit) async {
final current = state;
if (current is! DocumentLoadSuccess) return;
Expand Down
9 changes: 7 additions & 2 deletions app/lib/handlers/pen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ class PenHandler extends Handler<PenTool> {
submitElement(context.viewportSize, context.buildContext, event.pointer);
}

bool _currentlyBaking = false;

Future<void> submitElement(
Size viewportSize, BuildContext context, int index) async {
final bloc = context.read<DocumentBloc>();
var element = elements.remove(index);
final element = elements.remove(index);
if (element == null) return;
lastPosition.remove(index);
bloc.add(ElementsCreated([element]));
bloc.refresh();
if (_currentlyBaking) return;
_currentlyBaking = true;
await bloc.bake();
_currentlyBaking = false;
bloc.refresh();
}

void addPoint(BuildContext context, int pointer, Offset localPosition,
Expand Down
Loading

0 comments on commit 7d6c6e8

Please sign in to comment.