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

Prevents sending excessive value updates to the native side #12

Merged
merged 2 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions packages/zefyr/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.1

* Fixed: Prevent sending excessive value updates to the native side
which cause race conditions (#12).

## 0.1.0

* Initial release.
10 changes: 5 additions & 5 deletions packages/zefyr/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class _MyHomePageState extends State<MyHomePage> {
Widget build(BuildContext context) {
final theme = new ZefyrThemeData(
toolbarTheme: ZefyrToolbarTheme.fallback(context).copyWith(
color: Colors.grey.shade800,
toggleColor: Colors.grey.shade900,
iconColor: Colors.white,
disabledIconColor: Colors.grey.shade500,
),
color: Colors.grey.shade800,
toggleColor: Colors.grey.shade900,
iconColor: Colors.white,
disabledIconColor: Colors.grey.shade500,
),
);

final done = _editing
Expand Down
26 changes: 21 additions & 5 deletions packages/zefyr/lib/src/widgets/input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,23 @@ class InputConnectionController implements TextInputClient {
void updateRemoteValue(TextEditingValue value) {
if (!hasConnection) return;

if (value == _lastKnownRemoteTextEditingValue) return;
// Since we don't keep track of composing range in value provided by
// ZefyrController we need to add it here manually before comparing
// with the last known remote value.
// It is important to prevent excessive remote updates as it can cause
// race conditions.
final actualValue = value.copyWith(
composing: _lastKnownRemoteTextEditingValue.composing,
);

if (actualValue == _lastKnownRemoteTextEditingValue) return;

bool shouldRemember = value.text != _lastKnownRemoteTextEditingValue.text;
_lastKnownRemoteTextEditingValue = value;
_textInputConnection.setEditingState(value);
// Only keep track if text changed (selection changes are not relevant)
_lastKnownRemoteTextEditingValue = actualValue;
_textInputConnection.setEditingState(actualValue);
if (shouldRemember) {
_sentRemoteValues.add(value);
// Only keep track if text changed (selection changes are not relevant)
_sentRemoteValues.add(actualValue);
}
}

Expand Down Expand Up @@ -103,6 +113,12 @@ class InputConnectionController implements TextInputClient {
_sentRemoteValues.remove(value);
return;
}

if (_lastKnownRemoteTextEditingValue == value) {
// There is no difference between this value and the last known value.
return;
}

// Note Flutter (unintentionally?) silences errors occurred during
// text input update, so we have to report it ourselves.
// For more details see https://github.com/flutter/flutter/issues/19191
Expand Down
2 changes: 1 addition & 1 deletion packages/zefyr/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: zefyr
description: Rich text editor for Flutter.
version: 0.1.0
version: 0.1.1
author: Anatoly Pulyaevskiy <anatoly.pulyaevskiy@gmail.com>
homepage: https://github.com/pulyaevskiy/zefyr

Expand Down