From ef64616117200c6852a52df3c7a297168444020d Mon Sep 17 00:00:00 2001 From: Ellet <73608287+freshtechtips@users.noreply.github.com> Date: Thu, 26 Oct 2023 20:27:31 +0300 Subject: [PATCH] Fix bug && New properties && Remove old one --- CHANGELOG.md | 5 +++- .../models/config/editor/configurations.dart | 22 ++++++++++---- lib/src/widgets/editor/editor.dart | 2 +- lib/src/widgets/raw_editor/raw_editor.dart | 29 +++++++++++++++---- pubspec.yaml | 2 +- 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd3af0df..d5ed02f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ -## [8.0.1] +## [8.1.0] - Fixes a word typo of `mirgration` to `migration` in readme & migration document. - Updated migration guide +- Remove property `enableUnfocusOnTapOutside` in QuillEditor Configurations and add `isOnTapOutsideEnabled` instead +- Add a new callback which is called `onTapOutside` in the `QuillEditorConfigurations` which allow you to do something when tap outside of the edtior +- Fix a bug which cause the web platform to not unfocus the editor when tap outside of it (the default logic) to override this pleae pass a value to the callback ``onTapOutside`` ## [8.0.0] - If you have mirgrated recently, don't get scared from this update, it just add a documentation, mirgration guide and mark the version as more stable release, since we did break a lot of breaking changes (at least that what most developers says) we should have change the major version but when we were in the development of this new version, our time was very tight and now we are fixing the version number diff --git a/lib/src/models/config/editor/configurations.dart b/lib/src/models/config/editor/configurations.dart index 6696b26a..d84718e4 100644 --- a/lib/src/models/config/editor/configurations.dart +++ b/lib/src/models/config/editor/configurations.dart @@ -1,3 +1,4 @@ +// ignore_for_file: public_member_api_docs, sort_constructors_first import 'package:equatable/equatable.dart'; import 'package:flutter/foundation.dart' show Brightness, Uint8List, immutable; import 'package:flutter/material.dart' @@ -57,7 +58,8 @@ class QuillEditorConfigurations extends Equatable { this.customShortcuts, this.customActions, this.detectWordBoundary = true, - this.enableUnfocusOnTapOutside = true, + this.isOnTapOutsideEnabled = true, + this.onTapOutside, this.customLinkPrefixes = const [], this.dialogTheme, this.contentInsertionConfiguration, @@ -103,8 +105,17 @@ class QuillEditorConfigurations extends Equatable { /// Defaults to `false`. Cannot be `null`. final bool autoFocus; - /// Whether focus should be revoked on tap outside the editor. - final bool enableUnfocusOnTapOutside; + /// Whether the [onTapOutside] should be triggered or not + /// by Defaults to `true` + /// it have default implementation, check [onTapOuside] for more + final bool isOnTapOutsideEnabled; + + /// This will run only when [isOnTapOutsideEnabled] is true + /// by default on desktop and web it will unfocus + /// on mobile it will only unFocus if the kind property of + /// event [PointerDownEvent] is [PointerDeviceKind.unknown] + /// you can override this to fit your needs + final Function(PointerDownEvent event, FocusNode focusNode)? onTapOutside; /// Whether to show cursor. /// @@ -313,6 +324,7 @@ class QuillEditorConfigurations extends Equatable { EdgeInsetsGeometry? padding, bool? autoFocus, bool? enableUnfocusOnTapOutside, + Function(PointerDownEvent event, FocusNode focusNode)? onTapOutside, bool? showCursor, bool? paintCursorAboveText, bool? enableInteractiveSelection, @@ -353,8 +365,8 @@ class QuillEditorConfigurations extends Equatable { scrollBottomInset: scrollBottomInset ?? this.scrollBottomInset, padding: padding ?? this.padding, autoFocus: autoFocus ?? this.autoFocus, - enableUnfocusOnTapOutside: - enableUnfocusOnTapOutside ?? this.enableUnfocusOnTapOutside, + isOnTapOutsideEnabled: enableUnfocusOnTapOutside ?? isOnTapOutsideEnabled, + onTapOutside: onTapOutside ?? this.onTapOutside, showCursor: showCursor ?? this.showCursor, paintCursorAboveText: paintCursorAboveText ?? this.paintCursorAboveText, enableInteractiveSelection: diff --git a/lib/src/widgets/editor/editor.dart b/lib/src/widgets/editor/editor.dart index bc11b35e..766ad8aa 100644 --- a/lib/src/widgets/editor/editor.dart +++ b/lib/src/widgets/editor/editor.dart @@ -293,7 +293,7 @@ class QuillEditorState extends State customShortcuts: configurations.customShortcuts, customActions: configurations.customActions, customLinkPrefixes: configurations.customLinkPrefixes, - enableUnfocusOnTapOutside: configurations.enableUnfocusOnTapOutside, + enableUnfocusOnTapOutside: configurations.isOnTapOutsideEnabled, dialogTheme: configurations.dialogTheme, contentInsertionConfiguration: configurations.contentInsertionConfiguration, diff --git a/lib/src/widgets/raw_editor/raw_editor.dart b/lib/src/widgets/raw_editor/raw_editor.dart index 117c6f30..80e920fd 100644 --- a/lib/src/widgets/raw_editor/raw_editor.dart +++ b/lib/src/widgets/raw_editor/raw_editor.dart @@ -424,6 +424,10 @@ class RawEditorState extends EditorState } void _defaultOnTapOutside(PointerDownEvent event) { + if (isWeb()) { + widget.focusNode.unfocus(); + } + /// The focus dropping behavior is only present on desktop platforms /// and mobile browsers. switch (defaultTargetPlatform) { @@ -434,9 +438,9 @@ class RawEditorState extends EditorState // in the web browser, but we do unfocus for all other kinds of events. switch (event.kind) { case ui.PointerDeviceKind.touch: - if (isWeb()) { - widget.focusNode.unfocus(); - } + // if (isWeb()) { + // widget.focusNode.unfocus(); + // } break; case ui.PointerDeviceKind.mouse: case ui.PointerDeviceKind.stylus: @@ -446,7 +450,8 @@ class RawEditorState extends EditorState break; case ui.PointerDeviceKind.trackpad: throw UnimplementedError( - 'Unexpected pointer down event for trackpad'); + 'Unexpected pointer down event for trackpad', + ); } break; case TargetPlatform.linux: @@ -454,6 +459,11 @@ class RawEditorState extends EditorState case TargetPlatform.windows: widget.focusNode.unfocus(); break; + default: + throw UnsupportedError( + 'The platform ${defaultTargetPlatform.name} is not supported in the' + ' _defaultOnTapOutside', + ); } } @@ -555,7 +565,16 @@ class RawEditorState extends EditorState return TextFieldTapRegion( enabled: widget.enableUnfocusOnTapOutside, - onTapOutside: _defaultOnTapOutside, + onTapOutside: (event) { + final onTapOutside = + context.requireQuillEditorConfigurations.onTapOutside; + if (onTapOutside != null) { + context.requireQuillEditorConfigurations.onTapOutside + ?.call(event, widget.focusNode); + return; + } + _defaultOnTapOutside(event); + }, child: QuillStyles( data: _styles!, child: Shortcuts( diff --git a/pubspec.yaml b/pubspec.yaml index 697c3d17..86abf644 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill description: A rich text editor built for the modern Android, iOS, web and desktop platforms. It is the WYSIWYG editor and a Quill component for Flutter. -version: 8.0.1 +version: 8.1.0 homepage: https://1o24bbs.com/c/bulletjournal/108 repository: https://github.com/singerdmx/flutter-quill topics: