From 471c1cb7ee542977b777b0fc10cbaa5cfb35ddea Mon Sep 17 00:00:00 2001 From: li3317 Date: Sun, 21 Feb 2021 22:53:04 -0500 Subject: [PATCH 01/10] scroll screen on keyboard popup --- lib/widgets/editor.dart | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 29472aae..50b056dc 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -889,15 +889,10 @@ class RenderEditor extends RenderEditableContainerBox kMargin + offsetInViewport; final caretBottom = endpoints.single.point.dy + kMargin + offsetInViewport; - double dy; - if (caretTop < scrollOffset) { - dy = caretTop; - } else if (caretBottom > scrollOffset + viewportHeight) { + double dy = caretTop; + if (caretBottom > scrollOffset + viewportHeight) { dy = caretBottom - viewportHeight; } - if (dy == null) { - return null; - } return math.max(dy, 0.0); } } From c2c5b2a90f11a4e997c3787e28d5d0843eab0815 Mon Sep 17 00:00:00 2001 From: li3317 Date: Sun, 21 Feb 2021 22:54:53 -0500 Subject: [PATCH 02/10] bump version to 0.3.1 --- CHANGELOG.md | 5 ++++- pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7480006f..cff31022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,4 +93,7 @@ * Support placeholder. ## [0.3.0] -* Line Height calculated based on font size. \ No newline at end of file +* Line Height calculated based on font size. + +## [0.3.1] +* cursor focus when keyboard is on. \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 93c91366..8abfafb7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill description: One client and affiliated collaborator of Flutter Quill is Bullet Journal App. -version: 0.3.0 +version: 0.3.1 #author: bulletjournal homepage: https://bulletjournal.us/home/index.html repository: https://github.com/singerdmx/flutter-quill.git From 16e247307989e00f6b8cbd9d825563d6f51779da Mon Sep 17 00:00:00 2001 From: li3317 Date: Mon, 22 Feb 2021 17:45:22 -0500 Subject: [PATCH 03/10] Change type of SizeAttribute from String to double --- app/assets/sample_data.json | 24 ++++++++++++++++++++++++ lib/widgets/text_line.dart | 6 +++++- lib/widgets/toolbar.dart | 3 +++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/assets/sample_data.json b/app/assets/sample_data.json index 15cc2f2a..7fe41833 100644 --- a/app/assets/sample_data.json +++ b/app/assets/sample_data.json @@ -473,6 +473,30 @@ }, "insert": "Huge" }, + { + "attributes": { + "size": "15.0" + }, + "insert": "font size 15" + }, + { + "insert": " " + }, + { + "attributes": { + "size": "35" + }, + "insert": "font size 35" + }, + { + "insert": " " + }, + { + "attributes": { + "size": "20" + }, + "insert": "font size 20" + }, { "insert": "\n" } diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index 8608e69b..ca8e52ce 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -153,7 +153,11 @@ class TextLine extends StatelessWidget { res = res.merge(defaultStyles.sizeHuge); break; default: - throw "Invalid size ${size.value}"; + double fontSize = double.tryParse(size.value); + if (fontSize != null) { + res = res.merge(TextStyle(fontSize: fontSize)); + } else + throw "Invalid size ${size.value}"; } } diff --git a/lib/widgets/toolbar.dart b/lib/widgets/toolbar.dart index ae0a6553..03c1bdf1 100644 --- a/lib/widgets/toolbar.dart +++ b/lib/widgets/toolbar.dart @@ -784,6 +784,9 @@ class _HistoryButtonState extends State { } void _setIconColor() { + + if(!mounted) return; + if (widget.undo) { setState(() { _iconColor = widget.controller.hasUndo From fd3aac999f4fb34d036d8d7c71b7152170fd21c0 Mon Sep 17 00:00:00 2001 From: li3317 Date: Mon, 22 Feb 2021 17:49:29 -0500 Subject: [PATCH 04/10] small fix --- lib/widgets/text_line.dart | 3 ++- lib/widgets/toolbar.dart | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index ca8e52ce..ffe7ee93 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -156,8 +156,9 @@ class TextLine extends StatelessWidget { double fontSize = double.tryParse(size.value); if (fontSize != null) { res = res.merge(TextStyle(fontSize: fontSize)); - } else + } else { throw "Invalid size ${size.value}"; + } } } diff --git a/lib/widgets/toolbar.dart b/lib/widgets/toolbar.dart index 03c1bdf1..921cb91c 100644 --- a/lib/widgets/toolbar.dart +++ b/lib/widgets/toolbar.dart @@ -784,8 +784,7 @@ class _HistoryButtonState extends State { } void _setIconColor() { - - if(!mounted) return; + if (!mounted) return; if (widget.undo) { setState(() { From 08ed4c3c85b2bf38cb9631339f81d5ab68edc114 Mon Sep 17 00:00:00 2001 From: Xin Yao Date: Wed, 24 Feb 2021 02:34:41 -0800 Subject: [PATCH 05/10] Fix cursor focus issue when keyboard is on --- CHANGELOG.md | 5 ++++- app/pubspec.lock | 23 ++++++++++++++++++++++- lib/widgets/editor.dart | 9 +++++++-- lib/widgets/raw_editor.dart | 21 ++++++++++++++++++++- pubspec.lock | 21 +++++++++++++++++++++ pubspec.yaml | 6 +++--- 6 files changed, 77 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cff31022..2ae32204 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,4 +96,7 @@ * Line Height calculated based on font size. ## [0.3.1] -* cursor focus when keyboard is on. \ No newline at end of file +* cursor focus when keyboard is on. + +## [0.3.2] +* Fix cursor focus issue when keyboard is on. \ No newline at end of file diff --git a/app/pubspec.lock b/app/pubspec.lock index 53c35ed4..92f7e30d 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -111,6 +111,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.3.4" + flutter_keyboard_visibility: + dependency: transitive + description: + name: flutter_keyboard_visibility + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.4" + flutter_keyboard_visibility_platform_interface: + dependency: transitive + description: + name: flutter_keyboard_visibility_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + flutter_keyboard_visibility_web: + dependency: transitive + description: + name: flutter_keyboard_visibility_web + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" flutter_plugin_android_lifecycle: dependency: transitive description: @@ -124,7 +145,7 @@ packages: path: ".." relative: true source: path - version: "0.3.0" + version: "0.3.2" flutter_test: dependency: "direct dev" description: flutter diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 50b056dc..29472aae 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -889,10 +889,15 @@ class RenderEditor extends RenderEditableContainerBox kMargin + offsetInViewport; final caretBottom = endpoints.single.point.dy + kMargin + offsetInViewport; - double dy = caretTop; - if (caretBottom > scrollOffset + viewportHeight) { + double dy; + if (caretTop < scrollOffset) { + dy = caretTop; + } else if (caretBottom > scrollOffset + viewportHeight) { dy = caretBottom - viewportHeight; } + if (dy == null) { + return null; + } return math.max(dy, 0.0); } } diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index fbbb8a83..b99ddae1 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -7,6 +7,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; import 'package:flutter_quill/models/documents/attribute.dart'; import 'package:flutter_quill/models/documents/document.dart'; import 'package:flutter_quill/models/documents/nodes/block.dart'; @@ -123,8 +124,10 @@ class RawEditorState extends EditorState FocusAttachment _focusAttachment; CursorCont _cursorCont; ScrollController _scrollController; + KeyboardVisibilityController _keyboardVisibilityController; KeyboardListener _keyboardListener; bool _didAutoFocus = false; + bool _keyboardVisible = false; DefaultStyles _styles; final ClipboardStatusNotifier _clipboardStatus = ClipboardStatusNotifier(); final LayerLink _toolbarLayerLink = LayerLink(); @@ -692,6 +695,16 @@ class RawEditorState extends EditorState handleDelete, ); + _keyboardVisibilityController = KeyboardVisibilityController(); + _keyboardVisibilityController.onChange.listen((bool visible) { + setState(() { + _keyboardVisible = visible; + if (visible) { + _onChangeTextEditingValue(); + } + }); + }); + _focusAttachment = widget.focusNode.attach(context, onKey: (node, event) => _keyboardListener.handleRawKeyEvent(event)); widget.focusNode.addListener(_handleFocusChanged); @@ -869,8 +882,14 @@ class RawEditorState extends EditorState } _didChangeTextEditingValue() { - requestKeyboard(); + if (_keyboardVisible) { + _onChangeTextEditingValue(); + } else { + requestKeyboard(); + } + } + _onChangeTextEditingValue() { _showCaretOnScreen(); updateRemoteValueIfNeeded(); _cursorCont.startOrStopCursorTimerIfNeeded( diff --git a/pubspec.lock b/pubspec.lock index 9842e845..664e3fc8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -90,6 +90,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.3.5" + flutter_keyboard_visibility: + dependency: "direct main" + description: + name: flutter_keyboard_visibility + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.4" + flutter_keyboard_visibility_platform_interface: + dependency: transitive + description: + name: flutter_keyboard_visibility_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + flutter_keyboard_visibility_web: + dependency: transitive + description: + name: flutter_keyboard_visibility_web + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" flutter_plugin_android_lifecycle: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 8abfafb7..90baae21 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill description: One client and affiliated collaborator of Flutter Quill is Bullet Journal App. -version: 0.3.1 +version: 0.3.2 #author: bulletjournal homepage: https://bulletjournal.us/home/index.html repository: https://github.com/singerdmx/flutter-quill.git @@ -17,12 +17,12 @@ dependencies: collection: ^1.14.13 tuple: ^1.0.3 url_launcher: ^5.7.10 - flutter_colorpicker: ^0.3.4 + flutter_colorpicker: ^0.3.5 image_picker: ^0.6.7+22 photo_view: ^0.10.3 universal_html: ^1.2.1 file_picker: ^2.1.6 - + flutter_keyboard_visibility: ^4.0.4 dev_dependencies: flutter_test: From 33ce59ae4f39e04aea19600308621345b27e2cd6 Mon Sep 17 00:00:00 2001 From: Xin Yao Date: Wed, 24 Feb 2021 02:40:27 -0800 Subject: [PATCH 06/10] Upgrade flutter_colorpicker --- app/pubspec.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/pubspec.lock b/app/pubspec.lock index 92f7e30d..1b38ea1a 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -110,7 +110,7 @@ packages: name: flutter_colorpicker url: "https://pub.dartlang.org" source: hosted - version: "0.3.4" + version: "0.3.5" flutter_keyboard_visibility: dependency: transitive description: From 06000734e68e16011eb403e4c99b10900c17fee1 Mon Sep 17 00:00:00 2001 From: Xin Yao Date: Wed, 24 Feb 2021 02:46:09 -0800 Subject: [PATCH 07/10] Update _keyboardVisibilityController.onChange.listen --- lib/widgets/raw_editor.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index b99ddae1..e9376e7f 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -699,10 +699,10 @@ class RawEditorState extends EditorState _keyboardVisibilityController.onChange.listen((bool visible) { setState(() { _keyboardVisible = visible; - if (visible) { - _onChangeTextEditingValue(); - } }); + if (visible) { + _onChangeTextEditingValue(); + } }); _focusAttachment = widget.focusNode.attach(context, From 2efb4b12c2ce6581b2c048ec33a1c3bbf210b998 Mon Sep 17 00:00:00 2001 From: Xin Yao Date: Wed, 24 Feb 2021 02:56:21 -0800 Subject: [PATCH 08/10] Update _keyboardVisibilityController.onChange.listen --- lib/widgets/raw_editor.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index e9376e7f..98a70955 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -697,9 +697,7 @@ class RawEditorState extends EditorState _keyboardVisibilityController = KeyboardVisibilityController(); _keyboardVisibilityController.onChange.listen((bool visible) { - setState(() { - _keyboardVisible = visible; - }); + _keyboardVisible = visible; if (visible) { _onChangeTextEditingValue(); } From 6c156d4a9a9b33a2d4a7529fe367e8d9dcaee718 Mon Sep 17 00:00:00 2001 From: li3317 Date: Wed, 24 Feb 2021 22:36:22 -0500 Subject: [PATCH 09/10] more fix on keyboard focus when cursor is on + bump version --- CHANGELOG.md | 5 ++++- lib/widgets/editor.dart | 8 +++----- pubspec.yaml | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ae32204..3f23d572 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,4 +99,7 @@ * cursor focus when keyboard is on. ## [0.3.2] -* Fix cursor focus issue when keyboard is on. \ No newline at end of file +* Fix cursor focus issue when keyboard is on. + +## [0.3.3] +* More fix on cursor focus issue when keyboard is on. \ No newline at end of file diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 29472aae..0c4668d0 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -876,19 +876,17 @@ class RenderEditor extends RenderEditableContainerBox double getOffsetToRevealCursor( double viewportHeight, double scrollOffset, double offsetInViewport) { List endpoints = getEndpointsForSelection(selection); - if (endpoints.length != 1) { - return null; - } + TextSelectionPoint endpoint = endpoints.first; RenderEditableBox child = childAtPosition(selection.extent); const kMargin = 8.0; - double caretTop = endpoints.single.point.dy - + double caretTop = endpoint.point.dy - child.preferredLineHeight(TextPosition( offset: selection.extentOffset - child.getContainer().getOffset())) - kMargin + offsetInViewport; - final caretBottom = endpoints.single.point.dy + kMargin + offsetInViewport; + final caretBottom = endpoint.point.dy + kMargin + offsetInViewport; double dy; if (caretTop < scrollOffset) { dy = caretTop; diff --git a/pubspec.yaml b/pubspec.yaml index 90baae21..9c6efdc4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill description: One client and affiliated collaborator of Flutter Quill is Bullet Journal App. -version: 0.3.2 +version: 0.3.3 #author: bulletjournal homepage: https://bulletjournal.us/home/index.html repository: https://github.com/singerdmx/flutter-quill.git From ae8f1a396b93078203848a2f7621df619d736d62 Mon Sep 17 00:00:00 2001 From: li3317 Date: Wed, 24 Feb 2021 22:38:57 -0500 Subject: [PATCH 10/10] small fix --- lib/widgets/raw_editor.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index 98a70955..1b84e9b2 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -574,7 +574,9 @@ class RawEditorState extends EditorState _selectionOverlay?.handlesVisible = _shouldShowSelectionHandles(); - requestKeyboard(); + if (!_keyboardVisible) { + requestKeyboard(); + } } _buildChildren(Document doc, BuildContext context) {