Skip to content

Commit

Permalink
Send empty composing range to engine if invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir-P committed Apr 2, 2024
1 parent eef5462 commit 69dc727
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/fleather/lib/src/widgets/editor_input_client_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:math';
import 'dart:ui' as ui;

import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
Expand Down Expand Up @@ -95,7 +97,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState
// with the last known remote value.
// It is important to prevent excessive remote updates as it can cause
// race conditions.
final actualValue = value.copyWith(
var actualValue = value.copyWith(
composing: _lastKnownRemoteTextEditingValue?.composing,
);

Expand All @@ -107,6 +109,16 @@ mixin RawEditorStateTextInputClientMixin on EditorState
performSpellCheck(value.text);
}

// This is to prevent sending an editing state with invalid composing range
// to engine.
// TODO: Maybe it's better to also include composing range in controller?
// Actions like [_DeleteTextAction] are using controller's editing value
// to update remote value.
// See https://github.com/fleather-editor/fleather/issues/259#issuecomment-2032404450
if (!actualValue.isComposingRangeValid) {
actualValue = actualValue.copyWith(composing: TextRange.empty);
}

_lastKnownRemoteTextEditingValue = actualValue;
_textInputConnection!.setEditingState(actualValue);
}
Expand Down

0 comments on commit 69dc727

Please sign in to comment.