Add comments

pull/609/head
X Code 3 years ago
parent 78277d5cf7
commit 955d838532
  1. 19
      lib/src/widgets/editor.dart

@ -1229,8 +1229,25 @@ class RenderEditor extends RenderEditableContainerBox
/// The offset is the distance from the top of the editor and is the minimum
/// from the current scroll position until [selection] becomes visible.
/// Returns null if [selection] is already visible.
///
/// Finds the closest scroll offset that fully reveals the editing cursor.
///
/// The `scrollOffset` parameter represents current scroll offset in the
/// parent viewport.
///
/// The `offsetInViewport` parameter represents the editor's vertical offset
/// in the parent viewport. This value should normally be 0.0 if this editor
/// is the only child of the viewport or if it's the topmost child. Otherwise
/// it should be a positive value equal to total height of all siblings of
/// this editor from above it.
///
/// Returns `null` if the cursor is currently visible.
double? getOffsetToRevealCursor(
double viewportHeight, double scrollOffset, double offsetInViewport) {
// Endpoints coordinates represents lower left or lower right corner of
// the selection. If we want to scroll up to reveal the caret we need to
// adjust the dy value by the height of the line. We also add a small margin
// so that the caret is not too close to the edge of the viewport.
final endpoints = getEndpointsForSelection(selection);
// when we drag the right handle, we should get the last point
@ -1247,6 +1264,7 @@ class RenderEditor extends RenderEditableContainerBox
}
}
// Collapsed selection => caret
final child = childAtPosition(selection.extent);
const kMargin = 8.0;
@ -1267,6 +1285,7 @@ class RenderEditor extends RenderEditableContainerBox
if (dy == null) {
return null;
}
// Clamping to 0.0 so that the content does not jump unnecessarily.
return math.max(dy, 0);
}

Loading…
Cancel
Save