diff options
author | Andrés <andmarti@gmail.com> | 2021-03-16 17:19:21 -0300 |
---|---|---|
committer | Andrés <andmarti@gmail.com> | 2021-03-16 17:19:21 -0300 |
commit | 4fc2270e774de8f06dd1e479404d20c66d85ce7a (patch) | |
tree | 9b307e611dcecc68d4bc9468b11670dbc436e318 /src/cmds_edit.c | |
parent | bb3616d75bac0cdc27bd4219b2ddd512f9214cd7 (diff) |
EDIT_MODE: Added '^' 'g_' commands
Diffstat (limited to 'src/cmds_edit.c')
-rw-r--r-- | src/cmds_edit.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/cmds_edit.c b/src/cmds_edit.c index 149a812..094ddf0 100644 --- a/src/cmds_edit.c +++ b/src/cmds_edit.c @@ -98,6 +98,23 @@ void do_editmode(struct block * sb) { ui_show_header(); return; + } else if (sb->value == L'^') { // ^ + pos = first_nonblank_char(); + if (pos == -1) return; + real_inputline_pos = pos; + inputline_pos = wcswidth(inputline, real_inputline_pos); + ui_show_header(); + return; + + } else if (sb->value == L'g') { // ^ + if (ui_getch_b(&wi) == -1 || wi != L'_') return; + pos = last_nonblank_char(); + if (pos == -1) return; + real_inputline_pos = pos; + inputline_pos = wcswidth(inputline, real_inputline_pos); + ui_show_header(); + return; + } else if (sb->value == L'0' || sb->value == OKEY_HOME) { // 0 inputline_pos = 0; real_inputline_pos = 0; @@ -499,7 +516,30 @@ int look_back(wchar_t cb) { return -1; } +/** + * \brief Looks for a first non blank char in inputline + * + * \return position if found; -1 otherwise + */ +int first_nonblank_char() { + int cpos = -1; + while (++cpos < wcslen(inputline)) + if (inputline[cpos] && inputline[cpos] != L' ') return cpos; + return -1; +} + +/** + * \brief Looks for the last non blank char in inputline + * + * \return position if found; -1 otherwise + */ +int last_nonblank_char() { + int cpos = wcslen(inputline); + while (--cpos > 0) + if (inputline[cpos] && inputline[cpos] != L' ') return cpos; + return -1; +} /** * \brief Move backward one word @@ -554,7 +594,7 @@ int for_word(int end_of_word, int delete, int big_word) { } /** - * \brief TODO Cocument del_back_char() + * \brief TODO Document del_back_char() * * \return none */ |