anc95 / inquirer-file-tree-selection

inquirer prompt for select a file or dir by file tree
49 stars 26 forks source link

Folders are only found when a user selects them #28

Closed atjn closed 3 years ago

atjn commented 3 years ago

Hello again, and once again thanks for this really cool plugin :)

In all versions of this package prior to 1.0.7, any folder in the file tree would have an arrow in front of it, showing that it is a folder, and that it can be opened. In version 1.0.7, it seems there has been a regression where it only checks if something is a folder when you hover over it. It also seems that the very first folder that is automatically selected, isn't checked at all, which means it gets a play symbol instead of an arrow. That is not supposed to happen at all. (the last issue only happens when you use a validate function that displaces the cursor)

Steps to reproduce

Create a test project with the following code:

import inquirer from "inquirer";
import fileTree from "inquirer-file-tree-selection-prompt";
const prompt = inquirer.createPromptModule();
prompt.registerPrompt("file-tree", fileTree);

await prompt([
    {
        name: "test",
        type: "file-tree",
        onlyShowDir: true,
        onlyShowValid: true,
        message: `This is a test.`,
        validate: async path => Boolean(path !== process.cwd()),
    }
]);

Run it with version 1.0.6 (or any other older version) and see that it works as intended:

working

Then run it again with version 1.0.7 and see that there are multiple issues with the display:

broken

atjn commented 3 years ago

I am guessing this was changed in connection with #18

I would argue that this is too much lazy-loading. It really confuses me when folders don't have the arrow, since they then seem to be files instead.

I think it should be possible to create some sort of async function that traverses the file system, but doesn't block the UI from working at the same time. If that is too complicated, maybe you could instead use the old method of traversing all of the file system first, but then count how many files you've encountered. If the counter gets above something like 100, it stops traversing and changes to the lazy-load method instead. Doing it this way would also solve the second bug I found (play button on folder), because the default selected folder would always be part of the 100 items that have already been traversed.

anc95 commented 3 years ago

I just published 1.0.8 version. you can try this. If there is still some trouble with this plugin, very welcome to feedback here~