Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

! Support clipboard actions from the toolbar. #1843

Merged
merged 23 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3217059
toggle_style_button : calls to options.afterButtonPressed replaced by…
Mar 31, 2024
ea7ba7e
color_button calls afterButtonPressed
Apr 1, 2024
0593877
Remove comments
Apr 3, 2024
ae4c828
Fix formatting issue
AtlasAutocode Apr 7, 2024
b0d92d1
Fix FontFamily and Size button actions
AtlasAutocode Apr 8, 2024
66f0aa1
Merge branch 'singerdmx:master' into master
AtlasAutocode Apr 18, 2024
472b89c
Merge branch 'master' into selection_problems
AtlasAutocode Apr 18, 2024
dd03bff
Fix FontFamily and Size button actions
AtlasAutocode Apr 18, 2024
04f086c
Value setting Stateful toolbar buttons derive from base class
AtlasAutocode Apr 20, 2024
7419af6
Rename base class as QuillToolbarBaseValueButton
AtlasAutocode Apr 21, 2024
b793796
Fixes for before_push script
Apr 21, 2024
5249ad3
Removed deprecated functions
Apr 22, 2024
2334d79
Move clipboard actions to QuillController
Apr 24, 2024
55cb35d
Fix: collectAllIndividualStylesAndEmbed for result span
Apr 24, 2024
1131828
Merge branch 'master' into master
AtlasAutocode Apr 24, 2024
9e2d3d5
Add: Clipboard toolbar buttons
Apr 26, 2024
1db1f8b
export: Clipboard toolbar buttons
Apr 26, 2024
e76daa2
Fix: Dividers not shown in toolbar when multiRowsDisplay.
Apr 27, 2024
f1231b7
Add: test for QuillController clipboard
Apr 28, 2024
c9d105a
Merge branch 'singerdmx:master' into master
AtlasAutocode Apr 28, 2024
e681e66
Merge branch 'master' into clipboard
Apr 28, 2024
8854bb0
Localizations updated
Apr 29, 2024
03a9d14
QuillControllerConfigurations and clipboard paste
May 1, 2024
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
2 changes: 1 addition & 1 deletion example/lib/screens/quill/quill_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class _QuillScreenState extends State<QuillScreen> {

@override
Widget build(BuildContext context) {
_controller.readOnly = _isReadOnly;
Copy link
Collaborator

@EchoEllet EchoEllet Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not change this in the build method since it is called more often, users use the example as a source of using the library. This can impact performance more than not using the const keyword in QuillEditorConfigurations.

We should focus on important aspects that improve the performance noticeably.

return Scaffold(
appBar: AppBar(
title: const Text('Flutter Quill'),
Expand Down Expand Up @@ -152,7 +153,6 @@ class _QuillScreenState extends State<QuillScreen> {
configurations: QuillEditorConfigurations(
sharedConfigurations: _sharedConfigurations,
controller: _controller,
readOnly: _isReadOnly,
),
scrollController: _editorScrollController,
focusNode: _editorFocusNode,
Expand Down
12 changes: 12 additions & 0 deletions lib/src/l10n/generated/quill_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ abstract class FlutterQuillLocalizations {
/// **'Copy'**
String get copy;

/// No description provided for @cut.
///
/// In en, this message translates to:
/// **'Cut'**
String get cut => 'Cut';

/// No description provided for @paste.
///
/// In en, this message translates to:
/// **'Paste'**
String get paste => 'Paste';

/// No description provided for @remove.
///
/// In en, this message translates to:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/l10n/generated/quill_localizations_da.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class FlutterQuillLocalizationsDa extends FlutterQuillLocalizations {
String get alignRight => 'Align right';

@override
String get justifyWinWidth => 'Justify win width';
String get justifyWinWidth => 'Justify';

@override
String get textDirection => 'Text direction';
Expand Down
10 changes: 8 additions & 2 deletions lib/src/l10n/generated/quill_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class FlutterQuillLocalizationsEn extends FlutterQuillLocalizations {
@override
String get copy => 'Copy';

@override
String get cut => 'Cut';

@override
String get paste => 'Paste';

@override
String get remove => 'Remove';

Expand Down Expand Up @@ -128,7 +134,7 @@ class FlutterQuillLocalizationsEn extends FlutterQuillLocalizations {
String get alignRight => 'Align right';

@override
String get justifyWinWidth => 'Justify win width';
String get justifyWinWidth => 'Justify';

@override
String get textDirection => 'Text direction';
Expand Down Expand Up @@ -402,7 +408,7 @@ class FlutterQuillLocalizationsEnUs extends FlutterQuillLocalizationsEn {
String get alignRight => 'Align right';

@override
String get justifyWinWidth => 'Justify win width';
String get justifyWinWidth => 'Justify';

@override
String get textDirection => 'Text direction';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/l10n/generated/quill_localizations_ko.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class FlutterQuillLocalizationsKo extends FlutterQuillLocalizations {
String get alignRight => 'Align right';

@override
String get justifyWinWidth => 'Justify win width';
String get justifyWinWidth => 'Justify';

@override
String get textDirection => 'Text direction';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/l10n/generated/quill_localizations_ms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class FlutterQuillLocalizationsMs extends FlutterQuillLocalizations {
String get alignRight => 'Align right';

@override
String get justifyWinWidth => 'Justify win width';
String get justifyWinWidth => 'Justify';

@override
String get textDirection => 'Text direction';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/l10n/generated/quill_localizations_nl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class FlutterQuillLocalizationsNl extends FlutterQuillLocalizations {
String get alignRight => 'Align right';

@override
String get justifyWinWidth => 'Justify win width';
String get justifyWinWidth => 'Justify';

@override
String get textDirection => 'Text direction';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/l10n/generated/quill_localizations_pl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class FlutterQuillLocalizationsPl extends FlutterQuillLocalizations {
String get alignRight => 'Align right';

@override
String get justifyWinWidth => 'Justify win width';
String get justifyWinWidth => 'Justify';

@override
String get textDirection => 'Text direction';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/l10n/generated/quill_localizations_pt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class FlutterQuillLocalizationsPt extends FlutterQuillLocalizations {
String get alignRight => 'Align right';

@override
String get justifyWinWidth => 'Justify win width';
String get justifyWinWidth => 'Justify';

@override
String get textDirection => 'Text direction';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/l10n/generated/quill_localizations_tk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class FlutterQuillLocalizationsTk extends FlutterQuillLocalizations {
String get alignRight => 'Saga deňleşdir';

@override
String get justifyWinWidth => 'Justify win width';
String get justifyWinWidth => 'Justify';

@override
String get textDirection => 'Tekst ugry';
Expand Down
14 changes: 6 additions & 8 deletions lib/src/models/config/editor/editor_configurations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class QuillEditorConfigurations extends Equatable {
this.autoFocus = false,
this.expands = false,
this.placeholder,
this.readOnly = false,
this.checkBoxReadOnly,
this.disableClipboard = false,
this.textSelectionThemeData,
Expand Down Expand Up @@ -96,7 +95,7 @@ class QuillEditorConfigurations extends Equatable {
/// by any shortcut or keyboard operation. The text is still selectable.
///
/// Defaults to `false`. Must not be `null`.
final bool readOnly;
bool get readOnly => controller.readOnly;

/// Override [readOnly] for checkbox.
///
Expand Down Expand Up @@ -142,11 +141,11 @@ class QuillEditorConfigurations extends Equatable {

/// Whether the [onTapOutside] should be triggered or not
/// Defaults to `true`
/// it have default implementation, check [onTapOuside] for more
/// it have default implementation, check [onTapOutside] for more
final bool isOnTapOutsideEnabled;

/// This will run only when [isOnTapOutsideEnabled] is true
/// by default on desktop and web it will unfocus
/// by default on desktop and web it will un-focus
/// on mobile it will only unFocus if the kind property of
/// event [PointerDownEvent] is [PointerDeviceKind.unknown]
/// you can override this to fit your needs
Expand Down Expand Up @@ -313,7 +312,7 @@ class QuillEditorConfigurations extends Equatable {
/// Additional list if links prefixes, which must not be prepended
/// with "https://" when [LinkMenuAction.launch] happened
///
/// Useful for deeplinks
/// Useful for deep-links
final List<String> customLinkPrefixes;

/// Configures the dialog theme.
Expand Down Expand Up @@ -367,10 +366,10 @@ class QuillEditorConfigurations extends Equatable {
@override
List<Object?> get props => [
placeholder,
readOnly,
controller.readOnly,
];

// We might use code generator like freezed but sometimes it can be limitied
// We might use code generator like freezed but sometimes it can be limited
// instead whatever there is a change to the parameters in this class please
// regenerate this function using extension in vs code or plugin in intellij

Expand Down Expand Up @@ -431,7 +430,6 @@ class QuillEditorConfigurations extends Equatable {
sharedConfigurations: sharedConfigurations ?? this.sharedConfigurations,
controller: controller ?? this.controller,
placeholder: placeholder ?? this.placeholder,
readOnly: readOnly ?? this.readOnly,
checkBoxReadOnly: checkBoxReadOnly ?? this.checkBoxReadOnly,
disableClipboard: disableClipboard ?? this.disableClipboard,
scrollable: scrollable ?? this.scrollable,
Expand Down
1 change: 1 addition & 0 deletions lib/src/models/config/quill_configurations.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'editor/editor_configurations.dart';
export 'quill_controller_configurations.dart';
export 'quill_shared_configurations.dart';
export 'toolbar/simple_toolbar_configurations.dart';
8 changes: 8 additions & 0 deletions lib/src/models/config/quill_controller_configurations.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class QuillControllerConfigurations {
const QuillControllerConfigurations({this.onClipboardPaste});

/// Callback when the user pastes and data has not already been processed
///
/// Return true if the paste operation was handled
final Future<bool> Function()? onClipboardPaste;
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class QuillSimpleToolbarButtonOptions extends Equatable {
this.linkStyle = const QuillToolbarLinkStyleButtonOptions(),
this.linkStyle2 = const QuillToolbarLinkStyleButton2Options(),
this.customButtons = const QuillToolbarCustomButtonOptions(),
this.clipboardCut = const QuillToolbarToggleStyleButtonOptions(),
this.clipboardCopy = const QuillToolbarToggleStyleButtonOptions(),
this.clipboardPaste = const QuillToolbarToggleStyleButtonOptions(),
});

/// The base configurations for all the buttons which will apply to all
Expand Down Expand Up @@ -113,6 +116,10 @@ class QuillSimpleToolbarButtonOptions extends Equatable {

final QuillToolbarSearchButtonOptions search;

final QuillToolbarToggleStyleButtonOptions clipboardCut;
final QuillToolbarToggleStyleButtonOptions clipboardCopy;
final QuillToolbarToggleStyleButtonOptions clipboardPaste;

/// The reason we call this buttons in the end because this is responsible
/// for all the header style buttons and not just one, you still
/// can customize it and you also have child builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class QuillSimpleToolbarConfigurations extends QuillSharedToolbarProperties {
this.showSearchButton = true,
this.showSubscript = true,
this.showSuperscript = true,
this.showClipboardCut = true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Showing new buttons in a minor version is also a breaking change. We should focus on having less buttons and an opinioned toolbar that fit the needs of most of our users, noticed that currently, the toolbar takes more than half of the screen, which is an issue I introduced in 2023 when I introduced support for Material 3.

We should make it take less space, with less buttons, and instead have sections or groups where each group have related buttons, users can navigate between them, we should not touch the QuillSimpleToolbar anymore and introduce a new toolbar unless most developers want something different, currently, we don't have any reports regarding the toolbar though I noticed some developers already started to develop their our toolbar. We should introduce a new one instead of changing this. Or maybe provide those buttons so they can use them somewhere different than the toolbar.

The toolbar is one of the things that really need improvements. The UI is important for the end user.

this.showClipboardCopy = true,
this.showClipboardPaste = true,
this.linkStyleType = LinkStyleType.original,
this.headerStyleType = HeaderStyleType.original,

Expand Down Expand Up @@ -195,6 +198,9 @@ class QuillSimpleToolbarConfigurations extends QuillSharedToolbarProperties {
final bool showSearchButton;
final bool showSubscript;
final bool showSuperscript;
final bool showClipboardCut;
final bool showClipboardCopy;
final bool showClipboardPaste;

/// Toolbar items to display for controls of embed blocks
final List<EmbedButtonBuilder>? embedButtons;
Expand Down
14 changes: 7 additions & 7 deletions lib/src/models/documents/nodes/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,20 +407,20 @@ base class Line extends QuillContainer<Leaf?> {
final data = queryChild(offset, true);
var node = data.node as Leaf?;
if (node != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change related? Not sure why we need it for this feature.

var pos = 0;
pos = node.length - data.offset;
var pos = math.min(local, node.length - data.offset);
if (node is QuillText && node.style.isNotEmpty) {
result.add(OffsetValue(beg, node.style, node.length));
result.add(OffsetValue(beg, node.style, pos));
} else if (node.value is Embeddable) {
result.add(OffsetValue(beg, node.value as Embeddable, node.length));
result.add(OffsetValue(beg, node.value as Embeddable, pos));
}

while (!node!.isLast && pos < local) {
node = node.next as Leaf;
final span = math.min(local - pos, node.length);
if (node is QuillText && node.style.isNotEmpty) {
result.add(OffsetValue(pos + beg, node.style, node.length));
result.add(OffsetValue(pos + beg, node.style, span));
} else if (node.value is Embeddable) {
result.add(
OffsetValue(pos + beg, node.value as Embeddable, node.length));
result.add(OffsetValue(pos + beg, node.value as Embeddable, span));
}
pos += node.length;
}
Expand Down
Loading