Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: move editor text elements into separate files when possible #2274

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 1 addition & 1 deletion lib/flutter_quill.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export 'src/editor/style_widgets/style_widgets.dart';
export 'src/editor/widgets/cursor.dart';
export 'src/editor/widgets/default_styles.dart';
export 'src/editor/widgets/link.dart';
export 'src/editor/widgets/text/utils/text_block_utils.dart';
export 'src/editor/widgets/text/block_line/utils/text_block_utils.dart';
export 'src/editor_toolbar_controller_shared/copy_cut_service/copy_cut_service.dart';
export 'src/editor_toolbar_controller_shared/copy_cut_service/copy_cut_service_provider.dart';
export 'src/editor_toolbar_controller_shared/copy_cut_service/default_copy_cut_service.dart';
Expand Down
3 changes: 2 additions & 1 deletion lib/src/editor/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import 'widgets/box.dart';
import 'widgets/cursor.dart';
import 'widgets/delegate.dart';
import 'widgets/float_cursor.dart';
import 'widgets/text/text_selection.dart';
import 'widgets/text/selection/drag_text_selection.dart';
import 'widgets/text/selection/text_selection.dart';

/// Base interface for editable render objects.
abstract class RenderAbstractEditor implements TextLayoutMetrics {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/editor/raw_editor/raw_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:flutter/widgets.dart'
import '../../common/structs/offset_value.dart';
import '../../controller/quill_controller.dart';
import '../editor.dart';
import '../widgets/text/text_selection.dart';
import '../widgets/text/selection/text_selection.dart';
import 'config/raw_editor_configurations.dart';
import 'raw_editor_state.dart';

Expand Down
7 changes: 4 additions & 3 deletions lib/src/editor/raw_editor/raw_editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ import '../widgets/default_styles.dart';
import '../widgets/keyboard_service_widget.dart';
import '../widgets/link.dart';
import '../widgets/proxy.dart';
import '../widgets/text/text_block.dart';
import '../widgets/text/text_line.dart';
import '../widgets/text/text_selection.dart';
import '../widgets/text/block_line/text_block.dart';
import '../widgets/text/line/editable_text_line.dart';
import '../widgets/text/line/text_line.dart';
import '../widgets/text/selection/text_selection.dart';
import 'raw_editor.dart';
import 'raw_editor_actions.dart';
import 'raw_editor_render_object.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/editor/widgets/default_styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import '../../common/utils/platform.dart';
import '../../document/attribute.dart';
import '../../document/style.dart';
import '../style_widgets/checkbox_point.dart';
import 'text/utils/text_block_utils.dart';
import 'text/block_line/utils/text_block_utils.dart';

class QuillStyles extends InheritedWidget {
const QuillStyles({
Expand Down
2 changes: 1 addition & 1 deletion lib/src/editor/widgets/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '../../document/attribute.dart';
import '../../document/nodes/leaf.dart';
import '../editor.dart';
import '../raw_editor/raw_editor.dart';
import 'text/text_selection.dart';
import 'text/selection/text_selection.dart';

typedef CustomStyleBuilder = TextStyle Function(Attribute attribute);

Expand Down
63 changes: 63 additions & 0 deletions lib/src/editor/widgets/text/block_line/editable_text_block.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';

import '../../../../common/structs/horizontal_spacing.dart';
import '../../../../common/structs/vertical_spacing.dart';
import '../../../../document/nodes/block.dart';
import 'render_editable_text_block.dart';

//TODO: we need to document what does this and why we use it
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this was being used to separate the widget logic from the build and rendering logic.
For a StatefulWidget, we would use WidgetState to achieve the same purpose.
I guess I would leave it as a private class only callable from its parent EditableTextBlock. If we extract it as a separate public class, it could be mis-called from who knows where. (And people will ask 'why do we use this')

Copy link
Collaborator Author

@CatHood0 CatHood0 Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add some documentation about what makes this class. We have some docs about this, but i have no much time. I will search and add it correctly as soon as possible.

I wrote that TODO to remember that i need to add it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take as much time as you need.

@internal
@immutable
class EditableBlock extends MultiChildRenderObjectWidget {
const EditableBlock(
{required this.block,
required this.textDirection,
required this.horizontalSpacing,
required this.verticalSpacing,
required this.scrollBottomInset,
required this.decoration,
required this.contentPadding,
required super.children,
super.key});

final Block block;
final TextDirection textDirection;
final HorizontalSpacing horizontalSpacing;
final VerticalSpacing verticalSpacing;
final double scrollBottomInset;
final Decoration decoration;
final EdgeInsets? contentPadding;

EdgeInsets get _padding => EdgeInsets.only(
left: horizontalSpacing.left,
right: horizontalSpacing.right,
top: verticalSpacing.top,
bottom: verticalSpacing.bottom);

EdgeInsets get _contentPadding => contentPadding ?? EdgeInsets.zero;

@override
RenderEditableTextBlock createRenderObject(BuildContext context) {
return RenderEditableTextBlock(
block: block,
textDirection: textDirection,
padding: _padding,
scrollBottomInset: scrollBottomInset,
decoration: decoration,
contentPadding: _contentPadding,
);
}

@override
void updateRenderObject(
BuildContext context, covariant RenderEditableTextBlock renderObject) {
renderObject
..setContainer(block)
..textDirection = textDirection
..scrollBottomInset = scrollBottomInset
..setPadding(_padding)
..decoration = decoration
..contentPadding = _contentPadding;
}
}
Loading