From 579e4c9a34b98059530f08133b77f4ab44a60e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?=
Date: Fri, 2 Nov 2018 22:12:34 +0100 Subject: [PATCH] Make confirming a search choose the item --- sdn.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/sdn.cpp b/sdn.cpp index 6a255a0..3084248 100644 --- a/sdn.cpp +++ b/sdn.cpp @@ -478,6 +478,7 @@ static struct { string chosen; ///< Chosen item for the command line bool no_chdir; ///< Do not tell the shell to chdir + bool quitting; ///< Whether we should quit already int inotify_fd, inotify_wd = -1; ///< File watch bool out_of_date; ///< Entries may be out of date @@ -924,15 +925,15 @@ fun change_dir (const string &path) { } } -fun choose (const entry &entry) -> bool { +fun choose (const entry &entry) { // Dive into directories and accessible symlinks to them if (!S_ISDIR (entry.info.st_mode) && !S_ISDIR (entry.target_info.st_mode)) { g.chosen = entry.filename; - return false; + g.quitting = true; + } else { + change_dir (entry.filename); } - change_dir (entry.filename); - return true; } fun handle_editor (wint_t c) { @@ -976,19 +977,20 @@ fun handle (wint_t c) -> bool { case ACTION_CHOOSE_FULL: g.chosen = g.cwd + "/" + current.filename; g.no_chdir = true; - return false; + g.quitting = true; + break; case ACTION_CHOOSE: - if (choose (current)) - break; - return false; + choose (current); + break; case ACTION_HELP: show_help (); - return true; + break; case ACTION_QUIT_NO_CHDIR: g.no_chdir = true; - return false; + // Fall-through case ACTION_QUIT: - return false; + g.quitting = true; + break; case ACTION_SORT_LEFT: g.sort_column = (g.sort_column + entry::COLUMNS - 1) % entry::COLUMNS; @@ -1048,6 +1050,9 @@ fun handle (wint_t c) -> bool { g.editor_on_change = [] { search (g.editor_line); }; + g.editor_on_confirm = [] { + choose (g.entries[g.cursor]); + }; break; case ACTION_RENAME_PREFILL: g.editor_line = to_wide (current.filename); @@ -1084,7 +1089,7 @@ fun handle (wint_t c) -> bool { } fix_cursor_and_offset (); update (); - return true; + return !g.quitting; } fun inotify_check () {