Skip to content

Commit

Permalink
Force CodeMirror refresh once in view port (#2856)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough authored Feb 18, 2024
1 parent 778350e commit 23b85fe
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkgs/sketch_pad/lib/editor/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,21 @@ class _EditorWidgetState extends State<EditorWidget> implements EditorService {
(CodeMirror editor, [HintOptions? options]) {
return options!.results;
}.toJS);

// Listen for document body to be visible, then force a code mirror refresh.
final observer = web.IntersectionObserver(
(JSArray entries, web.IntersectionObserver observer) {
for (final entry in entries.toDart) {
if ((entry as web.IntersectionObserverEntry).isIntersecting) {
observer.unobserve(web.document.body!);
Timer.run(() => codeMirror!.refresh());
return;
}
}
}.toJS,
);

observer.observe(web.document.body!);
}

@override
Expand Down

0 comments on commit 23b85fe

Please sign in to comment.