resetMetadataOnSelectionCollapsed method

void resetMetadataOnSelectionCollapsed()
inherited

If a selection changed and is inside the text and empty (collapsed), this function sets the current metadata to the metadata of the text before it's new position

Implementation

void resetMetadataOnSelectionCollapsed() {
  if (!selection.isCollapsed) return;
  if (selection.end == text.length || textBeforeSelection().isNullOrEmpty) {
    return;
  }
  if (_metadataToggled) return;

  final TextMetadata newMetadata = (deltas.isNotEmpty
          ? deltas[text.indexOf(selection.textBefore(text).chars.last)]
              .metadata
          : metadata) ??
      metadata ??
      RichTextEditorController.defaultMetadata;

  _metadata = _metadata?.combineWith(
        newMetadata,
        favourOther: true,
      ) ??
      newMetadata;
}