Browse Source

Workaround for silenced errors in text input

Anatoly Pulyaevskiy 6 years ago
parent
commit
cd60b18bfc
2 changed files with 24 additions and 11 deletions
  1. 3
    3
      packages/notus/lib/src/document.dart
  2. 21
    8
      packages/zefyr/lib/src/widgets/input.dart

+ 3
- 3
packages/notus/lib/src/document.dart View File

@@ -130,10 +130,10 @@ class NotusDocument {
130 130
     assert(index >= 0 && length > 0);
131 131
     // TODO: need a heuristic rule to ensure last line-break.
132 132
     final change = _heuristics.applyDeleteRules(this, index, length);
133
-    // Delete rules are allowed to prevent the edit.
134
-//    if (change.isNotEmpty) {
133
+    // Delete rules are allowed to prevent the edit so it may be empty.
134
+    if (change.isNotEmpty) {
135 135
       compose(change, ChangeSource.local);
136
-//    }
136
+    }
137 137
     return change;
138 138
   }
139 139
 

+ 21
- 8
packages/zefyr/lib/src/widgets/input.dart View File

@@ -103,14 +103,27 @@ class InputConnectionController implements TextInputClient {
103 103
       _sentRemoteValues.remove(value);
104 104
       return;
105 105
     }
106
-
107
-    final effectiveLastKnownValue = _lastKnownRemoteTextEditingValue;
108
-    _lastKnownRemoteTextEditingValue = value;
109
-    final oldText = effectiveLastKnownValue.text;
110
-    final text = value.text;
111
-    final cursorPosition = value.selection.extentOffset;
112
-    final diff = fastDiff(oldText, text, cursorPosition);
113
-    onValueChanged(diff.start, diff.deleted, diff.inserted, value.selection);
106
+    // Note Flutter (unintentionally?) silences errors occurred during
107
+    // text input update, so we have to report it ourselves.
108
+    // For more details see https://github.com/flutter/flutter/issues/19191
109
+    // TODO: remove try-catch when/if Flutter stops silencing these errors.
110
+    try {
111
+      final effectiveLastKnownValue = _lastKnownRemoteTextEditingValue;
112
+      _lastKnownRemoteTextEditingValue = value;
113
+      final oldText = effectiveLastKnownValue.text;
114
+      final text = value.text;
115
+      final cursorPosition = value.selection.extentOffset;
116
+      final diff = fastDiff(oldText, text, cursorPosition);
117
+      onValueChanged(diff.start, diff.deleted, diff.inserted, value.selection);
118
+    } catch (e, trace) {
119
+      FlutterError.reportError(new FlutterErrorDetails(
120
+        exception: e,
121
+        stack: trace,
122
+        library: 'Zefyr',
123
+        context: 'while updating editing value',
124
+      ));
125
+      rethrow;
126
+    }
114 127
   }
115 128
 
116 129
   //