getFinalHighlightLength method

int getFinalHighlightLength(
  1. {required DictionarySearchResult? result,
  2. required String searchTerm}
)

Get final highlight length after a dictionary search.

Implementation

int getFinalHighlightLength({
  required DictionarySearchResult? result,
  required String searchTerm,
}) {
  if (isSpaceDelimited) {
    RegExp regex = RegExp('[ ]');

    int numberOfWords = result?.headings
            .firstWhereOrNull((e) => e.id == result.headingIds.first)
            ?.term
            .splitWithDelim(regex)
            .length ??
        1;
    List<String> searchTermWords = searchTerm.splitWithDelim(regex);
    return searchTermWords.sublist(0, numberOfWords).join().length;
  } else {
    return max(1, result?.bestLength ?? 0);
  }
}