diff options
author | pgen <p.gen.progs@gmail.com> | 2023-10-08 00:00:46 +0200 |
---|---|---|
committer | pgen <p.gen.progs@gmail.com> | 2023-10-08 00:00:46 +0200 |
commit | 8cf08fc2abcd79554551646f313c784f62fa9c07 (patch) | |
tree | 6293e2f1fb2e95d52188e02f1cca404012f91bf6 | |
parent | 03551e4ee8931bbcf75fb2ae13c1e92ce9c969dd (diff) |
Rework the code to go to the beginning/end of line
-rw-r--r-- | smenu.1 | 4 | ||||
-rw-r--r-- | smenu.c | 212 |
2 files changed, 79 insertions, 137 deletions
@@ -211,7 +211,7 @@ The meaning of the movement keys is as follows: tab(@); l l. \fB\(<-\fP, \fBh\fP@Previous word -\fBCTRL\ \(<-\fP, \fBH\fP@Start of line +\fBSHIFT HOME\fP, \fBCTRL\ \(<-\fP, \fBH\fP@Start of line in column or line mode \fB\(ua\fP, \fBk\fP@Previous line \fBPgUp\fP, \fBK\fP@Previous page \fBHOME\fP@First word of the window @@ -220,7 +220,7 @@ l l. @left while keeping the cursor visible \fB\(->\fP, \fBl\fP@Next word -\fBCTRL\ \(->\fP, \fBL\fP@End of line +\fBSHIFT END\fP, \fBCTRL\ \(->\fP, \fBL\fP@End of line in column or line mode \fB\(da\fP, \fBj\fP@Next line \fBPgDn\fP, \fBJ\fP@Next page \fBEND\fP@Last word of the window @@ -13059,12 +13059,6 @@ main(int argc, char *argv[]) /* """"""""""""""""""""""""""""""" */ goto kchome; - if (memcmp("\x1b[1;2H", buffer, 6) == 0 - || memcmp("\x1b[7$", buffer, 4) == 0) - /* SHIFT HOME key has been pressed. */ - /* """"""""""""""""""""""""""""""" */ - goto kshome; - if (memcmp("\x1bOF", buffer, 3) == 0 || memcmp("\x1bj", buffer, 2) == 0 || memcmp("\x1b[F", buffer, 3) == 0 @@ -13119,12 +13113,6 @@ main(int argc, char *argv[]) /* """""""""""""""""""""""""""""" */ goto kcend; - if (memcmp("\x1b[1;2F", buffer, 6) == 0 - || memcmp("\x1b[8$", buffer, 4) == 0) - /* SHIFT END key has been pressed. */ - /* """"""""""""""""""""""""""""""" */ - goto ksend; - if (memcmp("\x1bOD", buffer, 3) == 0 || memcmp("\x1b[D", buffer, 3) == 0) /* Left arrow key has been pressed. */ @@ -13172,16 +13160,20 @@ main(int argc, char *argv[]) /* """"""""""""""""""""""""" */ goto kdel; - if (memcmp("\x1b[1;5C", buffer, 6) == 0 + if (memcmp("\x1b[1;2F", buffer, 6) == 0 + || memcmp("\x1b[1;5C", buffer, 6) == 0 + || memcmp("\x1b[8$", buffer, 4) == 0 || memcmp("\x1bOc", buffer, 3) == 0) - /* CTRL -> has been pressed. */ - /* """""""""""""""""""""""""" */ + /* SHIFT END or CTRL -> has been pressed. */ + /* """""""""""""""""""""""""""""""""""""" */ goto keol; - if (memcmp("\x1b[1;5D", buffer, 6) == 0 + if (memcmp("\x1b[1;2H", buffer, 6) == 0 + || memcmp("\x1b[1;5D", buffer, 6) == 0 + || memcmp("\x1b[7$", buffer, 4) == 0 || memcmp("\x1bOd", buffer, 3) == 0) - /* CTRL <- key has been pressed. */ - /* """"""""""""""""""""""""""""" */ + /* SHIFT HOME or CTRL <- key has been pressed. */ + /* """"""""""""""""""""""""""""""""""""""""""" */ goto ksol; if (!toggles.no_mouse) @@ -13804,24 +13796,46 @@ main(int argc, char *argv[]) case 'H': if (search_mode == NONE) { - current = first_word_in_line_a[line_nb_of_word_a[current]]; + if (win.col_mode || win.line_mode) + { + long pos; - while (!word_a[current].is_selectable) - current++; + pos = first_word_in_line_a[line_nb_of_word_a[current]]; - win.first_column = 0; - set_new_first_column(&win, &term); + search_mode = NONE; - nl = disp_lines(&win, - &toggles, - current, - count, - search_mode, - &search_data, - &term, - last_line, - tmp_word, - &langinfo); + /* Find the first selectable word. */ + /* """"""""""""""""""""""""""""""" */ + while (!word_a[pos].is_last) + { + if (word_a[pos].is_selectable) + { + current = pos; + break; + } + + pos++; + + if (pos > current) + break; + } + + if (word_a[pos].is_last && word_a[pos].is_selectable) + current = pos; + + set_new_first_column(&win, &term); + + nl = disp_lines(&win, + &toggles, + current, + count, + search_mode, + &search_data, + &term, + last_line, + tmp_word, + &langinfo); + } } else goto special_cmds_when_searching; @@ -13851,52 +13865,6 @@ main(int argc, char *argv[]) break; - kshome: - /* SHIFT HOME key has been pressed. */ - /* -> first selectable word in the current line. */ - /* """"""""""""""""""""""""""""""""""""""""""""" */ - if (win.col_mode || win.line_mode) - { - long pos; - - pos = first_word_in_line_a[line_nb_of_word_a[current]]; - - search_mode = NONE; - - /* Find the first selectable word. */ - /* """"""""""""""""""""""""""""""" */ - while (!word_a[pos].is_last) - { - if (word_a[pos].is_selectable) - { - current = pos; - break; - } - - pos++; - - if (pos > current) - break; - } - - if (word_a[pos].is_last && word_a[pos].is_selectable) - current = pos; - - set_new_first_column(&win, &term); - - nl = disp_lines(&win, - &toggles, - current, - count, - search_mode, - &search_data, - &term, - last_line, - tmp_word, - &langinfo); - } - break; - /* shift the window to the left if possible. */ /* """"""""""""""""""""""""""""""""""""""""" */ case '<': @@ -13926,26 +13894,40 @@ main(int argc, char *argv[]) case 'L': if (search_mode == NONE) { - long cur_line = line_nb_of_word_a[current]; + if (win.col_mode || win.line_mode) + { + long pos; - current = get_line_last_word(cur_line, last_line); - win.first_column = win.real_max_width - 1 - (term.ncolumns - 3); + pos = current; - while (!word_a[current].is_selectable) - current--; + search_mode = NONE; - set_new_first_column(&win, &term); + /* Find the first selectable word. */ + /* """"""""""""""""""""""""""""""" */ + while (!word_a[pos].is_last) + { + if (word_a[pos].is_selectable) + current = pos; - nl = disp_lines(&win, - &toggles, - current, - count, - search_mode, - &search_data, - &term, - last_line, - tmp_word, - &langinfo); + pos++; + } + + if (word_a[pos].is_selectable) + current = pos; + + set_new_first_column(&win, &term); + + nl = disp_lines(&win, + &toggles, + current, + count, + search_mode, + &search_data, + &term, + last_line, + tmp_word, + &langinfo); + } } else goto special_cmds_when_searching; @@ -13975,46 +13957,6 @@ main(int argc, char *argv[]) break; - ksend: - /* SHIFT END key has been pressed. */ - /* -> last selectable word in the current line. */ - /* """""""""""""""""""""""""""""""""""""""""""" */ - if (win.col_mode || win.line_mode) - { - long pos; - - pos = current; - - search_mode = NONE; - - /* Find the first selectable word. */ - /* """"""""""""""""""""""""""""""" */ - while (!word_a[pos].is_last) - { - if (word_a[pos].is_selectable) - current = pos; - - pos++; - } - - if (word_a[pos].is_selectable) - current = pos; - - set_new_first_column(&win, &term); - - nl = disp_lines(&win, - &toggles, - current, - count, - search_mode, - &search_data, - &term, - last_line, - tmp_word, - &langinfo); - } - break; - /* shift the window to the left if possible. */ /* """"""""""""""""""""""""""""""""""""""""" */ case '>': |