Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

fix: 重复按TAB键会触发onChanged事件,且value有值为"\t" #319

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
56 changes: 28 additions & 28 deletions com.unity.uiwidgets/Runtime/widgets/editable_text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public virtual TextSpan buildTextSpan(TextStyle style = null , bool withComposin
spans.Add(new TextSpan(text: value.composing.textAfter(value.text)));
return new TextSpan(
style: style,
children: spans
children: spans
);
}
public TextSelection selection {
Expand All @@ -82,13 +82,13 @@ public void clear() {
public void clearComposing() {
value = value.copyWith(composing: TextRange.empty);
}

public bool isSelectionWithinTextBounds(TextSelection selection) {
return selection.start <= text.Length && selection.end <= text.Length;
}
}
public class ToolbarOptions {

public ToolbarOptions(
bool copy = false,
bool cut = false,
Expand All @@ -103,11 +103,11 @@ public ToolbarOptions(
}
public readonly bool copy;
public readonly bool cut;
public readonly bool paste;
public readonly bool paste;
public readonly bool selectAll;
}


public class EditableText : StatefulWidget {
public EditableText(
Key key = null,
Expand Down Expand Up @@ -182,7 +182,7 @@ public EditableText(
"minLines and maxLines must be null when expands is true."
);
D.assert(!obscureText || maxLines == 1, () => "Obscured fields cannot be multiline.");

scrollPadding = scrollPadding ?? EdgeInsets.all(20.0f);
D.assert(scrollPadding != null);
toolbarOptions = toolbarOptions ?? new ToolbarOptions(
Expand All @@ -197,7 +197,7 @@ public EditableText(
if (maxLines == 1) {
this.inputFormatters.Add(BlacklistingTextInputFormatter.singleLineFormatter);
}

showCursor = showCursor ?? !readOnly;

this.readOnly = readOnly;
Expand Down Expand Up @@ -260,7 +260,7 @@ public EditableText(
this.keyboardAppearance = keyboardAppearance;
this.enableInteractiveSelection = enableInteractiveSelection;
this.dragStartBehavior = dragStartBehavior;
this.scrollPhysics = scrollPhysics;
this.scrollPhysics = scrollPhysics;
}

public readonly bool readOnly;
Expand Down Expand Up @@ -364,7 +364,7 @@ public override void debugFillProperties(DiagnosticPropertiesBuilder properties)

public class EditableTextState : AutomaticKeepAliveClientWithTickerProviderStateMixin<EditableText>,
WidgetsBindingObserver, TextInputClient,
TextSelectionDelegate
TextSelectionDelegate
{
const int _kObscureShowLatestCharCursorTicks = 3;
static TimeSpan _kCursorBlinkHalfPeriod = TimeSpan.FromMilliseconds(500);
Expand All @@ -383,10 +383,10 @@ public class EditableTextState : AutomaticKeepAliveClientWithTickerProviderState

public ScrollController _scrollController = new ScrollController();
AnimationController _cursorBlinkOpacityController;

bool _didAutoFocus = false;
FocusAttachment _focusAttachment;

TextEditingValue _lastFormattedUnmodifiedTextEditingValue;
TextEditingValue _lastFormattedValue;
TextEditingValue _receivedRemoteTextEditingValue;
Expand Down Expand Up @@ -655,15 +655,15 @@ void _updateRemoteEditingValueIfNeeded() {
if (localValue == _receivedRemoteTextEditingValue) {
return;
}

_textInputConnection.setEditingState(localValue);
}

TextEditingValue _value {
get { return widget.controller.value; }
set { widget.controller.value = value; }
}


bool _hasFocus {
get { return widget.focusNode.hasFocus; }
Expand Down Expand Up @@ -761,7 +761,7 @@ void _updateSizeAndTransform() {
.addPostFrameCallback((TimeSpan _) => _updateSizeAndTransform());
}
}

void _closeInputConnectionIfNeeded() {
if (_hasInputConnection) {
_textInputConnection.close();
Expand Down Expand Up @@ -945,32 +945,32 @@ public void didChangeAccessibilityFeatures() {}
void _formatAndSetValue(TextEditingValue value, bool isIMEInput = false) {
//whitespaceFormatter ??= new _WhitespaceDirectionalityFormatter(textDirection: _textDirection);

bool textChanged = _value?.text != value?.text;
bool isRepeatText = value?.text == _lastFormattedUnmodifiedTextEditingValue?.text;
bool isRepeatSelection = value?.selection == _lastFormattedUnmodifiedTextEditingValue?.selection;
bool isRepeatSelection = value?.selection == _lastFormattedUnmodifiedTextEditingValue?.selection;
bool isRepeatComposing = value?.composing == _lastFormattedUnmodifiedTextEditingValue?.composing;
if (!isRepeatText && textChanged && widget.inputFormatters != null && widget.inputFormatters.isNotEmpty()) {

if (!isRepeatText && widget.inputFormatters != null && widget.inputFormatters.isNotEmpty()) {
foreach (TextInputFormatter formatter in widget.inputFormatters) {
value = formatter.formatEditUpdate(_value, value);
}
//value = _whitespaceFormatter.formatEditUpdate(_value, value);
_lastFormattedValue = value;
}

_value = value;

if (isRepeatText && isRepeatSelection && isRepeatComposing && textChanged && _lastFormattedValue != null) {
_value = _lastFormattedValue;
if (isRepeatText && isRepeatSelection && isRepeatComposing && _lastFormattedValue != null) {
value = _lastFormattedValue;
}


bool textChanged = _value?.text != value?.text;
_value = value;


_updateRemoteEditingValueIfNeeded();

if (textChanged && widget.onChanged != null)
widget.onChanged(value.text);
_lastFormattedUnmodifiedTextEditingValue = _receivedRemoteTextEditingValue;

}

void _onCursorColorTick() {
Expand Down Expand Up @@ -1242,14 +1242,14 @@ public TextSpan buildTextSpan() {
}
return new TextSpan(style: widget.style, text: text);
}

return widget.controller.buildTextSpan(
style: widget.style,
withComposing: !widget.readOnly
);
}


bool _unityKeyboard() {
return TouchScreenKeyboard.isSupported && widget.unityTouchKeyboard;
}
Expand Down Expand Up @@ -1284,9 +1284,9 @@ void _updateImePosIfNeed() {
_textInputConnection.setIMEPos(_getImePos());
});
}

}


class _Editable : LeafRenderObjectWidget {
public readonly TextSpan textSpan;
Expand Down