diff options
| author | WormHeamer | 2026-01-02 17:04:20 -0500 |
|---|---|---|
| committer | WormHeamer | 2026-01-02 17:04:20 -0500 |
| commit | 12214f20764340d4b04da7313fad35609ba86a7c (patch) | |
| tree | fd5ddcf6c46b8035866f5925c0f329ed087b142d | |
| parent | 203b568126817f707d895991dc35650d493b8fd0 (diff) | |
make select_file() start in directory of current buffer if possible
| -rw-r--r-- | main.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -515,6 +515,13 @@ static Str basename(Str s) { } } +static Str dirname(Str s) { + while (s.n > 0 && s.s[s.n - 1] == '/') s.n--; + while (s.n > 0 && s.s[s.n - 1] != '/') s.n--; + while (s.n > 0 && s.s[s.n - 1] == '/') s.n--; + return s; +} + #define STYLE_BUF (A_DEFAULT) #define STYLE_BUF_SEL (STYLE_BUF | A_REVERSE) #define STYLE_TXT (A_DEFAULT) @@ -1354,7 +1361,12 @@ again: } Str select_file(void) { - Str s = select_file_in("."); + const char *path = "."; + EditBuf *eb = &e.buf[e.bufi]; + if (eb->type == ED_BUF_FILE || eb->type == ED_BUF_BIN_FILE) { + path = str_to_cstr(dirname(eb->path), &e.scratch); + } + Str s = select_file_in(path); return s; } |
