updateLastSelectionToHeaderSelection method

UserSelectionState updateLastSelectionToHeaderSelection({
  1. int? anchor,
  2. required int focus,
  3. required Axis axis,
})

Transform the last selection on selections into a HeaderUserSelectionModel with anchor, focus and axis.

anchor defaults to the last selections UserSelectionModel.anchorCoordinate.

Implementation

UserSelectionState updateLastSelectionToHeaderSelection({
  int? anchor,
  required int focus,
  required Axis axis,
}) {
  final lastSelection = selections.last;
  final effectiveAnchor =
      anchor ?? _vectorValueFromAxis(lastSelection.anchorCoordinate, axis);

  final builder = selections.toBuilder();

  builder
    ..take(selections.length - 1)
    ..add(
      HeaderUserSelectionModel.fromSelectionModel(
        lastSelection,
        axis: axis,
        anchor: effectiveAnchor,
        focus: focus,
      ),
    );
  return UserSelectionState._(builder.build());
}