From 916f354c9b77881a50f3874e706d714ccbdc7dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?=
Date: Sat, 30 Oct 2021 12:32:40 +0200 Subject: [PATCH] Move the cursor to just created directories --- sdn.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sdn.cpp b/sdn.cpp index 67f928c..c467e75 100644 --- a/sdn.cpp +++ b/sdn.cpp @@ -828,8 +828,7 @@ fun at_cursor () -> const entry & { return g.cursor >= int (g.entries.size ()) ? invalid : g.entries[g.cursor]; } -fun resort (const string anchor = at_cursor ().filename) { - sort (begin (g.entries), end (g.entries)); +fun focus (const string &anchor) { if (!anchor.empty ()) { for (size_t i = 0; i < g.entries.size (); i++) 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) { g.unames.clear(); while (auto *ent = getpwent ()) @@ -1446,9 +1450,11 @@ fun handle (wint_t c) -> bool { case ACTION_MKDIR: g.editor = L"mkdir"; 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)); reload (true); + focus (mb); }; break;