shichongrui / obsidian-reveal-active-file

Obsidian plugin to reveal the active file automatically when you open a file
93 stars 11 forks source link

Feature Request: Add option to collapse all folders before revealing the active file in the file explorer #26

Open karutt opened 1 month ago

karutt commented 1 month ago

Summary

I would like to propose adding an option to collapse all folders in the file explorer before revealing the active file. This feature allows users to focus only on the folder containing the current file, which greatly improves the user experience, especially when working with a large number of open folders.

Proposed Solution

Adding the following line of code to trigger the collapse-all action before revealing the active file:

    private async reveal() {
        // --- add ---
        (this.app as any).commands.executeCommandById("obsidian-collapse-all-plugin:collapse-file-explorer");
        // -----------
        (this.app as any).commands.executeCommandById("file-explorer:reveal-active-file");
        await this.wait_active_leaf_change();
        this.app.workspace.setActiveLeaf(this.current_open_file_leaf, { focus: true });
    }

This would collapse all the folders in the file explorer before revealing the currently active file, allowing users to easily focus on the file they are working on.

Benefits This feature helps users who often open multiple folders and files to reduce the need for excessive scrolling and manual folder management. It creates a cleaner and more efficient workflow by automatically organizing the file explorer.

Additional Thoughts It would be great if there was also a toggle option in the plugin's settings to turn this feature on or off, depending on the user's preference. This would provide flexibility for users who may not want to collapse folders every time they open a file.

Thank you for considering this suggestion!

karutt commented 1 month ago

I just realized that the command obsidian-collapse-all-plugin:collapse-file-explorer utilizes functionality from another plugin called obsidian-collapse-all. This plugin must be installed and enabled for the command to work as expected.