// static
already_AddRefed<DeleteTextTransaction>
DeleteTextTransaction::MaybeCreateForPreviousCharacter(
                         EditorBase& aEditorBase,
                         CharacterData& aCharData,
                         uint32_t aOffset)
{
  if (NS_WARN_IF(!aOffset)) {
    return nullptr;
  }

  nsAutoString data;
  aCharData.GetData(data);
  if (NS_WARN_IF(data.IsEmpty())) {
    return nullptr;
  }

  uint32_t length = 1;
  uint32_t offset = aOffset - 1;
  if (offset &&
      NS_IS_LOW_SURROGATE(data[offset]) &&
      NS_IS_HIGH_SURROGATE(data[offset - 1])) {
    ++length;
    --offset;
  }
  return DeleteTextTransaction::MaybeCreate(aEditorBase, aCharData,
                                            offset, length);
}
// static
already_AddRefed<DeleteTextTransaction>
DeleteTextTransaction::MaybeCreateForNextCharacter(
                         EditorBase& aEditorBase,
                         CharacterData& aCharData,
                         uint32_t aOffset)
{
  nsAutoString data;
  aCharData.GetData(data);
  if (NS_WARN_IF(aOffset >= data.Length()) ||
      NS_WARN_IF(data.IsEmpty())) {
    return nullptr;
  }

  uint32_t length = 1;
  if (aOffset + 1 < data.Length() &&
      NS_IS_HIGH_SURROGATE(data[aOffset]) &&
      NS_IS_LOW_SURROGATE(data[aOffset + 1])) {
    ++length;
  }
  return DeleteTextTransaction::MaybeCreate(aEditorBase, aCharData,
                                            aOffset, length);
}