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
pull/1801/head
Douglas Ward 1 year ago
parent 05c17e1ebc
commit 3217059ac6
  1. 36
      example/lib/screens/quill/my_quill_toolbar.dart
  2. 11
      lib/src/models/documents/document.dart
  3. 47
      lib/src/widgets/quill/quill_controller.dart
  4. 7
      lib/src/widgets/toolbar/buttons/quill_icon_button.dart
  5. 4
      lib/src/widgets/toolbar/buttons/toggle_style_button.dart

@ -223,24 +223,24 @@ class MyQuillToolbar extends StatelessWidget {
'40': '40.0'
},
// headerStyleType: HeaderStyleType.buttons,
// buttonOptions: QuillSimpleToolbarButtonOptions(
// base: QuillToolbarBaseButtonOptions(
// afterButtonPressed: focusNode.requestFocus,
// // iconSize: 20,
// iconTheme: QuillIconTheme(
// iconButtonSelectedData: IconButtonData(
// style: IconButton.styleFrom(
// foregroundColor: Colors.blue,
// ),
// ),
// iconButtonUnselectedData: IconButtonData(
// style: IconButton.styleFrom(
// foregroundColor: Colors.red,
// ),
// ),
// ),
// ),
// ),
buttonOptions: QuillSimpleToolbarButtonOptions(
base: QuillToolbarBaseButtonOptions(
afterButtonPressed: focusNode.requestFocus,
// iconSize: 20,
// iconTheme: QuillIconTheme(
// iconButtonSelectedData: IconButtonData(
// style: IconButton.styleFrom(
// foregroundColor: Colors.blue,
// ),
// ),
// iconButtonUnselectedData: IconButtonData(
// style: IconButton.styleFrom(
// foregroundColor: Colors.red,
// ),
// ),
// ),
),
),
customButtons: [
QuillToolbarCustomButtonOptions(
icon: const Icon(Icons.add_alarm_rounded),

@ -184,11 +184,12 @@ class Document {
return (res.node as Line).collectStyle(res.offset, len);
}
if (res.offset == 0) {
rangeStyle = (res.node as Line).collectStyle(res.offset, len);
return rangeStyle.removeAll({
for (final attr in rangeStyle.values)
if (attr.isInline) attr
});
return rangeStyle = (res.node as Line).collectStyle(res.offset, len);
//COMMENT: Selecting the start of a line, user expects the style to be the visible style of the line including inline styles
// return rangeStyle.removeAll({
// for (final attr in rangeStyle.values)
// if (attr.isInline) attr
// });
}
rangeStyle = (res.node as Line).collectStyle(res.offset - 1, len);
final linkAttribute = rangeStyle.attributes[Attribute.link.key];

@ -327,7 +327,7 @@ class QuillController extends ChangeNotifier {
if (textSelection != null) {
if (delta == null || delta.isEmpty) {
_updateSelection(textSelection, ChangeSource.local);
_updateSelection(textSelection);
} else {
final user = Delta()
..retain(index)
@ -335,12 +335,11 @@ class QuillController extends ChangeNotifier {
..delete(len);
final positionDelta = getPositionDelta(user, delta);
_updateSelection(
textSelection.copyWith(
baseOffset: textSelection.baseOffset + positionDelta,
extentOffset: textSelection.extentOffset + positionDelta,
),
ChangeSource.local,
);
textSelection.copyWith(
baseOffset: textSelection.baseOffset + positionDelta,
extentOffset: textSelection.extentOffset + positionDelta,
),
insertNewline: data == '\n');
}
}
@ -389,7 +388,7 @@ class QuillController extends ChangeNotifier {
baseOffset: change.transformPosition(selection.baseOffset),
extentOffset: change.transformPosition(selection.extentOffset));
if (selection != adjustedSelection) {
_updateSelection(adjustedSelection, ChangeSource.local);
_updateSelection(adjustedSelection);
}
if (shouldNotifyListeners) {
notifyListeners();
@ -428,7 +427,7 @@ class QuillController extends ChangeNotifier {
}
void updateSelection(TextSelection textSelection, ChangeSource source) {
_updateSelection(textSelection, source);
_updateSelection(textSelection);
notifyListeners();
}
@ -445,7 +444,7 @@ class QuillController extends ChangeNotifier {
),
);
if (selection != textSelection) {
_updateSelection(textSelection, source);
_updateSelection(textSelection);
}
notifyListeners();
@ -479,21 +478,37 @@ class QuillController extends ChangeNotifier {
super.dispose();
}
void _updateSelection(TextSelection textSelection, ChangeSource source) {
/// Comments:
/// Removed param:
/// 'ChangeSource source' as not used within this function!
/// Added param:
/// insertNewline is non-null when user makes an editing change, true when newline is inserted to allow style to be maintained
void _updateSelection(TextSelection textSelection, {bool insertNewline = false}) {
_selection = textSelection;
final end = document.length - 1;
_selection = selection.copyWith(
baseOffset: math.min(selection.baseOffset, end),
extentOffset: math.min(selection.extentOffset, end));
//
if (keepStyleOnNewLine) {
final style = getSelectionStyle();
final ignoredStyles = style.attributes.values.where(
(s) => !s.isInline || s.key == Attribute.link.key,
);
toggledStyle = style.removeAll(ignoredStyles.toSet());
//
// Update toggledStyle:
// if insertNewline: gets style from preceding/last character entered (if any)
// else clears so style will be style of selection
//
if (insertNewline && selection.start > 0) {
final style = document.collectStyle(selection.start - 1, 0);
final ignoredStyles = style.attributes.values.where(
(s) => !s.isInline || s.key == Attribute.link.key,
);
toggledStyle = style.removeAll(ignoredStyles.toSet());
} else {
toggledStyle = const Style();
}
} else {
toggledStyle = const Style();
}
//
onSelectionChanged?.call(textSelection);
}

@ -26,7 +26,12 @@ class QuillToolbarIconButton extends StatelessWidget {
if (isSelected) {
return IconButton.filled(
tooltip: tooltip,
onPressed: onPressed,
onPressed: onPressed != null
? () {
onPressed?.call();
afterPressed?.call();
}
: null,
icon: icon,
style: iconTheme?.iconButtonSelectedData?.style,
visualDensity: iconTheme?.iconButtonSelectedData?.visualDensity,

@ -148,7 +148,7 @@ class QuillToolbarToggleStyleButtonState
void _onPressed() {
_toggleAttribute();
options.afterButtonPressed?.call();
afterButtonPressed?.call();
}
@override
@ -175,7 +175,7 @@ class QuillToolbarToggleStyleButtonState
options.fillColor,
_isToggled,
_toggleAttribute,
options.afterButtonPressed,
afterButtonPressed,
iconSize,
iconButtonFactor,
iconTheme,

Loading…
Cancel
Save