Skip to content

Conversation

@pkaila
Copy link

@pkaila pkaila commented Aug 31, 2025

This PR replaces the editor File menu with a hierarchical menu, which resembles a file picker in a regular text editor.

There is a subtle change from previous behaviour which is that the currently selected file will be highlighted by having a different background color for the currently selected file in the menu. This is instead of the caret '>' in front of the file name in the current version.

Otherwise, for users with only a few beancount files, the menu will look almost like it used to. The only difference will be that the directory where the file(s) reside is shown in the top and the files then listed below.

So instead of:

/beancount/data/root/main.bean
/beancount/data/root/other.bean

It will look like:

/beancount/data/root
 main.bean
 other.bean

For users with multiple files in a directory hierarchy, the change will be bigger.

Instead of:

/beancount/data/root/main.bean
/beancount/data/root/other/deeper/filec.bean
/beancount/data/root/other/deeper/filed.bean
/beancount/data/root/other/filea.bean
/beancount/data/root/other/fileb.bean

It will look like:

/beancount/data/root
 main.bean
 ▸ other/

And can be expanded to:

/beancount/data/root
 main.bean
 ▾ other/
   ▾ deeper/
     filec.bean
     filed.bean
   filea.bean
   fileb.bean

Unlike usually directories are not first in the order. Instead the order of the files and directories follows the existing alphabetic file ordering.

By default the directories leading to the currently selected file will be expanded, but can be collapsed. In which case the collapsed directory will show as being selected.

Here is an example of how it looks like:
example

Replace the editor File menu with a hierarchical menu, which resembles
a file picker in a regular text editor.

There is a subtle change from previous behaviour which is that the
currently selected file will be highlighted by having a different
background color for the currently selected file in the menu. This is
instead of the caret '>' in front of the file name in the current
version.

Otherwise, for users with only a few beancount files, the menu will look
almost like it used to. The only difference will be that the directory
where the file(s) reside is shown in the top and the files then listed
below.

So instead of:
```
/beancount/data/root/main.bean
/beancount/data/root/other.bean
```

It will look like:
```
/beancount/data/root
 main.bean
 other.bean
```

For users with multiple files in a directory hierarchy, the change will
be bigger.

Instead of:
```
/beancount/data/root/main.bean
/beancount/data/root/other/deeper/filec.bean
/beancount/data/root/other/deeper/filed.bean
/beancount/data/root/other/filea.bean
/beancount/data/root/other/fileb.bean
```

It will look like:
```
/beancount/data/root
 main.bean
 ▸ other/
```

And can be expanded to:
```
/beancount/data/root
 main.bean
 ▾ other/
   ▾ deeper/
     filec.bean
     filed.bean
   filea.bean
   fileb.bean
```

Unlike usually directories are _not_ first in the order. Instead the
order of the files and directories follows the existing alphabetic file
ordering.
Copy link
Member

@yagebu yagebu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. See my inline comments for how this could be better integrated using existing logic.

Also please add tests.

}
}

function buildSourcesTree($sources: Set<string>): SourceNode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could instead reuse the stratify function from lib/tree.ts

}

// Splits the path to dirname (including last separator) and basename
function dirnameBasename(path: string): [string, string] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should leave in lib/paths.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants