浏览代码

refine text edit

/main
fzhangtj 6 年前
当前提交
433ebb1c
共有 9 个文件被更改,包括 440 次插入172 次删除
  1. 14
      Assets/UIWidgets/Tests/EditableTextWiget.cs
  2. 44
      Assets/UIWidgets/painting/text_painter.cs
  3. 2
      Assets/UIWidgets/painting/text_span.cs
  4. 111
      Assets/UIWidgets/rendering/editable.cs
  5. 16
      Assets/UIWidgets/service/text_editing.cs
  6. 2
      Assets/UIWidgets/service/text_input.cs
  7. 16
      Assets/UIWidgets/ui/text.cs
  8. 33
      Assets/UIWidgets/ui/txt/paragraph.cs
  9. 374
      Assets/UIWidgets/widgets/editable_text.cs

14
Assets/UIWidgets/Tests/EditableTextWiget.cs


public static void renderWidgets() {
EditorWindow.GetWindow(typeof(EditableTextWiget));
}
private string txt = "Hello\n" +
"This is useful when you need to check if a certain key has been pressed - possibly with modifiers. The syntax for the key string\n" +
"asfsd \n" +
"P1:\n" +
"This is useful when you need to check if a certain key has been pressed - possibly with modifiers.The syntax for the key st\n" +
"\n" +
"\n" +
"\n" +
"\n" +
" sfsafd";
EditableTextWiget() {
}

color: ui.Color.fromARGB(255, 244, 190, 85),
child: new EditableText(
maxLines: 100,
controller: new TextEditingController("click to edit"),
controller: new TextEditingController(txt),
focusNode: new FocusNode(),
style: new TextStyle(),
selectionColor: Color.fromARGB(255, 255, 0, 0),

44
Assets/UIWidgets/painting/text_painter.cs


{
D.assert(!_needsLayout);
var offset = position.offset;
if (offset > 0)
{
var prevCodeUnit = _text.codeUnitAt(offset);
if (prevCodeUnit == null) // out of upper bounds
{
var rectNextLine = _paragraph.getNextLineStartRect();
if (rectNextLine != null)
{
return new Offset(rectNextLine.start, rectNextLine.top);
}
}
}
switch (position.affinity)
{
case TextAffinity.upstream:

return null;
}
public Paragraph.LineRange getLineRange(int lineNumber)
{
D.assert(!_needsLayout);
return _paragraph.getLineRange(lineNumber);
}
public Paragraph.LineRange getLineRange(TextPosition textPosition)
{
return getLineRange(getLineIndex(textPosition));
}
public List<TextBox> getBoxesForSelection(TextSelection selection)
{

{
D.assert(!_needsLayout);
var offset = getOffsetForCaret(position, Rect.zero);
var line = _paragraph.getLine(position);
var targetLineStart = _paragraph.getLineStart(line + move);
var newLineOffset = getOffsetForCaret(targetLineStart, Rect.zero);
var lineIndex = Math.Min(Math.Max(_paragraph.getLine(position) + move, 0), _paragraph.getLineCount());
var targetLineStart = _paragraph.getLineRange(lineIndex).start;
var newLineOffset = getOffsetForCaret(new TextPosition(targetLineStart), Rect.zero);
return getPositionForOffset(new Offset(offset.dx, newLineOffset.dy));
}

return _paragraph.getLine(position);
}
public TextPosition getLineStartPosition(int line)
{
D.assert(!_needsLayout);
return _paragraph.getLineStart(line);
}
public TextPosition getLineEndPosition(int line)
public int getLineCount()
return _paragraph.getLineEnd(line);
return _paragraph.getLineCount();
}
public TextPosition getWordRight(TextPosition position)

offset = range.end;
}
return new TextPosition(offset);
return new TextPosition(offset, position.affinity);
}
public TextPosition getWordLeft(TextPosition position)

}
}
return new TextPosition(offset);
return new TextPosition(offset, position.affinity);
}
private ParagraphStyle _createParagraphStyle(TextDirection defaultTextDirection = TextDirection.ltr)

2
Assets/UIWidgets/painting/text_span.cs


}
var offset = 0;
var result = -1;
int? result = null;
visitTextSpan(span =>
{
if (index - offset < span.text.Length)

111
Assets/UIWidgets/rendering/editable.cs


return _textPainter.getPositionVerticalMove(position, -1);
}
public TextPosition getLineStartPosition(TextPosition position)
public TextPosition getLineStartPosition(TextPosition position, TextAffinity? affinity = null)
return _textPainter.getLineStartPosition(_textPainter.getLineIndex(position));
var line = _textPainter.getLineRange(position);
return new TextPosition(offset:line.start, affinity:affinity??position.affinity);
}
public bool isLineEndOrStart(int offset)
{
int lineCount = _textPainter.getLineCount();
for (int i = 0; i < lineCount; i++)
{
var line = _textPainter.getLineRange(i);
if (line.start == offset || line.endIncludingNewLine == offset)
{
return true;
}
}
return false;
public TextPosition getLineEndPosition(TextPosition position)
public TextPosition getLineEndPosition(TextPosition position, TextAffinity? affinity = null)
return _textPainter.getLineEndPosition(_textPainter.getLineIndex(position));
var line = _textPainter.getLineRange(position);
return new TextPosition(offset:line.endIncludingNewLine, affinity:affinity??position.affinity);
}
public TextPosition getWordRight(TextPosition position)

return _textPainter.getWordLeft(position);
}
public TextPosition getParagraphStart(TextPosition position, TextAffinity? affinity = null)
{
D.assert(!_needsLayout);
int lineIndex = _textPainter.getLineIndex(position);
while (lineIndex - 1 >= 0)
{
var preLine = _textPainter.getLineRange(lineIndex - 1);
if (preLine.hardBreak)
{
break;
}
lineIndex--;
}
var line = _textPainter.getLineRange(lineIndex);
return new TextPosition(offset:line.start, affinity:affinity??position.affinity);
}
public TextPosition getParagraphEnd(TextPosition position, TextAffinity? affinity = null)
{
D.assert(!_needsLayout);
int lineIndex = _textPainter.getLineIndex(position);
int maxLine = _textPainter.getLineCount();
while (lineIndex < maxLine)
{
var line = _textPainter.getLineRange(lineIndex);
if (line.hardBreak)
{
break;
}
lineIndex++;
}
return new TextPosition(offset:_textPainter.getLineRange(lineIndex).endIncludingNewLine,
affinity:affinity??position.affinity);
}
public TextPosition getParagraphForward(TextPosition position, TextAffinity? affinity = null)
{
var lineCount = _textPainter.getLineCount();
Paragraph.LineRange line = null;
for (int i = 0; i < lineCount; ++i)
{
line = _textPainter.getLineRange(i);
if (!line.hardBreak)
{
continue;
}
if (line.end > position.offset)
{
break;
}
}
if (line == null)
{
return new TextPosition(position.offset, affinity??position.affinity);
}
return new TextPosition(line.end, affinity??position.affinity);
}
public TextPosition getParagraphBackward(TextPosition position, TextAffinity? affinity = null)
{
var lineCount = _textPainter.getLineCount();
Paragraph.LineRange line = null;
for (int i = lineCount - 1; i >= 0; --i)
{
line = _textPainter.getLineRange(i);
if (i != 0 && !_textPainter.getLineRange(i - 1).hardBreak)
{
continue;
}
if (line.start < position.offset)
{
break;
}
}
if (line == null)
{
return new TextPosition(position.offset, affinity??position.affinity);
}
return new TextPosition(line.start, affinity??position.affinity);
}
protected override double computeMinIntrinsicWidth(double height) {
_layoutText(double.PositiveInfinity);
return _textPainter.minIntrinsicWidth;

16
Assets/UIWidgets/service/text_editing.cs


}
}
public TextPosition startPos
{
get
{
return new TextPosition(offset: start, affinity: affinity);
}
}
public TextPosition endPos
{
get
{
return new TextPosition(offset: end, affinity: affinity);
}
}
public bool Equals(TextSelection other)
{
if (ReferenceEquals(null, other)) return false;

2
Assets/UIWidgets/service/text_input.cs


int offset = selection.baseOffset + move;
offset = Math.Max(0, offset);
offset = Math.Min(offset, text.Length);
return this.copyWith(selection: TextSelection.collapsed(offset));
return this.copyWith(selection: TextSelection.collapsed(offset, affinity: selection.affinity));
}
public TextEditingValue compose(string composeText)

16
Assets/UIWidgets/ui/text.cs


w700, // bold
}
public class TextPosition
public class TextPosition: IEquatable<TextPosition>
{
public readonly int offset;
public readonly TextAffinity affinity;

return string.Format("Offset: {0}, Affinity: {1}", offset, affinity);
}
protected bool Equals(TextPosition other)
public bool Equals(TextPosition other)
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return offset == other.offset && affinity == other.affinity;
}

{
return (offset * 397) ^ (int) affinity;
}
}
public static bool operator ==(TextPosition left, TextPosition right)
{
return Equals(left, right);
}
public static bool operator !=(TextPosition left, TextPosition right)
{
return !Equals(left, right);
}
}

33
Assets/UIWidgets/ui/txt/paragraph.cs


}
class LineRange
public class LineRange
{
public LineRange(int start, int end, int endExcludingWhitespace, int endIncludingNewLine, bool hardBreak)
{

return result;
}
public TextBox getNextLineStartRect()
{
if (_text.Length == 0 || _text[_text.Length - 1] != '\n')
{
return null;
}
var lineNumber = getLineCount() - 1;
var top = (lineNumber > 0) ? _lineHeights[lineNumber - 1] : 0;
var bottom = _lineHeights[lineNumber];
return TextBox.fromLTBD(0, top, 0, bottom, TextDirection.ltr);
}
public PositionWithAffinity getGlyphPositionAtCoordinate(double dx, double dy)
{
if (_lineHeights.Count == 0)

for (int lineIndex = 0; lineIndex < getLineCount(); ++lineIndex)
{
var line = _lineRanges[lineIndex];
if (offset >= line.start && offset <= line.end)
if ((offset >= line.start && offset < line.endIncludingNewLine))
{
return lineIndex;
}

}
public TextPosition getLineStart(int lineIndex)
public LineRange getLineRange(int lineIndex)
lineIndex = Math.Min(getLineCount() - 1, Math.Max(lineIndex, 0));
return new TextPosition(_lineRanges[lineIndex].start);
}
public TextPosition getLineEnd(int lineIndex)
{
lineIndex = Math.Min(getLineCount() - 1, Math.Max(lineIndex, 0));
return new TextPosition(_lineRanges[lineIndex].end);
return _lineRanges[lineIndex];
}
public IndexRange getWordBoundary(int offset)

var blockSize = blockEnd - blockStart;
if (blockSize == 0)
{
_lineRanges.Add(new LineRange(blockStart, blockEnd, blockEnd, blockEnd + 1, true));
_lineRanges.Add(new LineRange(blockStart, blockEnd, blockEnd,
blockEnd < _text.Length ? blockEnd + 1: blockEnd, true));
_lineWidths.Add(0);
continue;
}

nonSpaceEnd--;
}
_lineRanges.Add(new LineRange(line.start, end, nonSpaceEnd, end + 1, end == blockEnd));
_lineRanges.Add(new LineRange(line.start, end, nonSpaceEnd,
end == blockEnd && end < _text.Length ? end + 1 : end, end == blockEnd));
_lineWidths.Add(line.width);
}
}

374
Assets/UIWidgets/widgets/editable_text.cs


{
return new EditableTextState();
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
public override void debugFillProperties(DiagnosticPropertiesBuilder properties)
{
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<TextEditingController>("controller", controller));
properties.add(new DiagnosticsProperty<FocusNode>("focusNode", focusNode));

{
style.debugFillProperties(properties);
}
properties.add(new EnumProperty<TextAlign>("textAlign", textAlign, defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new EnumProperty<TextDirection?>("textDirection", textDirection, defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new DiagnosticsProperty<double>("textScaleFactor", textScaleFactor, defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new EnumProperty<TextAlign>("textAlign", textAlign,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new EnumProperty<TextDirection?>("textDirection", textDirection,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new DiagnosticsProperty<double>("textScaleFactor", textScaleFactor,
defaultValue: Diagnostics.kNullDefaultValue));
public class EditableTextState: State<EditableText>, TextInputClient
public class EditableTextState : State<EditableText>, TextInputClient
public override void initState()
{
base.initState();

widget.controller.addListener(_didChangeTextEditingValue);
_updateRemoteEditingValueIfNeeded();
}
if (widget.focusNode != oldWidget.focusNode) {
if (widget.focusNode != oldWidget.focusNode)
{
oldWidget.focusNode.removeListener(_handleFocusChanged);
widget.focusNode.addListener(_handleFocusChanged);
}

widget.focusNode.removeListener(_handleFocusChanged);
base.dispose();
}
public void updateEditingValue(TextEditingValue value) {
if (value.text != _value.text) {
public void updateEditingValue(TextEditingValue value)
{
if (value.text != _value.text)
{
if (widget.obscureText && value.text.Length == _value.text.Length + 1) {
if (widget.obscureText && value.text.Length == _value.text.Length + 1)
{
_obscureShowCharTicksPending = _kObscureShowLatestCharCursorTicks;
_obscureLatestCharIndex = _value.selection.baseOffset;
}

public TextEditingValue getValueForOperation(TextEditOp operation)
{
Debug.Log(string.Format("operation {0}", operation));
TextPosition newExtend = null;
TextEditingValue newValue = null;
TextSelection newSelection = null;
TextPosition startPos = new TextPosition(_value.selection.start, _value.selection.affinity);
case TextEditOp.MoveLeft:
return _value.moveLeft();
case TextEditOp.MoveLeft:
newValue = _value.moveLeft();
break;
return _value.moveRight();
case TextEditOp.MoveUp:
newPosition = this.renderEditable.getPositionUp(new TextPosition(_value.selection.start, _value.selection.affinity));
return _value.copyWith(selection: TextSelection.fromPosition(newPosition));
case TextEditOp.MoveDown:
newPosition = this.renderEditable.getPositionDown(new TextPosition(_value.selection.start, _value.selection.affinity));
return _value.copyWith(selection: TextSelection.fromPosition(newPosition));
case TextEditOp.MoveLineStart:
newPosition = this.renderEditable.getLineStartPosition(new TextPosition(_value.selection.start, _value.selection.affinity));
return _value.copyWith(selection: TextSelection.fromPosition(newPosition));
case TextEditOp.MoveLineEnd:
newPosition = this.renderEditable.getLineEndPosition(new TextPosition(_value.selection.start, _value.selection.affinity));
return _value.copyWith(selection: TextSelection.fromPosition(newPosition));
case TextEditOp.MoveWordRight:
newPosition = this.renderEditable.getWordRight(new TextPosition(_value.selection.start));
return _value.copyWith(selection: TextSelection.fromPosition(newPosition));
case TextEditOp.MoveWordLeft:
newPosition = this.renderEditable.getWordLeft(new TextPosition(_value.selection.start));
return _value.copyWith(selection: TextSelection.fromPosition(newPosition));
newValue = _value.moveRight();
break;
case TextEditOp.MoveUp:
newPosition = this.renderEditable.getPositionUp(startPos);
break;
case TextEditOp.MoveDown:
newPosition = this.renderEditable.getPositionDown(startPos);
break;
case TextEditOp.MoveLineStart:
newPosition = this.renderEditable.getParagraphStart(startPos, TextAffinity.downstream);
break;
case TextEditOp.MoveLineEnd:
newPosition = this.renderEditable.getParagraphEnd(startPos, TextAffinity.upstream);
break;
case TextEditOp.MoveWordRight:
newPosition = this.renderEditable.getWordRight(startPos);
break;
case TextEditOp.MoveWordLeft:
newPosition = this.renderEditable.getWordLeft(startPos);
break;
return _value.copyWith(selection: TextSelection.collapsed(0));
case TextEditOp.MoveTextEnd:
return _value.copyWith(selection: TextSelection.collapsed(_value.text.Length));
// case TextEditOp.MoveParagraphForward: MoveParagraphForward(); break;
// case TextEditOp.MoveParagraphBackward: MoveParagraphBackward(); break;
// case TextEditOp.MoveGraphicalLineStart: MoveGraphicalLineStart(); break;
// case TextEditOp.MoveGraphicalLineEnd: MoveGraphicalLineEnd(); break;
case TextEditOp.SelectLeft:
return _value.extendLeft();
case TextEditOp.SelectRight:
return _value.extendRight();
case TextEditOp.SelectUp:
newPosition = this.renderEditable.getPositionUp(_value.selection.extendPos);
return _value.copyWith(selection: _value.selection.copyWith(extentOffset: newPosition.offset));
case TextEditOp.SelectDown:
newPosition = this.renderEditable.getPositionDown(_value.selection.extendPos);
return _value.copyWith(selection: _value.selection.copyWith(extentOffset: newPosition.offset));
case TextEditOp.SelectWordRight:
newPosition = this.renderEditable.getWordRight(_value.selection.extendPos);
return _value.copyWith(selection: _value.selection.copyWith(extentOffset: newPosition.offset));
case TextEditOp.SelectWordLeft:
newPosition = this.renderEditable.getWordLeft(_value.selection.extendPos);
return _value.copyWith(selection: _value.selection.copyWith(extentOffset: newPosition.offset));
newPosition = new TextPosition(0);
break;
case TextEditOp.MoveTextEnd:
newPosition = new TextPosition(_value.text.Length);
break;
case TextEditOp.MoveParagraphForward:
newPosition = this.renderEditable.getParagraphForward(startPos);
break;
case TextEditOp.MoveParagraphBackward:
newPosition = this.renderEditable.getParagraphBackward(startPos);
break;
case TextEditOp.MoveGraphicalLineStart:
newPosition = this.renderEditable.getLineStartPosition(startPos, TextAffinity.downstream);
break;
case TextEditOp.MoveGraphicalLineEnd:
newPosition = this.renderEditable.getLineEndPosition(startPos, TextAffinity.upstream);
break;
case TextEditOp.SelectLeft:
newValue = _value.extendLeft();
break;
case TextEditOp.SelectRight:
newValue = _value.extendRight();
break;
case TextEditOp.SelectUp:
newExtend = this.renderEditable.getPositionUp(_value.selection.extendPos);
break;
case TextEditOp.SelectDown:
newExtend = this.renderEditable.getPositionDown(_value.selection.extendPos);
break;
case TextEditOp.SelectWordRight:
newExtend = this.renderEditable.getWordRight(_value.selection.extendPos);
break;
case TextEditOp.SelectWordLeft:
newExtend = this.renderEditable.getWordLeft(_value.selection.extendPos);
break;
case TextEditOp.SelectTextStart:
return _value.copyWith(selection: _value.selection.copyWith(extentOffset: 0));
case TextEditOp.SelectTextEnd:
return _value.copyWith(selection: _value.selection.copyWith(extentOffset: _value.text.Length));
// case TextEditOp.ExpandSelectGraphicalLineStart: ExpandSelectGraphicalLineStart(); break;
// case TextEditOp.ExpandSelectGraphicalLineEnd: ExpandSelectGraphicalLineEnd(); break;
// case TextEditOp.SelectParagraphForward: SelectParagraphForward(); break;
// case TextEditOp.SelectParagraphBackward: SelectParagraphBackward(); break;
// case TextEditOp.SelectGraphicalLineStart: SelectGraphicalLineStart(); break;
// case TextEditOp.SelectGraphicalLineEnd: SelectGraphicalLineEnd(); break;
case TextEditOp.Delete: return _value.deleteSelection(false);
case TextEditOp.SelectTextStart:
newExtend = new TextPosition(0);
break;
case TextEditOp.SelectTextEnd:
newExtend = new TextPosition(_value.text.Length);
break;
case TextEditOp.ExpandSelectGraphicalLineStart:
if (_value.selection.isCollapsed || !this.renderEditable.isLineEndOrStart(_value.selection.start))
{
newSelection = new TextSelection(this.renderEditable.getLineStartPosition(startPos).offset,
_value.selection.end, _value.selection.affinity);
}
break;
case TextEditOp.ExpandSelectGraphicalLineEnd:
if (_value.selection.isCollapsed || !this.renderEditable.isLineEndOrStart(_value.selection.end))
{
newSelection = new TextSelection(_value.selection.start,
this.renderEditable.getLineEndPosition(_value.selection.endPos).offset,
_value.selection.affinity);
}
break;
case TextEditOp.SelectParagraphForward:
newExtend = this.renderEditable.getParagraphForward(_value.selection.extendPos);
break;
case TextEditOp.SelectParagraphBackward:
newExtend = this.renderEditable.getParagraphBackward(_value.selection.extendPos);
break;
case TextEditOp.SelectGraphicalLineStart:
newExtend = this.renderEditable.getLineStartPosition(_value.selection.extendPos);
break;
case TextEditOp.SelectGraphicalLineEnd:
newExtend = this.renderEditable.getLineEndPosition(startPos);
break;
case TextEditOp.Delete:
newValue = _value.deleteSelection(false);
break;
return _value.deleteSelection();
newValue = _value.deleteSelection();
break;
case TextEditOp.SelectAll:
newSelection = _value.selection.copyWith(baseOffset: 0, extentOffset: _value.text.Length);
break;
}
if (newPosition != null)
{
return _value.copyWith(selection: TextSelection.fromPosition(newPosition));
}
else if (newExtend != null)
{
return _value.copyWith(selection: _value.selection.copyWith(extentOffset: newExtend.offset));
} else if (newSelection != null)
{
return _value.copyWith(selection: newSelection);
}
else if (newValue != null)
{
return newValue;
}
return _value;

bool _hasInputConnection
{
get
{
return _textInputConnection != null && _textInputConnection.attached;
}
get { return _textInputConnection != null && _textInputConnection.attached; }
void _openInputConnection() {
if (!_hasInputConnection) {
void _openInputConnection()
{
if (!_hasInputConnection)
{
TextEditingValue localValue = _value;
_lastKnownRemoteTextEditingValue = localValue;
_textInputConnection = Window.instance.textInput.attach(this);

void _closeInputConnectionIfNeeded() {
if (_hasInputConnection) {
void _closeInputConnectionIfNeeded()
{
if (_hasInputConnection)
{
_textInputConnection.close();
_textInputConnection = null;
_lastKnownRemoteTextEditingValue = null;

void _openOrCloseInputConnectionIfNeeded() {
if (_hasFocus && widget.focusNode.consumeKeyboardToken()) {
void _openOrCloseInputConnectionIfNeeded()
{
if (_hasFocus && widget.focusNode.consumeKeyboardToken())
{
} else if (!_hasFocus) {
}
else if (!_hasFocus)
{
_closeInputConnectionIfNeeded();
widget.controller.clearComposing();
}

FocusScope.of(context).requestFocus(widget.focusNode);
}
}
private void _handleSelectionChanged(TextSelection selection, RenderEditable renderObject, SelectionChangedCause cause) {
private void _handleSelectionChanged(TextSelection selection, RenderEditable renderObject,
SelectionChangedCause cause)
{
if (widget.onSelectionChanged != null)
{
widget.onSelectionChanged(selection, cause);

void _handleCaretChanged(Rect caretRect) {
if (_textChangedSinceLastCaretUpdate) {
_textChangedSinceLastCaretUpdate = false;
void _handleCaretChanged(Rect caretRect)
{
if (_textChangedSinceLastCaretUpdate)
{
_textChangedSinceLastCaretUpdate = false;
// scheduleMicrotask(() { // todo
// _scrollController.animateTo(
// _getScrollOffsetForCaret(caretRect),

// });
}
}
private void _formatAndSetValue(TextEditingValue value) {
private void _formatAndSetValue(TextEditingValue value)
{
if (widget.inputFormatters != null && widget.inputFormatters.isNotEmpty()) {
if (widget.inputFormatters != null && widget.inputFormatters.isNotEmpty())
{
} else {
}
else
{
widget.onChanged(value.text);
widget.onChanged(value.text);
set
{
widget.controller.value = value;
}
set { widget.controller.value = value; }
}
private bool _hasFocus

private bool _isMultiline
{
get { return widget.maxLines != 1; }
get { return widget.maxLines != 1; }
}
private void _didChangeTextEditingValue()

setState(() => {});
setState(() => { });
if (!_hasFocus) {
if (!_hasFocus)
{
} else if (!_value.selection.isValid) {
}
else if (!_value.selection.isValid)
{
widget.controller.selection = TextSelection.collapsed(offset: _value.text.Length);
}
}

get
{
TextDirection? result = widget.textDirection ?? Directionality.of(context);
D.assert(result != null,
string.Format("{0} created without a textDirection and with no ambient Directionality.", GetType().FullName));
D.assert(result != null,
string.Format("{0} created without a textDirection and with no ambient Directionality.",
GetType().FullName));
return result;
}
}

get { return (RenderEditable)_editableKey.currentContext.findRenderObject(); }
get { return (RenderEditable) _editableKey.currentContext.findRenderObject(); }
public override Widget build(BuildContext context)
public override Widget build(BuildContext context)
{
FocusScope.of(context).reparentIfNeeded(widget.focusNode);
// todo base.build(context); See AutomaticKeepAliveClientMixin.

onSelectionChanged: _handleSelectionChanged,
onCaretChanged: _handleCaretChanged,
rendererIgnoresPointer: widget.rendererIgnoresPointer
);
);
public TextSpan buildTextSpan() {
if (!widget.obscureText && _value.composing.isValid) {
public TextSpan buildTextSpan()
{
if (!widget.obscureText && _value.composing.isValid)
{
new TextStyle(decoration: TextDecoration.underline)
);
new TextStyle(decoration: TextDecoration.underline)
);
return new TextSpan(
style: widget.style,

}
var text = _value.text;
if (widget.obscureText) {
if (widget.obscureText)
{
text = new string(RenderEditable.obscuringCharacter, text.Length);
int o =
_obscureShowCharTicksPending > 0 ? _obscureLatestCharIndex : -1;

internal class _Editable : LeafRenderObjectWidget
{
public readonly TextSpan textSpan;

bool autocorrect = false, ViewportOffset offset = null, SelectionChangedHandler onSelectionChanged = null,
CaretChangedHandler onCaretChanged = null, bool rendererIgnoresPointer = false, Key key = null) : base(key)
{
this.textSpan = textSpan;
this.value = value;
this.cursorColor = cursorColor;

{
return new RenderEditable(
text: textSpan,
textDirection: textDirection??TextDirection.ltr,
textDirection: textDirection ?? TextDirection.ltr,
offset: offset,
showCursor: showCursor,
cursorColor: cursorColor,

textScaleFactor: textScaleFactor,
textAlign: textAlign,
selection: value.selection,
selection: value.selection,
ignorePointer: rendererIgnoresPointer
);
}
ignorePointer: rendererIgnoresPointer
);
}
public override void updateRenderObject(BuildContext context, RenderObject renderObject)
{

edit.onSelectionChanged = onSelectionChanged;
edit.onCaretChanged = onCaretChanged;
edit.ignorePointer = rendererIgnoresPointer;
edit.obscureText = obscureText;
edit.obscureText = obscureText;
class _FixedViewportOffset : ViewportOffset {
internal _FixedViewportOffset(double _pixels) {
class _FixedViewportOffset : ViewportOffset
{
internal _FixedViewportOffset(double _pixels)
{
internal new static _FixedViewportOffset zero() {
internal new static _FixedViewportOffset zero()
{
public override double pixels {
public override double pixels
{
public override bool applyViewportDimension(double viewportDimension) {
public override bool applyViewportDimension(double viewportDimension)
{
public override bool applyContentDimensions(double minScrollExtent, double maxScrollExtent) {
public override bool applyContentDimensions(double minScrollExtent, double maxScrollExtent)
{
public override void correctBy(double correction) {
public override void correctBy(double correction)
{
public override void jumpTo(double pixels) {
public override void jumpTo(double pixels)
{
public override IPromise animateTo(double to, TimeSpan duration, Curve curve) {
public override IPromise animateTo(double to, TimeSpan duration, Curve curve)
{
public override ScrollDirection userScrollDirection {
public override ScrollDirection userScrollDirection
{
public override bool allowImplicitScrolling {
public override bool allowImplicitScrolling
{
get { return false; }
}
}
正在加载...
取消
保存