didSelectFile method

(bool, String?) didSelectFile(
  1. Msg msg
)

Returns whether a file was selected on this message.

Returns a tuple of (didSelect, path).

Implementation

(bool, String?) didSelectFile(Msg msg) {
  if (_files.isEmpty) return (false, null);

  if (msg is! KeyMsg) return (false, null);

  if (!msg.key.matchesSingle(_keyMap.select)) {
    return (false, null);
  }

  final file = _files[_selected];
  final isDir = file.isDirectory;
  final selectedPath = _selectedPath;

  if (isDir && _dirAllowed && selectedPath != null) {
    return (true, selectedPath);
  }

  if (!isDir && _fileAllowed && selectedPath != null) {
    if (canSelect(p.basename(selectedPath))) {
      return (true, selectedPath);
    }
  }

  return (false, null);
}