summaryrefslogtreecommitdiffstats
path: root/src/c_init.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/c_init.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/c_init.c b/src/c_init.c
index b463830..82600e8 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -109,23 +109,34 @@ static short
char *c_set_ptr(t_bool reset, char key, t_msh *msh)
{
static char *p = NULL;
+ static char *context = NULL;
if (reset == TRUE)
{
p = msh->curr_hist_ptr + ft_strlen(msh->curr_hist_ptr);
+ context = msh->curr_hist_ptr;
return (NULL);
}
- if ((key == -1 && p - msh->curr_hist_ptr != 0) || key == 1)
+ if (key == -1 && context == msh->curr_hist_ptr
+ && p - context == 0 && msh->prev_hist != NULL)
+ {
+ p = msh->prev_hist + ft_strlen(msh->prev_hist);
+ context = msh->prev_hist;
+ }
+ else if (key == 1 && context == msh->prev_hist
+ && p == msh->prev_hist + ft_strlen(msh->prev_hist))
+ {
+ p = msh->curr_hist_ptr;
+ context = msh->curr_hist_ptr;
+ }
+ else if ((key == -1 && p - context != 0) || key == 1)
{
p += (key == -1) ? (2 * key) : (0);
- while (((key == -1 && p - msh->curr_hist_ptr != 0) || key == 1) && *p != C_LF && *p != C_NUL)
- {
+ while (((key == -1 && p - context != 0) || key == 1)
+ && *p != C_LF && *p != C_NUL)
p += key;
- }
- if (p - msh->curr_hist_ptr != 0 && *p != C_NUL)
- {
+ if (p - context != 0 && *p != C_NUL)
p += 1;
- }
}
return (p);
}