Skip to content

Commit 2c9bbcf

Browse files
committed
Rename StyleBuilder to CustomStyleBuilder
1 parent bd41d77 commit 2c9bbcf

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

lib/src/widgets/delegate.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
22
import 'package:flutter/gestures.dart';
33
import 'package:flutter/material.dart';
44
import 'package:flutter/rendering.dart';
5+
import '../../flutter_quill.dart';
56

67
import '../models/documents/nodes/leaf.dart';
78
import 'editor.dart';
@@ -10,7 +11,7 @@ import 'text_selection.dart';
1011
typedef EmbedBuilder = Widget Function(
1112
BuildContext context, Embed node, bool readOnly);
1213

13-
typedef StyleBuilder = TextStyle Function(String attributeKey);
14+
typedef CustomStyleBuilder = TextStyle Function(Attribute attribute);
1415

1516
abstract class EditorTextSelectionGestureDetectorBuilderDelegate {
1617
GlobalKey<EditorState> getEditableTextKey();

lib/src/widgets/editor.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class QuillEditor extends StatefulWidget {
252252
this.onSingleLongTapMoveUpdate,
253253
this.onSingleLongTapEnd,
254254
this.embedBuilder = _defaultEmbedBuilder,
255-
this.styleBuilder,
255+
this.customStyleBuilder,
256256
Key? key});
257257

258258
factory QuillEditor.basic({
@@ -312,7 +312,7 @@ class QuillEditor extends StatefulWidget {
312312
onSingleLongTapEnd;
313313

314314
final EmbedBuilder embedBuilder;
315-
final StyleBuilder? styleBuilder;
315+
final CustomStyleBuilder? customStyleBuilder;
316316

317317
@override
318318
_QuillEditorState createState() => _QuillEditorState();
@@ -417,7 +417,7 @@ class _QuillEditorState extends State<QuillEditor>
417417
widget.enableInteractiveSelection,
418418
widget.scrollPhysics,
419419
widget.embedBuilder,
420-
widget.styleBuilder,
420+
widget.customStyleBuilder,
421421
),
422422
);
423423
}

lib/src/widgets/raw_editor.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class RawEditor extends StatefulWidget {
5757
this.enableInteractiveSelection,
5858
this.scrollPhysics,
5959
this.embedBuilder,
60-
this.styleBuilder,
60+
this.customStyleBuilder,
6161
) : assert(maxHeight == null || maxHeight > 0, 'maxHeight cannot be null'),
6262
assert(minHeight == null || minHeight >= 0, 'minHeight cannot be null'),
6363
assert(maxHeight == null || minHeight == null || maxHeight >= minHeight,
@@ -90,7 +90,7 @@ class RawEditor extends StatefulWidget {
9090
final bool enableInteractiveSelection;
9191
final ScrollPhysics? scrollPhysics;
9292
final EmbedBuilder embedBuilder;
93-
final StyleBuilder? styleBuilder;
93+
final CustomStyleBuilder? customStyleBuilder;
9494
@override
9595
State<StatefulWidget> createState() => RawEditorState();
9696
}
@@ -249,7 +249,7 @@ class RawEditorState extends EditorState
249249
indentLevelCounts: indentLevelCounts,
250250
onCheckboxTap: _handleCheckboxTap,
251251
readOnly: widget.readOnly,
252-
styleBuilder: widget.styleBuilder);
252+
customStyleBuilder: widget.customStyleBuilder);
253253
result.add(editableTextBlock);
254254
} else {
255255
throw StateError('Unreachable.');
@@ -264,7 +264,7 @@ class RawEditorState extends EditorState
264264
line: node,
265265
textDirection: _textDirection,
266266
embedBuilder: widget.embedBuilder,
267-
styleBuilder: widget.styleBuilder,
267+
customStyleBuilder: widget.customStyleBuilder,
268268
styles: _styles!,
269269
readOnly: widget.readOnly,
270270
);

lib/src/widgets/text_block.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class EditableTextBlock extends StatelessWidget {
6363
required this.indentLevelCounts,
6464
required this.onCheckboxTap,
6565
required this.readOnly,
66-
this.styleBuilder,
66+
this.customStyleBuilder,
6767
Key? key});
6868

6969
final Block block;
@@ -77,7 +77,7 @@ class EditableTextBlock extends StatelessWidget {
7777
final bool hasFocus;
7878
final EdgeInsets? contentPadding;
7979
final EmbedBuilder embedBuilder;
80-
final StyleBuilder? styleBuilder;
80+
final CustomStyleBuilder? customStyleBuilder;
8181
final CursorCont cursorCont;
8282
final Map<int, int> indentLevelCounts;
8383
final Function(int, bool) onCheckboxTap;
@@ -125,7 +125,7 @@ class EditableTextBlock extends StatelessWidget {
125125
line: line,
126126
textDirection: textDirection,
127127
embedBuilder: embedBuilder,
128-
styleBuilder: styleBuilder,
128+
customStyleBuilder: customStyleBuilder,
129129
styles: styles!,
130130
readOnly: readOnly,
131131
),

lib/src/widgets/text_line.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TextLine extends StatelessWidget {
2727
required this.styles,
2828
required this.readOnly,
2929
this.textDirection,
30-
this.styleBuilder,
30+
this.customStyleBuilder,
3131
Key? key,
3232
}) : super(key: key);
3333

@@ -36,7 +36,7 @@ class TextLine extends StatelessWidget {
3636
final EmbedBuilder embedBuilder;
3737
final DefaultStyles styles;
3838
final bool readOnly;
39-
final StyleBuilder? styleBuilder;
39+
final CustomStyleBuilder? customStyleBuilder;
4040

4141
@override
4242
Widget build(BuildContext context) {
@@ -158,13 +158,16 @@ class TextLine extends StatelessWidget {
158158

159159
TextStyle _applyCustomAttributes(
160160
TextStyle textStyle, Map<String, Attribute> attributes) {
161-
if (styleBuilder == null) {
161+
if (customStyleBuilder == null) {
162162
return textStyle;
163163
}
164-
attributes.keys.where((key) => !attributes.containsKey(key)).forEach((key) {
165-
/// Custom Attribute
166-
final customAttr = styleBuilder!.call(key);
167-
textStyle = textStyle.merge(customAttr);
164+
attributes.keys.forEach((key) {
165+
final attr = attributes[key];
166+
if (attr != null) {
167+
/// Custom Attribute
168+
final customAttr = customStyleBuilder!.call(attr);
169+
textStyle = textStyle.merge(customAttr);
170+
}
168171
});
169172
return textStyle;
170173
}

0 commit comments

Comments
 (0)