handleGranularlyExtendSelection method

  1. @protected
SelectionResult handleGranularlyExtendSelection(
  1. GranularlyExtendSelectionEvent event
)

Extend current selection in a certain TextGranularity.

Implementation

@protected
SelectionResult handleGranularlyExtendSelection(GranularlyExtendSelectionEvent event) {
  assert((currentSelectionStartIndex == -1) == (currentSelectionEndIndex == -1));
  if (currentSelectionStartIndex == -1) {
    if (event.forward) {
      currentSelectionStartIndex = currentSelectionEndIndex = 0;
    } else {
      currentSelectionStartIndex = currentSelectionEndIndex = selectables.length;
    }
  }
  int targetIndex = event.isEnd ? currentSelectionEndIndex : currentSelectionStartIndex;
  SelectionResult result = dispatchSelectionEventToChild(selectables[targetIndex], event);
  if (event.forward) {
    assert(result != SelectionResult.previous);
    while (targetIndex < selectables.length - 1 && result == SelectionResult.next) {
      targetIndex += 1;
      result = dispatchSelectionEventToChild(selectables[targetIndex], event);
      assert(result != SelectionResult.previous);
    }
  } else {
    assert(result != SelectionResult.next);
    while (targetIndex > 0 && result == SelectionResult.previous) {
      targetIndex -= 1;
      result = dispatchSelectionEventToChild(selectables[targetIndex], event);
      assert(result != SelectionResult.next);
    }
  }
  if (event.isEnd) {
    currentSelectionEndIndex = targetIndex;
  } else {
    currentSelectionStartIndex = targetIndex;
  }
  return result;
}