Skip to content

Commit

Permalink
[SuperEditor][SuperReader] - Add indent support to blockquote (Resolves
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-carroll committed Sep 26, 2024
1 parent 4c0859d commit 5998c75
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions super_editor/lib/src/default_editor/blockquote.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:super_editor/src/core/edit_context.dart';
import 'package:super_editor/src/core/editor.dart';
import 'package:super_editor/src/core/styles.dart';
import 'package:super_editor/src/default_editor/attributions.dart';
import 'package:super_editor/src/default_editor/blocks/indentation.dart';
import 'package:super_editor/src/infrastructure/_logging.dart';
import 'package:super_editor/src/infrastructure/attributed_text_styles.dart';
import 'package:super_editor/src/infrastructure/keyboard.dart';
Expand Down Expand Up @@ -55,6 +56,7 @@ class BlockquoteComponentBuilder implements ComponentBuilder {
nodeId: node.id,
text: node.text,
textStyleBuilder: noStyleBuilder,
indent: node.indent,
backgroundColor: const Color(0x00000000),
borderRadius: BorderRadius.zero,
textDirection: textDirection,
Expand All @@ -78,6 +80,8 @@ class BlockquoteComponentBuilder implements ComponentBuilder {
textKey: componentContext.componentKey,
text: componentViewModel.text,
styleBuilder: componentViewModel.textStyleBuilder,
indent: componentViewModel.indent,
indentCalculator: componentViewModel.indentCalculator,
backgroundColor: componentViewModel.backgroundColor,
borderRadius: componentViewModel.borderRadius,
textSelection: componentViewModel.selection,
Expand All @@ -97,6 +101,8 @@ class BlockquoteComponentViewModel extends SingleColumnLayoutComponentViewModel
required this.textStyleBuilder,
this.textDirection = TextDirection.ltr,
this.textAlignment = TextAlign.left,
this.indent = 0,
this.indentCalculator = defaultParagraphIndentCalculator,
required this.backgroundColor,
required this.borderRadius,
this.selection,
Expand All @@ -122,6 +128,10 @@ class BlockquoteComponentViewModel extends SingleColumnLayoutComponentViewModel
TextDirection textDirection;
@override
TextAlign textAlignment;

int indent;
TextBlockIndentCalculator indentCalculator;

@override
TextSelection? selection;
@override
Expand Down Expand Up @@ -149,6 +159,8 @@ class BlockquoteComponentViewModel extends SingleColumnLayoutComponentViewModel
textStyleBuilder: textStyleBuilder,
textDirection: textDirection,
textAlignment: textAlignment,
indent: indent,
indentCalculator: indentCalculator,
backgroundColor: backgroundColor,
borderRadius: borderRadius,
selection: selection,
Expand All @@ -171,6 +183,7 @@ class BlockquoteComponentViewModel extends SingleColumnLayoutComponentViewModel
text == other.text &&
textDirection == other.textDirection &&
textAlignment == other.textAlignment &&
indent == other.indent &&
backgroundColor == other.backgroundColor &&
borderRadius == other.borderRadius &&
selection == other.selection &&
Expand All @@ -188,6 +201,7 @@ class BlockquoteComponentViewModel extends SingleColumnLayoutComponentViewModel
text.hashCode ^
textDirection.hashCode ^
textAlignment.hashCode ^
indent.hashCode ^
backgroundColor.hashCode ^
borderRadius.hashCode ^
selection.hashCode ^
Expand All @@ -207,6 +221,8 @@ class BlockquoteComponent extends StatelessWidget {
required this.text,
required this.styleBuilder,
this.textSelection,
this.indent = 0,
this.indentCalculator = defaultParagraphIndentCalculator,
this.selectionColor = Colors.lightBlueAccent,
required this.backgroundColor,
required this.borderRadius,
Expand All @@ -219,6 +235,8 @@ class BlockquoteComponent extends StatelessWidget {
final AttributedText text;
final AttributionStyleBuilder styleBuilder;
final TextSelection? textSelection;
final int indent;
final TextBlockIndentCalculator indentCalculator;
final Color selectionColor;
final Color backgroundColor;
final BorderRadius borderRadius;
Expand All @@ -235,15 +253,29 @@ class BlockquoteComponent extends StatelessWidget {
borderRadius: borderRadius,
color: backgroundColor,
),
child: TextComponent(
key: textKey,
text: text,
textStyleBuilder: styleBuilder,
textSelection: textSelection,
selectionColor: selectionColor,
highlightWhenEmpty: highlightWhenEmpty,
underlines: underlines,
showDebugPaint: showDebugPaint,
child: Row(
children: [
// Indent spacing on left.
SizedBox(
width: indentCalculator(
styleBuilder({}),
indent,
),
),
// The actual paragraph UI.
Expanded(
child: TextComponent(
key: textKey,
text: text,
textStyleBuilder: styleBuilder,
textSelection: textSelection,
selectionColor: selectionColor,
highlightWhenEmpty: highlightWhenEmpty,
underlines: underlines,
showDebugPaint: showDebugPaint,
),
),
],
),
),
);
Expand Down

0 comments on commit 5998c75

Please sign in to comment.