mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
fix richtextfield
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -183,7 +183,7 @@ class RichTextItem {
|
||||
if (insertionOffset == 0 && range.start == 0) {
|
||||
final insertedLength = delta.textInserted.length;
|
||||
controller.newSelection = TextSelection.collapsed(offset: insertedLength);
|
||||
if (isText && delta.isText) {
|
||||
if (!isRich && delta.isText) {
|
||||
text = delta.textInserted + text;
|
||||
range = TextRange(start: range.start, end: range.start + text.length);
|
||||
return null;
|
||||
@@ -232,7 +232,7 @@ class RichTextItem {
|
||||
return [insertedItem];
|
||||
}
|
||||
|
||||
if (isText &&
|
||||
if (!isRich &&
|
||||
range.start < insertionOffset &&
|
||||
range.end > insertionOffset) {
|
||||
final leadingText = text.substring(0, insertionOffset - range.start);
|
||||
@@ -375,7 +375,7 @@ class RichTextItem {
|
||||
}
|
||||
|
||||
if (range.start < replacedRange.start && range.end > replacedRange.end) {
|
||||
if (isText) {
|
||||
if (!isRich) {
|
||||
if (delta.isText) {
|
||||
text = text.replaceRange(
|
||||
replacedRange.start - range.start,
|
||||
@@ -451,7 +451,7 @@ class RichTextItem {
|
||||
}
|
||||
|
||||
if (range.start < replacedRange.start && range.end <= replacedRange.end) {
|
||||
if (isText) {
|
||||
if (!isRich) {
|
||||
if (delta.isText) {
|
||||
text = text.replaceRange(
|
||||
text.length - (range.end - replacedRange.start),
|
||||
@@ -496,7 +496,7 @@ class RichTextItem {
|
||||
|
||||
if (range.start >= replacedRange.start && range.end > replacedRange.end) {
|
||||
if (range.start > replacedRange.start) {
|
||||
if (isText) {
|
||||
if (!isRich) {
|
||||
text = text.substring(replacedRange.end - range.start);
|
||||
final start = replacedRange.start + delta.replacementText.length;
|
||||
range = TextRange(start: start, end: start + text.length);
|
||||
@@ -504,7 +504,7 @@ class RichTextItem {
|
||||
}
|
||||
return (remove: true, toAdd: null);
|
||||
}
|
||||
if (isText) {
|
||||
if (!isRich) {
|
||||
if (delta.isText) {
|
||||
text = text.replaceRange(
|
||||
0,
|
||||
@@ -551,7 +551,7 @@ class RichTextItem {
|
||||
return '\ntype: [${type.name}],'
|
||||
'text: [$text],'
|
||||
'rawText: [$_rawText],'
|
||||
'\nrange: [$range]\n';
|
||||
'\nrange: [TextRange(start: ${range.start}, end: ${range.end})]\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,10 +602,6 @@ class RichTextEditingController extends TextEditingController {
|
||||
}
|
||||
|
||||
void syncRichText(TextEditingDelta delta) {
|
||||
if (text.isEmpty) {
|
||||
items.clear();
|
||||
}
|
||||
|
||||
int? addIndex;
|
||||
List<RichTextItem>? toAdd;
|
||||
|
||||
@@ -617,6 +613,7 @@ class RichTextEditingController extends TextEditingController {
|
||||
if (e.textInserted == '@') {
|
||||
onMention?.call();
|
||||
}
|
||||
|
||||
if (items.isEmpty) {
|
||||
final config = delta.config;
|
||||
items.add(
|
||||
@@ -724,7 +721,19 @@ class RichTextEditingController extends TextEditingController {
|
||||
// return TextSpan(style: style, text: text);
|
||||
// }
|
||||
|
||||
// debugPrint('$items,,\n$selection');
|
||||
// bool isValid = true;
|
||||
// int cursor = 0;
|
||||
// for (var e in items) {
|
||||
// final range = e.range;
|
||||
// if (range.start == cursor) {
|
||||
// cursor = range.end;
|
||||
// } else {
|
||||
// isValid = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// debugPrint('isValid: $isValid');
|
||||
// debugPrint('$items\n$selection');
|
||||
|
||||
return TextSpan(
|
||||
style: style,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
library;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io' show Platform;
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' as ui hide TextStyle;
|
||||
import 'dart:ui';
|
||||
@@ -3171,7 +3172,8 @@ class EditableTextState extends State<EditableText>
|
||||
TextEditingValue get currentTextEditingValue => _value;
|
||||
|
||||
@override
|
||||
void updateEditingValue(TextEditingValue value) {
|
||||
void updateEditingValue(TextEditingValue value,
|
||||
{TextEditingValue? remoteValue}) {
|
||||
// This method handles text editing state updates from the platform text
|
||||
// input plugin. The [EditableText] may not have the focus or an open input
|
||||
// connection, as autofill can update a disconnected [EditableText].
|
||||
@@ -3194,9 +3196,12 @@ class EditableTextState extends State<EditableText>
|
||||
// everything else.
|
||||
value = _value.copyWith(selection: value.selection);
|
||||
}
|
||||
_lastKnownRemoteTextEditingValue = _value;
|
||||
_lastKnownRemoteTextEditingValue = remoteValue ?? value;
|
||||
|
||||
if (value == _value) {
|
||||
if (remoteValue != null && Platform.isIOS) {
|
||||
_updateRemoteEditingValueIfNeeded();
|
||||
}
|
||||
// This is possible, for example, when the numeric keyboard is input,
|
||||
// the engine will notify twice for the same value.
|
||||
// Track at https://github.com/flutter/flutter/issues/65811
|
||||
@@ -3288,8 +3293,10 @@ class EditableTextState extends State<EditableText>
|
||||
|
||||
@override
|
||||
void updateEditingValueWithDeltas(List<TextEditingDelta> textEditingDeltas) {
|
||||
TextEditingValue remoteValue = _value;
|
||||
for (final TextEditingDelta delta in textEditingDeltas) {
|
||||
widget.controller.syncRichText(delta);
|
||||
remoteValue = delta.apply(remoteValue);
|
||||
}
|
||||
|
||||
final newValue = _value.copyWith(
|
||||
@@ -3298,7 +3305,7 @@ class EditableTextState extends State<EditableText>
|
||||
composing: textEditingDeltas.lastOrNull?.composing,
|
||||
);
|
||||
|
||||
updateEditingValue(newValue);
|
||||
updateEditingValue(newValue, remoteValue: remoteValue);
|
||||
|
||||
// TextEditingValue value = _value;
|
||||
// for (final TextEditingDelta delta in textEditingDeltas) {
|
||||
|
||||
@@ -31,8 +31,6 @@ abstract class CommonRichTextPubPage
|
||||
|
||||
abstract class CommonRichTextPubPageState<T extends CommonRichTextPubPage>
|
||||
extends CommonPublishPageState<T> {
|
||||
bool? hasPub;
|
||||
|
||||
@override
|
||||
late final RichTextEditingController editController =
|
||||
RichTextEditingController(
|
||||
|
||||
@@ -198,4 +198,7 @@ class _ReplyPageState extends CommonRichTextPubPageState<LiveSendDmPanel> {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onMention([bool fromClick = false]) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user