Skip to content

Commit 165999a

Browse files
authored
[SuperEditor] - Fix editor overlays obscures everything beneath it when Dev Tools paints layout bounds (Resolves #2610) (#2618)
1 parent 01ce693 commit 165999a

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

super_editor/lib/src/default_editor/document_caret_overlay.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter/scheduler.dart';
44
import 'package:super_editor/src/core/document_composer.dart';
55
import 'package:super_editor/src/core/document_layout.dart';
66
import 'package:super_editor/src/infrastructure/documents/document_layers.dart';
7+
import 'package:super_editor/src/infrastructure/flutter/empty_box.dart';
78
import 'package:super_editor/src/infrastructure/platforms/mobile_documents.dart';
89
import 'package:super_text_layout/super_text_layout.dart';
910

@@ -191,11 +192,11 @@ class CaretDocumentOverlayState extends DocumentLayoutLayerState<CaretDocumentOv
191192
// `displayOnAllPlatforms` to true.
192193
final platform = widget.platformOverride ?? defaultTargetPlatform;
193194
if (!widget.displayOnAllPlatforms && (platform == TargetPlatform.android || platform == TargetPlatform.iOS)) {
194-
return const SizedBox();
195+
return const EmptyBox();
195196
}
196197

197198
if (_shouldHideCaretForExpandedSelection) {
198-
return const SizedBox();
199+
return const EmptyBox();
199200
}
200201

201202
// Use a RepaintBoundary so that caret flashing doesn't invalidate our

super_editor/lib/src/default_editor/document_gestures_touch_android.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import 'package:super_editor/src/document_operations/selection_operations.dart';
1919
import 'package:super_editor/src/infrastructure/_logging.dart';
2020
import 'package:super_editor/src/infrastructure/content_layers.dart';
2121
import 'package:super_editor/src/infrastructure/flutter/build_context.dart';
22+
import 'package:super_editor/src/infrastructure/flutter/empty_box.dart';
2223
import 'package:super_editor/src/infrastructure/flutter/eager_pan_gesture_recognizer.dart';
2324
import 'package:super_editor/src/infrastructure/flutter/flutter_scheduler.dart';
2425
import 'package:super_editor/src/infrastructure/multi_tap_gesture.dart';
@@ -366,7 +367,7 @@ class SuperEditorAndroidToolbarFocalPointDocumentLayerBuilder implements SuperEd
366367
SuperEditorAndroidControlsScope.maybeNearestOf(context) == null) {
367368
// There's no controls scope. This probably means SuperEditor is configured with
368369
// a non-Android gesture mode. Build nothing.
369-
return const ContentLayerProxyWidget(child: SizedBox());
370+
return const ContentLayerProxyWidget(child: EmptyBox());
370371
}
371372

372373
return AndroidToolbarFocalPointDocumentLayer(
@@ -399,7 +400,7 @@ class SuperEditorAndroidHandlesDocumentLayerBuilder implements SuperEditorLayerB
399400
SuperEditorAndroidControlsScope.maybeNearestOf(context) == null) {
400401
// There's no controls scope. This probably means SuperEditor is configured with
401402
// a non-Android gesture mode. Build nothing.
402-
return const ContentLayerProxyWidget(child: SizedBox());
403+
return const ContentLayerProxyWidget(child: EmptyBox());
403404
}
404405

405406
return AndroidHandlesDocumentLayer(

super_editor/lib/src/default_editor/document_gestures_touch_ios.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:super_editor/src/default_editor/text_tools.dart';
1717
import 'package:super_editor/src/document_operations/selection_operations.dart';
1818
import 'package:super_editor/src/infrastructure/_logging.dart';
1919
import 'package:super_editor/src/infrastructure/content_layers.dart';
20+
import 'package:super_editor/src/infrastructure/flutter/empty_box.dart';
2021
import 'package:super_editor/src/infrastructure/flutter/eager_pan_gesture_recognizer.dart';
2122
import 'package:super_editor/src/infrastructure/flutter/build_context.dart';
2223
import 'package:super_editor/src/infrastructure/flutter/flutter_scheduler.dart';
@@ -1952,7 +1953,7 @@ class SuperEditorIosToolbarFocalPointDocumentLayerBuilder implements SuperEditor
19521953
if (defaultTargetPlatform != TargetPlatform.iOS || SuperEditorIosControlsScope.maybeNearestOf(context) == null) {
19531954
// There's no controls scope. This probably means SuperEditor is configured with
19541955
// a non-iOS gesture mode. Build nothing.
1955-
return const ContentLayerProxyWidget(child: SizedBox());
1956+
return const ContentLayerProxyWidget(child: EmptyBox());
19561957
}
19571958

19581959
return IosToolbarFocalPointDocumentLayer(
@@ -1985,7 +1986,7 @@ class SuperEditorIosHandlesDocumentLayerBuilder implements SuperEditorLayerBuild
19851986
if (defaultTargetPlatform != TargetPlatform.iOS || SuperEditorIosControlsScope.maybeNearestOf(context) == null) {
19861987
// There's no controls scope. This probably means SuperEditor is configured with
19871988
// a non-iOS gesture mode. Build nothing.
1988-
return const ContentLayerProxyWidget(child: SizedBox());
1989+
return const ContentLayerProxyWidget(child: EmptyBox());
19891990
}
19901991

19911992
final controlsController = SuperEditorIosControlsScope.rootOf(context);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import 'package:flutter/rendering.dart';
2+
import 'package:flutter/widgets.dart';
3+
4+
/// A widget that takes up all available space, but unlike `SizedBox`, this widget
5+
/// doesn't paint anything in debug mode.
6+
///
7+
/// Typically, when a Flutter app wants to take up space with a widget without
8+
/// painting anything, a `SizedBox` used. However, when using Flutter debug
9+
/// tools to see layout boundaries, every `SizedBox` paints itself with a gray
10+
/// color. This is especially a problem when a `SizedBox` is displayed in an
11+
/// overlay. To solve that problem, `EmptyBox` takes up space where a
12+
/// `SizedBox` may have been used, but paints nothing in debug mode, allowing
13+
/// users to see the content beneath the overlay.
14+
class EmptyBox extends LeafRenderObjectWidget {
15+
const EmptyBox();
16+
17+
@override
18+
RenderEmptyBox createRenderObject(BuildContext context) {
19+
return RenderEmptyBox();
20+
}
21+
}
22+
23+
class RenderEmptyBox extends RenderProxyBox {}

0 commit comments

Comments
 (0)