|
@@ -32,11 +32,14 @@ class RichTextNodeWidgetBuilder extends NodeWidgetBuilder {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+typedef FlowyTextSpanDecorator = TextSpan Function(TextSpan textSpan);
|
|
|
|
+
|
|
class FlowyRichText extends StatefulWidget {
|
|
class FlowyRichText extends StatefulWidget {
|
|
const FlowyRichText({
|
|
const FlowyRichText({
|
|
Key? key,
|
|
Key? key,
|
|
this.cursorHeight,
|
|
this.cursorHeight,
|
|
this.cursorWidth = 2.0,
|
|
this.cursorWidth = 2.0,
|
|
|
|
+ this.textSpanDecorator,
|
|
required this.textNode,
|
|
required this.textNode,
|
|
required this.editorState,
|
|
required this.editorState,
|
|
}) : super(key: key);
|
|
}) : super(key: key);
|
|
@@ -45,6 +48,7 @@ class FlowyRichText extends StatefulWidget {
|
|
final double cursorWidth;
|
|
final double cursorWidth;
|
|
final TextNode textNode;
|
|
final TextNode textNode;
|
|
final EditorState editorState;
|
|
final EditorState editorState;
|
|
|
|
+ final FlowyTextSpanDecorator? textSpanDecorator;
|
|
|
|
|
|
@override
|
|
@override
|
|
State<FlowyRichText> createState() => _FlowyRichTextState();
|
|
State<FlowyRichText> createState() => _FlowyRichTextState();
|
|
@@ -70,7 +74,7 @@ class _FlowyRichTextState extends State<FlowyRichText> with Selectable {
|
|
} else if (attributes.quote == true) {
|
|
} else if (attributes.quote == true) {
|
|
return _buildQuotedRichText(context);
|
|
return _buildQuotedRichText(context);
|
|
} else if (attributes.heading != null) {
|
|
} else if (attributes.heading != null) {
|
|
- return _buildHeadingRichText(context);
|
|
|
|
|
|
+ // return _buildHeadingRichText(context);
|
|
} else if (attributes.number != null) {
|
|
} else if (attributes.number != null) {
|
|
return _buildNumberListRichText(context);
|
|
return _buildNumberListRichText(context);
|
|
}
|
|
}
|
|
@@ -87,14 +91,13 @@ class _FlowyRichTextState extends State<FlowyRichText> with Selectable {
|
|
@override
|
|
@override
|
|
Rect getCursorRectInPosition(Position position) {
|
|
Rect getCursorRectInPosition(Position position) {
|
|
final textPosition = TextPosition(offset: position.offset);
|
|
final textPosition = TextPosition(offset: position.offset);
|
|
- final baseRect = frontWidgetRect();
|
|
|
|
final cursorOffset =
|
|
final cursorOffset =
|
|
_renderParagraph.getOffsetForCaret(textPosition, Rect.zero);
|
|
_renderParagraph.getOffsetForCaret(textPosition, Rect.zero);
|
|
final cursorHeight = widget.cursorHeight ??
|
|
final cursorHeight = widget.cursorHeight ??
|
|
_renderParagraph.getFullHeightForCaret(textPosition) ??
|
|
_renderParagraph.getFullHeightForCaret(textPosition) ??
|
|
5.0; // default height
|
|
5.0; // default height
|
|
return Rect.fromLTWH(
|
|
return Rect.fromLTWH(
|
|
- baseRect.centerRight.dx + cursorOffset.dx - (widget.cursorWidth / 2),
|
|
|
|
|
|
+ cursorOffset.dx - (widget.cursorWidth / 2),
|
|
cursorOffset.dy,
|
|
cursorOffset.dy,
|
|
widget.cursorWidth,
|
|
widget.cursorWidth,
|
|
cursorHeight,
|
|
cursorHeight,
|
|
@@ -138,11 +141,7 @@ class _FlowyRichTextState extends State<FlowyRichText> with Selectable {
|
|
}
|
|
}
|
|
|
|
|
|
Widget _buildRichText(BuildContext context) {
|
|
Widget _buildRichText(BuildContext context) {
|
|
- if (_textNode.children.isEmpty) {
|
|
|
|
- return _buildSingleRichText(context);
|
|
|
|
- } else {
|
|
|
|
- return _buildRichTextWithChildren(context);
|
|
|
|
- }
|
|
|
|
|
|
+ return _buildSingleRichText(context);
|
|
}
|
|
}
|
|
|
|
|
|
Widget _buildRichTextWithChildren(BuildContext context) {
|
|
Widget _buildRichTextWithChildren(BuildContext context) {
|
|
@@ -166,10 +165,11 @@ class _FlowyRichTextState extends State<FlowyRichText> with Selectable {
|
|
}
|
|
}
|
|
|
|
|
|
Widget _buildSingleRichText(BuildContext context) {
|
|
Widget _buildSingleRichText(BuildContext context) {
|
|
- return SizedBox(
|
|
|
|
- width:
|
|
|
|
- MediaQuery.of(context).size.width - 20, // FIXME: use the const value
|
|
|
|
- child: RichText(key: _textKey, text: _decorateTextSpanWithGlobalStyle),
|
|
|
|
|
|
+ return RichText(
|
|
|
|
+ key: _textKey,
|
|
|
|
+ text: widget.textSpanDecorator != null
|
|
|
|
+ ? widget.textSpanDecorator!(_decorateTextSpanWithGlobalStyle)
|
|
|
|
+ : _decorateTextSpanWithGlobalStyle,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|