summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/main.c b/main.c
index 12e9549..894ed85 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,5 @@
// @TODO:
+// - ensure buffer->filename never contains / on windows
// - split
// - Windows installation
#include "base.h"
@@ -435,6 +436,24 @@ int main(int argc, char **argv) {
ted->drag_buffer = NULL;
}
+ { // ted->cwd should be the directory containing the last active buffer
+ TextBuffer *buffer = ted->active_buffer;
+ if (buffer) {
+ char const *buffer_path = buffer_get_filename(buffer);
+ if (buffer_path && !buffer_is_untitled(buffer)) {
+ assert(*buffer_path);
+ char *last_sep = strrchr(buffer_path, PATH_SEPARATOR);
+ if (last_sep) {
+ size_t dirname_len = (size_t)(last_sep - buffer_path);
+ if (dirname_len == 0) dirname_len = 1; // make sure "/x" sets our cwd to "/", not ""
+ // set cwd to buffer's directory
+ memcpy(ted->cwd, buffer_path, dirname_len);
+ ted->cwd[dirname_len] = 0;
+ }
+ }
+ }
+ }
+
u32 key_modifier = (u32)ctrl_down << KEY_MODIFIER_CTRL_BIT
| (u32)shift_down << KEY_MODIFIER_SHIFT_BIT