Skip to content

Commit

Permalink
Fix reported issues (#1886)
Browse files Browse the repository at this point in the history
* toggle_style_button : calls to options.afterButtonPressed replaced by call to class function afterButtonPressed to allow default call to base button settings
quill_icon_button: L26 build for isSelected updated to call afterButtonPressed = same as if not selected
QuillController _updateSelection removed param=source because not used; added new param insertNewline when true set tog to style of preceding char (last entered); updated replaceText to call _updateSelection for NL
document collectStyle:  Selecting the start of a line, user expects the style to be the visible style of the line including inline styles

* color_button calls afterButtonPressed
insert at start of line uses style for line

* Remove comments

* Fix formatting issue

* Fix FontFamily and Size button actions

* Fix FontFamily and Size button actions

* Value setting Stateful toolbar buttons derive from base class

* Rename base class as QuillToolbarBaseValueButton

* Fixes for before_push script

* Removed deprecated functions

* Move clipboard actions to QuillController

* Fix: collectAllIndividualStylesAndEmbed for result span

* Add: Clipboard toolbar buttons

* export: Clipboard toolbar buttons

* Fix: Dividers not shown in toolbar when multiRowsDisplay.
Fix: Toolbar drop buttons clipped when !multiRowsDisplay

* Add: test for QuillController clipboard
Dart Formatted

* Localizations updated

* QuillControllerConfigurations and clipboard paste

* Fix: CheckList action

* Fix: Multiline selection  and refactor toolbar buttons

* Add tests: Multiline selection

* Fix header toggle button and new block attribute support.

* Fix QuillToolbarColorButtonExtraOptions

---------

Co-authored-by: Douglas Ward <[email protected]>
  • Loading branch information
AtlasAutocode and Douglas Ward committed May 21, 2024
1 parent 0f3f159 commit f7a00e5
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 33 deletions.
1 change: 1 addition & 0 deletions lib/src/models/documents/nodes/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ base class Line extends QuillContainer<Leaf?> {
int _getNodeText(Leaf node, StringBuffer buffer, int offset, int remaining) {
final text = node.toPlainText();
if (text == Embed.kObjectReplacementCharacter) {
buffer.write(Embed.kObjectReplacementCharacter);
return remaining - node.length;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/models/rules/insert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ class PreserveInlineStylesRule extends InsertRule {

if ((prev.data as String).endsWith('\n')) {
if (prev.attributes != null) {
for (final key in prev.attributes!.keys) {
if (Attribute.blockKeys.contains(key)) {
for (final value in prev.attributes!.values) {
if (!(value as Attribute).isInline) {
return null;
}
}
Expand Down
7 changes: 7 additions & 0 deletions lib/src/widgets/toolbar/base_button/base_value_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ abstract class QuillToolbarCommonButtonState<
String get tooltip =>
options.tooltip ?? baseButtonExtraOptions?.tooltip ?? defaultTooltip;

IconData get defaultIconData;

IconData get iconData =>
options.iconData ??
context.quillToolbarBaseButtonOptions?.iconData ??
defaultIconData;

double get iconSize =>
options.iconSize ?? baseButtonExtraOptions?.iconSize ?? kDefaultIconSize;

Expand Down
5 changes: 3 additions & 2 deletions lib/src/widgets/toolbar/buttons/clipboard_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class QuillToolbarClipboardButtonState
ClipboardAction.paste => context.loc.paste,
};

IconData get _icon => switch (widget.clipboardAction) {
@override
IconData get defaultIconData => switch (widget.clipboardAction) {
ClipboardAction.cut => Icons.cut_outlined,
ClipboardAction.copy => Icons.copy_outlined,
ClipboardAction.paste => Icons.paste_outlined,
Expand Down Expand Up @@ -132,7 +133,7 @@ class QuillToolbarClipboardButtonState
message: tooltip,
child: QuillToolbarIconButton(
icon: Icon(
_icon,
iconData,
size: iconSize * iconButtonFactor,
),
isSelected: false,
Expand Down
10 changes: 4 additions & 6 deletions lib/src/widgets/toolbar/buttons/color/color_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@ class QuillToolbarColorButtonState extends QuillToolbarColorBaseButtonState {
super.dispose();
}

IconData get iconData {
return options.iconData ??
baseButtonExtraOptions?.iconData ??
(widget.isBackground ? Icons.format_color_fill : Icons.color_lens);
}
@override
IconData get defaultIconData =>
widget.isBackground ? Icons.format_color_fill : Icons.color_lens;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -140,7 +138,7 @@ class QuillToolbarColorButtonState extends QuillToolbarColorBaseButtonState {
_showColorPicker();
afterButtonPressed?.call();
},
iconColor: null,
iconColor: iconColor,
iconColorBackground: iconColorBackground,
fillColor: fillColor,
fillColorBackground: fillColorBackground,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/widgets/toolbar/buttons/font_family_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class QuillToolbarFontFamilyButtonState extends QuillToolbarBaseButtonState<
@override
String get defaultTooltip => context.loc.fontFamily;

@override
IconData get defaultIconData => Icons.font_download_outlined;

void _onPressed() {
if (_menuController.isOpen) {
_menuController.close();
Expand Down
3 changes: 3 additions & 0 deletions lib/src/widgets/toolbar/buttons/font_size_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class QuillToolbarFontSizeButtonState extends QuillToolbarBaseButtonState<
@override
String get defaultTooltip => context.loc.fontSize;

@override
IconData get defaultIconData => Icons.format_size_outlined;

void _onDropdownButtonPressed() {
if (_menuController.isOpen) {
_menuController.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class QuillToolbarSelectHeaderStyleButtonsState
@override
String get defaultTooltip => context.loc.headerStyle;

@override
IconData get defaultIconData => Icons.question_mark_outlined;

Style get _selectionStyle => controller.getSelectionStyle();

final _valueToText = <Attribute, String>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
@override
String get defaultTooltip => context.loc.headerStyle;

@override
IconData get defaultIconData => Icons.question_mark_outlined;

Attribute<dynamic> _selectedItem = Attribute.header;

final _menuController = MenuController();
Expand Down
7 changes: 4 additions & 3 deletions lib/src/widgets/toolbar/buttons/history_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class QuillToolbarHistoryButtonState
String get defaultTooltip =>
widget.isUndo ? context.loc.undo : context.loc.redo;

@override
IconData get defaultIconData =>
(widget.isUndo ? Icons.undo_outlined : Icons.redo_outlined);

@override
void initState() {
super.initState();
Expand All @@ -53,9 +57,6 @@ class QuillToolbarHistoryButtonState

@override
Widget build(BuildContext context) {
final iconData = options.iconData ??
baseButtonExtraOptions?.iconData ??
(widget.isUndo ? Icons.undo_outlined : Icons.redo_outlined);
final childBuilder =
options.childBuilder ?? baseButtonExtraOptions?.childBuilder;

Expand Down
11 changes: 4 additions & 7 deletions lib/src/widgets/toolbar/buttons/indent_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ class QuillToolbarIndentButtonState extends QuillToolbarIndentBaseButtonState {
? context.loc.increaseIndent
: context.loc.decreaseIndent;

IconData get iconData {
return options.iconData ??
baseButtonExtraOptions?.iconData ??
(widget.isIncrease
? Icons.format_indent_increase
: Icons.format_indent_decrease);
}
@override
IconData get defaultIconData => widget.isIncrease
? Icons.format_indent_increase
: Icons.format_indent_decrease;

void _sharedOnPressed() {
widget.controller.indentSelection(widget.isIncrease);
Expand Down
5 changes: 2 additions & 3 deletions lib/src/widgets/toolbar/buttons/link_style_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ class QuillToolbarLinkStyleButtonState
controller.removeListener(_didChangeSelection);
}

IconData get iconData {
return options.iconData ?? baseButtonExtraOptions?.iconData ?? Icons.link;
}
@override
IconData get defaultIconData => Icons.link;

Color get dialogBarrierColor {
return options.dialogBarrierColor ??
Expand Down
7 changes: 2 additions & 5 deletions lib/src/widgets/toolbar/buttons/toggle_check_list_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ class QuillToolbarToggleCheckListButtonState
@override
String get defaultTooltip => context.loc.checkedList;

IconData get iconData {
return options.iconData ??
baseButtonExtraOptions?.iconData ??
Icons.check_box;
}
@override
IconData get defaultIconData => Icons.check_box;

@override
Widget build(BuildContext context) {
Expand Down
8 changes: 3 additions & 5 deletions lib/src/widgets/toolbar/buttons/toggle_style_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,8 @@ class QuillToolbarToggleStyleButtonState
@override
String get defaultTooltip => _defaultTooltipAndIconData.$1;

IconData get iconData {
return options.iconData ??
context.quillToolbarBaseButtonOptions?.iconData ??
_defaultTooltipAndIconData.$2;
}
@override
IconData get defaultIconData => _defaultTooltipAndIconData.$2;

void _onPressed() {
_toggleAttribute();
Expand Down Expand Up @@ -140,6 +137,7 @@ class QuillToolbarToggleStyleButtonState

bool _getIsToggled(Map<String, Attribute> attrs) {
if (widget.attribute.key == Attribute.list.key ||
widget.attribute.key == Attribute.header.key ||
widget.attribute.key == Attribute.script.key ||
widget.attribute.key == Attribute.align.key) {
final attribute = attrs[widget.attribute.key];
Expand Down

0 comments on commit f7a00e5

Please sign in to comment.