From b94f757d770e9c303602ebe3e0477bdc7af09ff8 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Wed, 17 Jan 2018 09:14:30 -0800 Subject: [PATCH] Small simplification in RenderEditable (#14119) --- .../flutter/lib/src/material/text_field.dart | 1 - .../flutter/lib/src/rendering/editable.dart | 31 +++---------------- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index a374f99c865..9d8868a54c1 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -389,7 +389,6 @@ class _TextFieldState extends State with AutomaticKeepAliveClientMixi } void _handleTapCancel() { - _renderEditable.handleTapCancel(); _cancelCurrentSplash(); } diff --git a/packages/flutter/lib/src/rendering/editable.dart b/packages/flutter/lib/src/rendering/editable.dart index bdafe3ea92a..3a4a36c9d0d 100644 --- a/packages/flutter/lib/src/rendering/editable.dart +++ b/packages/flutter/lib/src/rendering/editable.dart @@ -155,8 +155,7 @@ class RenderEditable extends RenderBox { assert(!_showCursor.value || cursorColor != null); _tap = new TapGestureRecognizer(debugOwner: this) ..onTapDown = _handleTapDown - ..onTap = _handleTap - ..onTapCancel = _handleTapCancel; + ..onTap = _handleTap; _longPress = new LongPressGestureRecognizer(debugOwner: this) ..onLongPress = _handleLongPress; } @@ -171,7 +170,7 @@ class RenderEditable extends RenderBox { /// If true [handleEvent] does nothing and it's assumed that this /// renderer will be notified of input gestures via [handleTapDown], - /// [handleTap], [handleTapCancel], and [handleLongPress]. + /// [handleTap], and [handleLongPress]. /// /// The default value of this property is false. bool ignorePointer; @@ -569,7 +568,6 @@ class RenderEditable extends RenderBox { } Offset _lastTapDownPosition; - Offset _longPressPosition; /// If [ignorePointer] is false (the default) then this method is called by /// the internal gesture recognizer's [TapGestureRecognizer.onTapDown] @@ -594,10 +592,8 @@ class RenderEditable extends RenderBox { void handleTap() { _layoutText(constraints.maxWidth); assert(_lastTapDownPosition != null); - final Offset globalPosition = _lastTapDownPosition; - _lastTapDownPosition = 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); } } @@ -606,22 +602,6 @@ class RenderEditable extends RenderBox { 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 /// the internal gesture recognizer's [LongPressRecognizer.onLongPress] /// callback. @@ -630,10 +610,9 @@ class RenderEditable extends RenderBox { /// press events by calling this method. void handleLongPress() { _layoutText(constraints.maxWidth); - final Offset globalPosition = _longPressPosition; - _longPressPosition = null; + assert(_lastTapDownPosition != null); if (onSelectionChanged != null) { - final TextPosition position = _textPainter.getPositionForOffset(globalToLocal(globalPosition)); + final TextPosition position = _textPainter.getPositionForOffset(globalToLocal(_lastTapDownPosition)); onSelectionChanged(_selectWordAtOffset(position), this, SelectionChangedCause.longPress); } }