Small simplification in RenderEditable (#14119)
This commit is contained in:
parent
b0d5d2d928
commit
b94f757d77
@ -389,7 +389,6 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleTapCancel() {
|
void _handleTapCancel() {
|
||||||
_renderEditable.handleTapCancel();
|
|
||||||
_cancelCurrentSplash();
|
_cancelCurrentSplash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,8 +155,7 @@ class RenderEditable extends RenderBox {
|
|||||||
assert(!_showCursor.value || cursorColor != null);
|
assert(!_showCursor.value || cursorColor != null);
|
||||||
_tap = new TapGestureRecognizer(debugOwner: this)
|
_tap = new TapGestureRecognizer(debugOwner: this)
|
||||||
..onTapDown = _handleTapDown
|
..onTapDown = _handleTapDown
|
||||||
..onTap = _handleTap
|
..onTap = _handleTap;
|
||||||
..onTapCancel = _handleTapCancel;
|
|
||||||
_longPress = new LongPressGestureRecognizer(debugOwner: this)
|
_longPress = new LongPressGestureRecognizer(debugOwner: this)
|
||||||
..onLongPress = _handleLongPress;
|
..onLongPress = _handleLongPress;
|
||||||
}
|
}
|
||||||
@ -171,7 +170,7 @@ class RenderEditable extends RenderBox {
|
|||||||
|
|
||||||
/// If true [handleEvent] does nothing and it's assumed that this
|
/// If true [handleEvent] does nothing and it's assumed that this
|
||||||
/// renderer will be notified of input gestures via [handleTapDown],
|
/// renderer will be notified of input gestures via [handleTapDown],
|
||||||
/// [handleTap], [handleTapCancel], and [handleLongPress].
|
/// [handleTap], and [handleLongPress].
|
||||||
///
|
///
|
||||||
/// The default value of this property is false.
|
/// The default value of this property is false.
|
||||||
bool ignorePointer;
|
bool ignorePointer;
|
||||||
@ -569,7 +568,6 @@ class RenderEditable extends RenderBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Offset _lastTapDownPosition;
|
Offset _lastTapDownPosition;
|
||||||
Offset _longPressPosition;
|
|
||||||
|
|
||||||
/// If [ignorePointer] is false (the default) then this method is called by
|
/// If [ignorePointer] is false (the default) then this method is called by
|
||||||
/// the internal gesture recognizer's [TapGestureRecognizer.onTapDown]
|
/// the internal gesture recognizer's [TapGestureRecognizer.onTapDown]
|
||||||
@ -594,10 +592,8 @@ class RenderEditable extends RenderBox {
|
|||||||
void handleTap() {
|
void handleTap() {
|
||||||
_layoutText(constraints.maxWidth);
|
_layoutText(constraints.maxWidth);
|
||||||
assert(_lastTapDownPosition != null);
|
assert(_lastTapDownPosition != null);
|
||||||
final Offset globalPosition = _lastTapDownPosition;
|
|
||||||
_lastTapDownPosition = null;
|
|
||||||
if (onSelectionChanged != null) {
|
if (onSelectionChanged != null) {
|
||||||
final TextPosition position = _textPainter.getPositionForOffset(globalToLocal(globalPosition));
|
final TextPosition position = _textPainter.getPositionForOffset(globalToLocal(_lastTapDownPosition));
|
||||||
onSelectionChanged(new TextSelection.fromPosition(position), this, SelectionChangedCause.tap);
|
onSelectionChanged(new TextSelection.fromPosition(position), this, SelectionChangedCause.tap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -606,22 +602,6 @@ class RenderEditable extends RenderBox {
|
|||||||
handleTap();
|
handleTap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If [ignorePointer] is false (the default) then this method is called by
|
|
||||||
/// the internal gesture recognizer's [TapGestureRecognizer.onTapCancel]
|
|
||||||
/// callback.
|
|
||||||
///
|
|
||||||
/// When [ignorePointer] is true, an ancestor widget must respond to tap
|
|
||||||
/// cancel events by calling this method.
|
|
||||||
void handleTapCancel() {
|
|
||||||
// longPress arrives after tapCancel, so remember the tap position.
|
|
||||||
_longPressPosition = _lastTapDownPosition;
|
|
||||||
_lastTapDownPosition = null;
|
|
||||||
}
|
|
||||||
void _handleTapCancel() {
|
|
||||||
assert(!ignorePointer);
|
|
||||||
handleTapCancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// If [ignorePointer] is false (the default) then this method is called by
|
/// If [ignorePointer] is false (the default) then this method is called by
|
||||||
/// the internal gesture recognizer's [LongPressRecognizer.onLongPress]
|
/// the internal gesture recognizer's [LongPressRecognizer.onLongPress]
|
||||||
/// callback.
|
/// callback.
|
||||||
@ -630,10 +610,9 @@ class RenderEditable extends RenderBox {
|
|||||||
/// press events by calling this method.
|
/// press events by calling this method.
|
||||||
void handleLongPress() {
|
void handleLongPress() {
|
||||||
_layoutText(constraints.maxWidth);
|
_layoutText(constraints.maxWidth);
|
||||||
final Offset globalPosition = _longPressPosition;
|
assert(_lastTapDownPosition != null);
|
||||||
_longPressPosition = null;
|
|
||||||
if (onSelectionChanged != null) {
|
if (onSelectionChanged != null) {
|
||||||
final TextPosition position = _textPainter.getPositionForOffset(globalToLocal(globalPosition));
|
final TextPosition position = _textPainter.getPositionForOffset(globalToLocal(_lastTapDownPosition));
|
||||||
onSelectionChanged(_selectWordAtOffset(position), this, SelectionChangedCause.longPress);
|
onSelectionChanged(_selectWordAtOffset(position), this, SelectionChangedCause.longPress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user