Move the cursor to just created directories

This commit is contained in:
Přemysl Eric Janouch 2021-10-30 12:32:40 +02:00
parent 050f875c47
commit 916f354c9b
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 9 additions and 3 deletions

12
sdn.cpp
View File

@ -828,8 +828,7 @@ fun at_cursor () -> const entry & {
return g.cursor >= int (g.entries.size ()) ? invalid : g.entries[g.cursor]; return g.cursor >= int (g.entries.size ()) ? invalid : g.entries[g.cursor];
} }
fun resort (const string anchor = at_cursor ().filename) { fun focus (const string &anchor) {
sort (begin (g.entries), end (g.entries));
if (!anchor.empty ()) { if (!anchor.empty ()) {
for (size_t i = 0; i < g.entries.size (); i++) for (size_t i = 0; i < g.entries.size (); i++)
if (g.entries[i].filename == anchor) if (g.entries[i].filename == anchor)
@ -837,6 +836,11 @@ fun resort (const string anchor = at_cursor ().filename) {
} }
} }
fun resort (const string anchor = at_cursor ().filename) {
sort (begin (g.entries), end (g.entries));
focus (anchor);
}
fun reload (bool keep_anchor) { fun reload (bool keep_anchor) {
g.unames.clear(); g.unames.clear();
while (auto *ent = getpwent ()) while (auto *ent = getpwent ())
@ -1446,9 +1450,11 @@ fun handle (wint_t c) -> bool {
case ACTION_MKDIR: case ACTION_MKDIR:
g.editor = L"mkdir"; g.editor = L"mkdir";
g.editor_on[ACTION_INPUT_CONFIRM] = [] { g.editor_on[ACTION_INPUT_CONFIRM] = [] {
if (mkdir (to_mb (g.editor_line).c_str (), 0777)) auto mb = to_mb (g.editor_line);
if (mkdir (mb.c_str (), 0777))
show_message (strerror (errno)); show_message (strerror (errno));
reload (true); reload (true);
focus (mb);
}; };
break; break;