From: David Lawrence Ramsey Date: Sat, 26 Aug 2006 15:14:55 +0000 (+0000) Subject: properly preserve the cursor position when going from the "Read File" or X-Git-Tag: v1.9.99pre1~12 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=98332d40dcf639ee70d31e2482f563dfacf73274;p=nano.git properly preserve the cursor position when going from the "Read File" or "Save File As" prompt to the file browser to the "Go To Directory" prompt, and then canceling back to the "Read File" or "Save File As" prompt git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3850 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 3c720a84..9a448acf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -56,6 +56,11 @@ CVS code - do_insertfile_void(), shortcut_init(), toggle_init(), help_init(), print_view_warning(), usage(), and do_mark(). (Benno Schulenberg, minor tweaks by DLR) + - Properly preserve the cursor position when going from the + "Read File" or "Save File As" prompt to the file browser to + the "Go To Directory" prompt, and then canceling back to the + "Read File" or "Save File As" prompt. Changes to + get_prompt_string() and do_prompt(). (DLR) - browser.c: do_browser() - Refactor the mouse support, modeling it after do_mouse() for diff --git a/src/prompt.c b/src/prompt.c index ee1440ed..1d67d88a 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -33,6 +33,10 @@ static size_t statusbar_x = (size_t)-1; /* The cursor position in answer. */ static size_t statusbar_pww = (size_t)-1; /* The place we want in answer. */ +static size_t old_statusbar_x = (size_t)-1; + /* The old cursor position in answer, if any. */ +static size_t old_statusbar_pww = (size_t)-1; + /* The old place we want in answer, if any. */ static bool reset_statusbar_x = FALSE; /* Should we reset the cursor position at the statusbar * prompt? */ @@ -965,13 +969,20 @@ int get_prompt_string(bool allow_tabs, answer = mallocstrcpy(answer, curranswer); curranswer_len = strlen(answer); - /* Only put statusbar_x at the end of the string (and change - * statusbar_pww to match) if it's uninitialized, if it would be - * past the end of curranswer, or if reset_statusbar_x is TRUE. - * Otherwise, leave it alone. This is so the cursor position stays - * at the same place if a prompt-changing toggle is pressed. */ - if (statusbar_x == (size_t)-1 || statusbar_x > curranswer_len || - reset_statusbar_x) { + /* If reset_statusbar_x is TRUE, restore statusbar_x and + * statusbar_pww to what they were before this prompt. Then, if + * statusbar_x is uninitialized or past the end of curranswer, put + * statusbar_x at the end of the string and update statusbar_pww + * based on it. We do these things so that the cursor position + * stays at the right place if a prompt-changing toggle is pressed, + * or if this prompt was started from another prompt and we cancel + * out of it. */ + if (reset_statusbar_x) { + statusbar_x = old_statusbar_x; + statusbar_pww = old_statusbar_pww; + } + + if (statusbar_x == (size_t)-1 || statusbar_x > curranswer_len) { statusbar_x = curranswer_len; statusbar_pww = statusbar_xplustabs(); } @@ -1126,8 +1137,8 @@ int get_prompt_string(bool allow_tabs, * associated function, so reset statusbar_x and statusbar_pww. */ if (kbinput == NANO_CANCEL_KEY || kbinput == NANO_ENTER_KEY || ran_func) { - statusbar_x = (size_t)-1; - statusbar_pww = (size_t)-1; + statusbar_x = old_statusbar_x; + statusbar_pww = old_statusbar_pww; } return kbinput; @@ -1192,6 +1203,9 @@ int do_prompt(bool allow_tabs, free(prompt); prompt = NULL; + old_statusbar_x = statusbar_x; + old_statusbar_pww = statusbar_pww; + reset_statusbar_x = FALSE; switch (retval) {