Completion: Add Shift+Tab to move back in the list like zsh

This commit is contained in:
M600 2017-03-27 09:31:31 +02:00
parent bdff3a032a
commit 6d742b1235
2 changed files with 14 additions and 9 deletions

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/18 11:13:04 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_D 4348699
# define KP_L 4479771 # define KP_L 4479771
# define KP_R 4414235 # define KP_R 4414235
# define KP_T 9
# define KP_TS 5921563
/* /*
** Autocompletion list for the valid candidates from the parser. ** Autocompletion list for the valid candidates from the parser.

View file

@ -6,18 +6,18 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/09/20 14:50:33 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" #include "completion.h"
/* /*
** Function to select the next item in the list if it has already been created ** Function to select the next or previous item in the list if it has already
** and if the key pressed is tab. ** 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; t_clst *ptr;
@ -25,8 +25,11 @@ static void c_next_item(t_comp *c)
while (!ptr->cursor) while (!ptr->cursor)
ptr = ptr->next; ptr = ptr->next;
ptr->cursor = 0; 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. ** Once the completion has been processed, this is the return point.
@ -117,8 +120,8 @@ int completion(long int keypress)
else else
{ {
c_term_resize(s->comp); c_term_resize(s->comp);
if (keypress == TOUCHE_TAB) if (keypress == KP_T || keypress == KP_TS)
c_next_item(s->comp); keypress == KP_T ? c_mv_tab(s->comp, 1) : c_mv_tab(s->comp, 0);
else if (c_keypress(s->comp, keypress)) else if (c_keypress(s->comp, keypress))
return (1); return (1);
} }