Skip to content

Commit

Permalink
fix demo in 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zmtzawqlp committed Aug 26, 2024
1 parent 41a4526 commit 75bf133
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
54 changes: 52 additions & 2 deletions example/lib/src/pages/chat_demo1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:extended_text_field/extended_text_field.dart';
import 'package:ff_annotation_route_library/ff_annotation_route_library.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:loading_more_list/loading_more_list.dart';
import '../data/tu_chong_repository.dart';
import '../data/tu_chong_source.dart';
Expand Down Expand Up @@ -481,8 +482,7 @@ class _ChatDemo1State extends State<ChatDemo1> {
final TextSpan oldTextSpan =
_mySpecialTextSpanBuilder.build(_textEditingController.text);

final TextEditingValue value =
ExtendedTextLibraryUtils.handleSpecialTextSpanDelete(
final TextEditingValue value = handleSpecialTextSpanDelete(
_textEditingController.deleteText(),
_textEditingController.value,
oldTextSpan,
Expand Down Expand Up @@ -537,3 +537,53 @@ class Message {
final bool isMe;
final String content;
}

TextEditingValue handleSpecialTextSpanDelete(
TextEditingValue value,
TextEditingValue? oldValue,
InlineSpan oldTextSpan,
TextInputConnection? textInputConnection) {
final String? oldText = oldValue?.text;
String newText = value.text;

/// take care of image span
if (oldText != null && oldText.length > newText.length) {
final int difStart = value.selection.extentOffset;
//int difEnd = oldText.length - 1;
// for (; difStart < newText.length; difStart++) {
// if (oldText[difStart] != newText[difStart]) {
// break;
// }
// }

int caretOffset = value.selection.extentOffset;
if (difStart > 0) {
oldTextSpan.visitChildren((InlineSpan span) {
if (span is SpecialInlineSpanBase &&
(span as SpecialInlineSpanBase).deleteAll) {
final SpecialInlineSpanBase specialTs = span as SpecialInlineSpanBase;
if (difStart > specialTs.start && difStart < specialTs.end) {
//difStart = ts.start;
newText = newText.replaceRange(specialTs.start, difStart, '');
caretOffset -= difStart - specialTs.start;
return false;
}
}
return true;
});

if (newText != value.text) {
value = TextEditingValue(
text: newText,
selection: value.selection.copyWith(
baseOffset: caretOffset,
extentOffset: caretOffset,
affinity: value.selection.affinity,
isDirectional: value.selection.isDirectional));
textInputConnection?.setEditingState(value);
}
}
}

return value;
}
2 changes: 2 additions & 0 deletions lib/src/text_input/keyboard_binding.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:ui';

import 'package:extended_keyboard/extended_keyboard.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ topics:

environment:
sdk: ">=2.17.6 <4.0.0"
flutter: ">=1.17.0"
flutter: ">=3.0.0"

dependencies:
flutter:
Expand Down

0 comments on commit 75bf133

Please sign in to comment.