diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 935a279a..dcd66200 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/03/23 15:41:32 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 09:30:01 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,8 @@ # define KP_D 4348699 # define KP_L 4479771 # define KP_R 4414235 +# define KP_T 9 +# define KP_TS 5921563 /* ** Autocompletion list for the valid candidates from the parser. diff --git a/42sh/src/completion/completion.c b/42sh/src/completion/completion.c index 2a5f7afb..752ed3f5 100644 --- a/42sh/src/completion/completion.c +++ b/42sh/src/completion/completion.c @@ -6,18 +6,18 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/09/20 14:50:33 by alao #+# #+# */ -/* Updated: 2017/03/23 18:58:47 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 09:30:40 by alao ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" /* -** Function to select the next item in the list if it has already been created -** and if the key pressed is tab. +** Function to select the next or previous item in the list if it has already +** been created and if the key pressed is tab. */ -static void c_next_item(t_comp *c) +static void c_mv_tab(t_comp *c, int next) { t_clst *ptr; @@ -25,8 +25,11 @@ static void c_next_item(t_comp *c) while (!ptr->cursor) ptr = ptr->next; ptr->cursor = 0; - ptr->next->cursor = 1; -} + if (next) + ptr->next->cursor = 1; + else + ptr->prev->cursor = 1; + } /* ** Once the completion has been processed, this is the return point. @@ -117,8 +120,8 @@ int completion(long int keypress) else { c_term_resize(s->comp); - if (keypress == TOUCHE_TAB) - c_next_item(s->comp); + if (keypress == KP_T || keypress == KP_TS) + keypress == KP_T ? c_mv_tab(s->comp, 1) : c_mv_tab(s->comp, 0); else if (c_keypress(s->comp, keypress)) return (1); }