Started ctrl-left
This commit is contained in:
@@ -49,7 +49,7 @@ static WINDOW *inp_win;
|
||||
static int pad_start = 0;
|
||||
static int rows, cols;
|
||||
|
||||
static int _handle_edit(const wint_t ch, char *input, int *size);
|
||||
static int _handle_edit(int result, const wint_t ch, char *input, int *size);
|
||||
static int _printable(const wint_t ch);
|
||||
static void _clear_input(void);
|
||||
static void _go_to_end(int display_size);
|
||||
@@ -131,9 +131,25 @@ inp_get_char(char *input, int *size)
|
||||
prof_handle_activity();
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (ch != 0) {
|
||||
char *res = "?";
|
||||
if (result == ERR) {
|
||||
res = "ERR";
|
||||
}
|
||||
if (result == OK) {
|
||||
res = "OK";
|
||||
}
|
||||
if (result == KEY_CODE_YES) {
|
||||
res = "KEY_CODE_YES";
|
||||
}
|
||||
|
||||
cons_show("KEY CODE: %d, RESULT = %s", ch, res);
|
||||
win_current_page_off();
|
||||
}
|
||||
*/
|
||||
// if it wasn't an arrow key etc
|
||||
if (!_handle_edit(ch, input, size)) {
|
||||
if (!_handle_edit(result, ch, input, size)) {
|
||||
if (_printable(ch) && result != KEY_CODE_YES) {
|
||||
inp_x = getcurx(inp_win);
|
||||
|
||||
@@ -248,7 +264,7 @@ _clear_input(void)
|
||||
* return 0 if it wasnt
|
||||
*/
|
||||
static int
|
||||
_handle_edit(const wint_t ch, char *input, int *size)
|
||||
_handle_edit(int result, const wint_t ch, char *input, int *size)
|
||||
{
|
||||
char *prev = NULL;
|
||||
char *next = NULL;
|
||||
@@ -262,6 +278,54 @@ _handle_edit(const wint_t ch, char *input, int *size)
|
||||
|
||||
inp_x = getcurx(inp_win);
|
||||
|
||||
// CTRL-LEFT
|
||||
if ((result == KEY_CODE_YES) && (ch == 540) && (inp_x > 0)) {
|
||||
input[*size] = '\0';
|
||||
gchar *curr_ch = g_utf8_offset_to_pointer(input, inp_x);
|
||||
gchar *prev_ch = g_utf8_find_prev_char(input, curr_ch);
|
||||
|
||||
// no more chars to left, set to beginning
|
||||
if (prev_ch == NULL) {
|
||||
inp_x = 0;
|
||||
wmove(inp_win, 0, inp_x);
|
||||
|
||||
// otherwise, go back to start of previous word
|
||||
} else {
|
||||
gunichar prev_uni = g_utf8_get_char(prev_ch);
|
||||
while (!g_unichar_isspace(prev_uni)) {
|
||||
prev_ch = g_utf8_find_prev_char(input, prev_ch);
|
||||
if (prev_ch != NULL) {
|
||||
prev_uni = g_utf8_get_char(prev_ch);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (prev_ch == NULL) {
|
||||
inp_x = 0;
|
||||
wmove(inp_win, 0, inp_x);
|
||||
} else {
|
||||
glong offset = g_utf8_pointer_to_offset(input, prev_ch);
|
||||
inp_x = offset;
|
||||
wmove(inp_win, 0, inp_x);
|
||||
}
|
||||
}
|
||||
|
||||
// if gone off screen to left, jump left (half a screen worth)
|
||||
if (inp_x <= pad_start) {
|
||||
pad_start = pad_start - (cols / 2);
|
||||
if (pad_start < 0) {
|
||||
pad_start = 0;
|
||||
}
|
||||
|
||||
_inp_win_refresh();
|
||||
}
|
||||
return 1;
|
||||
} else if ((result == KEY_CODE_YES) && (ch == 555)) { // CTRL-RIGHT
|
||||
cons_show("CTRL-RIGHT");
|
||||
win_current_page_off();
|
||||
return 1;
|
||||
} else {
|
||||
switch(ch) {
|
||||
|
||||
case 27: // ESC
|
||||
@@ -396,7 +460,7 @@ _handle_edit(const wint_t ch, char *input, int *size)
|
||||
return 1;
|
||||
|
||||
case KEY_LEFT:
|
||||
if (inp_x > 0)
|
||||
if (inp_x > 0) {
|
||||
wmove(inp_win, 0, inp_x-1);
|
||||
|
||||
// current position off screen to left
|
||||
@@ -404,6 +468,7 @@ _handle_edit(const wint_t ch, char *input, int *size)
|
||||
pad_start--;
|
||||
_inp_win_refresh();
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
case KEY_RIGHT:
|
||||
@@ -449,6 +514,7 @@ _handle_edit(const wint_t ch, char *input, int *size)
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user