Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* Remove unicode from `QuillText` element that causes weird caret behavior on empty lines [#2453](https://github.com/singerdmx/flutter-quill/pull/2453).
* Focus and open context menu on right click if unfocused [#2477](https://github.com/singerdmx/flutter-quill/pull/2477).
* Update QuillController `length` extension method deprecation message [#2483](https://github.com/singerdmx/flutter-quill/pull/2483).
- Remove unicode from `QuillText` element that causes weird caret behavior on empty lines [#2453](https://github.com/singerdmx/flutter-quill/pull/2453).
- Focus and open context menu on right click if unfocused [#2477](https://github.com/singerdmx/flutter-quill/pull/2477).
- Update QuillController `length` extension method deprecation message [#2483](https://github.com/singerdmx/flutter-quill/pull/2483).

### Added

* `Rule` is now part of the public API, so that `Document.setCustomRules` can be used.
- `Rule` is now part of the public API, so that `Document.setCustomRules` can be used.
- `decoration` property in `DefaultTextBlockStyle` for the `header` attribute to customize headers with borders, background colors, and other styles using `BoxDecoration` [#2429](https://github.com/singerdmx/flutter-quill/pull/2429).

## [11.0.0] - 2025-02-16

Expand Down
32 changes: 29 additions & 3 deletions lib/src/editor/raw_editor/raw_editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,8 @@ class QuillRawEditorState extends EditorState
prevNodeOl = attrs[Attribute.list.key] == Attribute.ol;
final nodeTextDirection = getDirectionOfNode(node, _textDirection);
if (node is Line) {
final editableTextLine = _getEditableTextLineFromNode(node, context);
final editableTextLine =
_getEditableTextLineFromNode(node, context, attrs);
result.add(Directionality(
textDirection: nodeTextDirection, child: editableTextLine));
} else if (node is Block) {
Expand Down Expand Up @@ -639,7 +640,7 @@ class QuillRawEditorState extends EditorState
}

EditableTextLine _getEditableTextLineFromNode(
Line node, BuildContext context) {
Line node, BuildContext context, Map<String, Attribute<dynamic>> attrs) {
final textLine = TextLine(
line: node,
textDirection: _textDirection,
Expand Down Expand Up @@ -668,7 +669,8 @@ class QuillRawEditorState extends EditorState
_hasFocus,
MediaQuery.devicePixelRatioOf(context),
_cursorCont,
_styles!.inlineCode!);
_styles!.inlineCode!,
_getDecoration(node, _styles, attrs));
return editableTextLine;
}

Expand Down Expand Up @@ -772,6 +774,30 @@ class QuillRawEditorState extends EditorState
return VerticalSpacing.zero;
}

BoxDecoration? _getDecoration(Node node, DefaultStyles? defaultStyles,
Map<String, Attribute<dynamic>> attrs) {
if (attrs.containsKey(Attribute.header.key)) {
final level = attrs[Attribute.header.key]!.value;
switch (level) {
case 1:
return defaultStyles!.h1!.decoration;
case 2:
return defaultStyles!.h2!.decoration;
case 3:
return defaultStyles!.h3!.decoration;
case 4:
return defaultStyles!.h4!.decoration;
case 5:
return defaultStyles!.h5!.decoration;
case 6:
return defaultStyles!.h6!.decoration;
default:
throw ArgumentError('Invalid level $level');
}
}
return null;
}

void _didChangeTextEditingValueListener() {
_didChangeTextEditingValue(controller.ignoreFocusOnTextChange);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/editor/widgets/text/text_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class EditableTextBlock extends StatelessWidget {
MediaQuery.devicePixelRatioOf(context),
cursorCont,
styles!.inlineCode!,
);
null);
final nodeTextDirection = getDirectionOfNode(line, textDirection);
children.add(
Directionality(
Expand Down
25 changes: 23 additions & 2 deletions lib/src/editor/widgets/text/text_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ class EditableTextLine extends RenderObjectWidget {
this.devicePixelRatio,
this.cursorCont,
this.inlineCodeStyle,
this.decoration,
{super.key});

final Line line;
Expand All @@ -751,6 +752,7 @@ class EditableTextLine extends RenderObjectWidget {
final double devicePixelRatio;
final CursorCont cursorCont;
final InlineCodeStyle inlineCodeStyle;
final BoxDecoration? decoration;

@override
RenderObjectElement createElement() {
Expand All @@ -769,7 +771,8 @@ class EditableTextLine extends RenderObjectWidget {
_getPadding(),
color,
cursorCont,
inlineCodeStyle);
inlineCodeStyle,
decoration);
}

@override
Expand All @@ -785,7 +788,8 @@ class EditableTextLine extends RenderObjectWidget {
..hasFocus = hasFocus
..setDevicePixelRatio(devicePixelRatio)
..setCursorCont(cursorCont)
..setInlineCodeStyle(inlineCodeStyle);
..setInlineCodeStyle(inlineCodeStyle)
..setDecoration(decoration);
}

EdgeInsetsGeometry _getPadding() {
Expand All @@ -812,6 +816,7 @@ class RenderEditableTextLine extends RenderEditableBox {
this.color,
this.cursorCont,
this.inlineCodeStyle,
this.decoration,
);

RenderBox? _leading;
Expand All @@ -830,6 +835,7 @@ class RenderEditableTextLine extends RenderEditableBox {
List<TextBox>? _selectedRects;
late Rect _caretPrototype;
InlineCodeStyle inlineCodeStyle;
BoxDecoration? decoration;
final Map<TextLineSlot, RenderBox> children = <TextLineSlot, RenderBox>{};

Iterable<RenderBox> get _children sync* {
Expand Down Expand Up @@ -945,6 +951,12 @@ class RenderEditableTextLine extends RenderEditableBox {
markNeedsLayout();
}

void setDecoration(BoxDecoration? newDecoration) {
if (decoration == newDecoration) return;
decoration = newDecoration;
markNeedsPaint();
}

// Start selection implementation

bool containsTextSelection() {
Expand Down Expand Up @@ -1334,6 +1346,15 @@ class RenderEditableTextLine extends RenderEditableBox {
);
}
}
final boxDecoration = decoration;
if (boxDecoration != null) {
final paintRect = offset & size;
boxDecoration.createBoxPainter().paint(
context.canvas,
paintRect.topLeft,
ImageConfiguration(size: paintRect.size),
);
}

if (_body != null) {
final parentData = _body!.parentData as BoxParentData;
Expand Down