isLexicallyPotentialFilePath method

bool isLexicallyPotentialFilePath(
  1. String text
)

Lexically detects if a pasted text string represents a potential local file path.

This check is purely synchronous and lexical, meaning it does not perform filesystem I/O, making it safe to run on the main UI/rendering thread without blocking.

Implementation

bool isLexicallyPotentialFilePath(String text) {
  final trimmed = text.trim();
  if (trimmed.isEmpty) return false;

  if (pathContext.isAbsolute(trimmed)) return true;

  // Check for user home syntax or standard relative path segment prefixes
  return trimmed.startsWith('~/') ||
      trimmed.startsWith(r'~\') ||
      trimmed.startsWith('./') ||
      trimmed.startsWith(r'.\') ||
      trimmed.startsWith('../') ||
      trimmed.startsWith(r'..\');
}