Format code

pull/295/head
Cheryl Zhang 4 years ago
parent 240688f06e
commit 0aa1a9cee0
  1. 8
      lib/src/widgets/editor.dart
  2. 10
      lib/src/widgets/text_selection.dart

@ -903,19 +903,21 @@ class RenderEditor extends RenderEditableContainerBox
double? getOffsetToRevealCursor( double? getOffsetToRevealCursor(
double viewportHeight, double scrollOffset, double offsetInViewport) { double viewportHeight, double scrollOffset, double offsetInViewport) {
final endpoints = getEndpointsForSelection(selection); final endpoints = getEndpointsForSelection(selection);
// when we drag the right handle, we should get the last point // when we drag the right handle, we should get the last point
TextSelectionPoint endpoint; TextSelectionPoint endpoint;
if (selection.isCollapsed) { if (selection.isCollapsed) {
endpoint = endpoints.first; endpoint = endpoints.first;
} else { } else {
if (selection is DragTextSelection) { if (selection is DragTextSelection) {
endpoint = (selection as DragTextSelection).first ? endpoints.first : endpoints.last; endpoint = (selection as DragTextSelection).first
? endpoints.first
: endpoints.last;
} else { } else {
endpoint = endpoints.first; endpoint = endpoints.first;
} }
} }
final child = childAtPosition(selection.extent); final child = childAtPosition(selection.extent);
const kMargin = 8.0; const kMargin = 8.0;

@ -25,12 +25,10 @@ enum _TextSelectionHandlePosition { START, END }
/// internal use, used to get drag direction information /// internal use, used to get drag direction information
class DragTextSelection extends TextSelection { class DragTextSelection extends TextSelection {
final bool first;
const DragTextSelection({ const DragTextSelection({
TextAffinity affinity = TextAffinity.downstream,
int baseOffset = 0, int baseOffset = 0,
int extentOffset = 0, int extentOffset = 0,
TextAffinity affinity = TextAffinity.downstream,
bool isDirectional = false, bool isDirectional = false,
this.first = true, this.first = true,
}) : super( }) : super(
@ -40,6 +38,8 @@ class DragTextSelection extends TextSelection {
isDirectional: isDirectional, isDirectional: isDirectional,
); );
final bool first;
@override @override
DragTextSelection copyWith({ DragTextSelection copyWith({
int? baseOffset, int? baseOffset,
@ -191,7 +191,7 @@ class EditorTextSelectionOverlay {
default: default:
throw 'Invalid position'; throw 'Invalid position';
} }
final currSelection = newSelection != null final currSelection = newSelection != null
? DragTextSelection( ? DragTextSelection(
baseOffset: newSelection.baseOffset, baseOffset: newSelection.baseOffset,
@ -201,7 +201,7 @@ class EditorTextSelectionOverlay {
first: position == _TextSelectionHandlePosition.START, first: position == _TextSelectionHandlePosition.START,
) )
: null; : null;
selectionDelegate selectionDelegate
..userUpdateTextEditingValue( ..userUpdateTextEditingValue(
value.copyWith(selection: currSelection, composing: TextRange.empty), value.copyWith(selection: currSelection, composing: TextRange.empty),

Loading…
Cancel
Save