OSC/bc_js_filepicker

default to . if directory, otherwise initialize to ..

Closed this issue · 5 comments

Defaulting to <initial_value>/.. (the directory above the initial value) should probably only happen when the initial_value is a file right? Otherwise when you give a directory, you start out in the directory above it, which is kinda strange.

I propose a check, if it's a file then initialize to .. (above) otherwise . (here). A simple check may just to see if there's a file extension. If there's no extension you can assume it's a directory, this may be simpler/more efficient than fetching the FS to verify.

You start in the directory above the selected item for two reasons. The first is so that your selected item can be shown to be selected by applying the active class to it (makes it blue). The second is that without querying the API there is no way to be sure that the selected item is a directory or a file.

We could attempt to use file extensions but that doesn't handle files without extensions like /usr/bin/env, or directories that appear to have extensions like /etc/sudoers.d.

We can assume that those are edge cases, and implement more complicated error handling?

Having the file picker open to a default location is a separate thing from what directory the file picker should open to when there is a currently selected file or directory.

A separate data attribute should allow specifying the default directory to open to if there is no selected file or directory.

If setting a default directory to open the picker to when there is no selection is not possible that should be opened as a separate issue.

OK. it's just if I initialize to /tmp/foo wanting folks to pick a file from foo, the filepicker sets itself to /tmp and they have to then step back into /tmp/foo. It just seems like a counter-intuitive UX for directories.

You could set a default value of /tmp/foo/.