tabComplete method

String? tabComplete(
  1. String currentQuery, {
  2. String displayPath(
    1. R result
    )?,
})

Compute the tab-completion expansion for currentQuery.

Finds the longest common prefix of all current result display paths and returns it if it is strictly longer than currentQuery. Returns null when there is nothing to expand.

displayPath extracts the comparable path string from each result. The default implementation handles SignalSearchResult and OccurrenceSearchResult automatically; pass a custom extractor for other result types.

Implementation

String? tabComplete(
  String currentQuery, {
  String Function(R result)? displayPath,
}) {
  if (_results.isEmpty) {
    return null;
  }

  final extractor = displayPath ?? _defaultDisplayPath;
  final paths = _results.map(extractor).toList();
  final prefix = HierarchyService.longestCommonPrefix(paths);
  if (prefix == null) {
    return null;
  }

  // Normalise the query the same way UpdateQuery does so lengths are
  // comparable (e.g. dots → slashes).
  final normalizedQuery = _normalizeFn(currentQuery);
  if (prefix.length <= normalizedQuery.length) {
    return null;
  }
  return prefix;
}