Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
satotoshitaka11 authored Jan 21, 2025
2 parents 63b5b57 + 221fce4 commit 06c71d3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/1_bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ body:
- type: checkboxes
attributes:
label: Have you checked for an existing issue?
description: Ensure there isn’t already an open issue for this feature request.
description: Ensure there isn’t already an open issue for this bug.
options:
- label: I have searched the [existing issues](https://github.com/singerdmx/flutter-quill/issues)
required: true
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `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-dev.21] - 2025-01-21

### Added

- `enableClipboardPaste` flag in `QuillToolbarClipboardButton` to determine if the button defaults to `null,` which will use `ClipboardMonitor`, which checks every second if the clipboard has content to paste [#2427](https://github.com/singerdmx/flutter-quill/pull/2427).

## [11.0.0-dev.20] - 2025-01-19

### Changed
Expand Down Expand Up @@ -194,7 +200,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Apple-specific font dependency for subscript and superscript functionality from the example.
- **BREAKING**: The [`super_clipboard`](https://pub.dev/packages/super_clipboard) plugin, To restore legacy behavior for `super_clipboard`, use [`flutter_quill_extensions`](https://pub.dev/packages/flutter_quill_extensions) package and `FlutterQuillExtensions.useSuperClipboardPlugin()`.

[unreleased]: https://github.com/singerdmx/flutter-quill/compare/v11.0.0-dev.20...HEAD
[unreleased]: https://github.com/singerdmx/flutter-quill/compare/v11.0.0-dev.21...HEAD
[11.0.0-dev.21]: https://github.com/singerdmx/flutter-quill/compare/v11.0.0-dev.20...v11.0.0-dev.21
[11.0.0-dev.20]: https://github.com/singerdmx/flutter-quill/compare/v11.0.0-dev.19...v11.0.0-dev.20
[11.0.0-dev.19]: https://github.com/singerdmx/flutter-quill/compare/v11.0.0-dev.18...v11.0.0-dev.19
[11.0.0-dev.18]: https://github.com/singerdmx/flutter-quill/compare/v11.0.0-dev.17...v11.0.0-dev.18
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ packages:
path: ".."
relative: true
source: path
version: "11.0.0-dev.20"
version: "11.0.0-dev.21"
flutter_quill_delta_from_html:
dependency: transitive
description:
Expand Down
67 changes: 57 additions & 10 deletions lib/src/toolbar/buttons/clipboard_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ class ClipboardMonitor {
bool get canPaste => _canPaste;
Timer? _timer;

bool _isCheckingClipboard = false;

void monitorClipboard(bool add, void Function() listener) {
if (kIsWeb) return;

if (add) {
_timer = Timer.periodic(
const Duration(seconds: 1), (timer) => _update(listener));
Expand All @@ -33,17 +36,27 @@ class ClipboardMonitor {
}

Future<void> _update(void Function() listener) async {
if (_isCheckingClipboard) {
return;
}

_isCheckingClipboard = true;

final clipboardService = ClipboardServiceProvider.instance;

if (await clipboardService.hasClipboardContent) {
_canPaste = true;

listener();
}

_isCheckingClipboard = false;
}
}

@experimental
class QuillToolbarClipboardButton extends QuillToolbarToggleStyleBaseButton {
QuillToolbarClipboardButton({
const QuillToolbarClipboardButton({
required super.controller,
required this.clipboardAction,
QuillToolbarClipboardButtonOptions? options,
Expand All @@ -55,21 +68,19 @@ class QuillToolbarClipboardButton extends QuillToolbarToggleStyleBaseButton {
}) : _options = options,
super(options: options ?? const QuillToolbarClipboardButtonOptions());

// TODO: This field will be used by the PR: https://github.com/singerdmx/flutter-quill/pull/2427
// ignore: unused_field
final QuillToolbarClipboardButtonOptions? _options;

final ClipboardAction clipboardAction;

final ClipboardMonitor _monitor = ClipboardMonitor();

@override
State<StatefulWidget> createState() => QuillToolbarClipboardButtonState();
}

class QuillToolbarClipboardButtonState
extends QuillToolbarToggleStyleBaseButtonState<
QuillToolbarClipboardButton> {
final ClipboardMonitor _monitor = ClipboardMonitor();

@override
bool get currentStateValue {
switch (widget.clipboardAction) {
Expand All @@ -78,23 +89,54 @@ class QuillToolbarClipboardButtonState
case ClipboardAction.copy:
return !controller.selection.isCollapsed;
case ClipboardAction.paste:
return !controller.readOnly && (kIsWeb || widget._monitor.canPaste);
return !controller.readOnly &&
(kIsWeb ||
(widget._options?.enableClipboardPaste ?? _monitor.canPaste));
}
}

void _listenClipboardStatus() => didChangeEditingValue();

@override
void didUpdateWidget(QuillToolbarClipboardButton oldWidget) {
super.didUpdateWidget(oldWidget);

// Default didUpdateWidget handler, otherwise simple flag change didn't stop the monitor.
if (oldWidget.controller != controller) {
oldWidget.controller.removeListener(didChangeEditingValue);
removeExtraListener(oldWidget);
controller.addListener(didChangeEditingValue);
addExtraListener();
currentValue = currentStateValue;
}
// The controller didn't change, but enableClipboardPaste did.
else if (widget.clipboardAction == ClipboardAction.paste) {
final isTimerActive = _monitor._timer?.isActive ?? false;

// Enable clipboard monitoring if not active and should be monitored.
if (_shouldUseClipboardMonitor && !isTimerActive) {
_monitor.monitorClipboard(true, _listenClipboardStatus);
}
// Disable clipboard monitoring if active and should not be monitored.
else if (!_shouldUseClipboardMonitor && isTimerActive) {
_monitor.monitorClipboard(false, _listenClipboardStatus);
}

currentValue = currentStateValue;
}
}

@override
void addExtraListener() {
if (widget.clipboardAction == ClipboardAction.paste) {
widget._monitor.monitorClipboard(true, _listenClipboardStatus);
if (_shouldUseClipboardMonitor) {
_monitor.monitorClipboard(true, _listenClipboardStatus);
}
}

@override
void removeExtraListener(covariant QuillToolbarClipboardButton oldWidget) {
if (widget.clipboardAction == ClipboardAction.paste) {
oldWidget._monitor.monitorClipboard(false, _listenClipboardStatus);
if (_shouldUseClipboardMonitor) {
_monitor.monitorClipboard(false, _listenClipboardStatus);
}
}

Expand All @@ -112,6 +154,11 @@ class QuillToolbarClipboardButtonState
ClipboardAction.paste => Icons.paste_outlined,
};

bool get _shouldUseClipboardMonitor {
return widget.clipboardAction == ClipboardAction.paste &&
(widget._options?.enableClipboardPaste == null);
}

void _onPressed() {
switch (widget.clipboardAction) {
case ClipboardAction.cut:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_quill
description: "A rich text editor built for Android, iOS, Web, and desktop platforms. It's the WYSIWYG editor and a Quill component for Flutter."
version: 11.0.0-dev.20
version: 11.0.0-dev.21
homepage: https://github.com/singerdmx/flutter-quill/
repository: https://github.com/singerdmx/flutter-quill/
issue_tracker: https://github.com/singerdmx/flutter-quill/issues/
Expand Down

0 comments on commit 06c71d3

Please sign in to comment.