Add keybinding to move forward to end of word

Closes #495
This commit is contained in:
Josip Janzic 2017-07-05 22:38:18 +02:00
parent 37309fdd0d
commit c18668fe8e
No known key found for this signature in database
GPG Key ID: 210BC3C60D619EEE
2 changed files with 36 additions and 9 deletions

View File

@ -106,10 +106,14 @@ SELECTION MODE
+-----------------------------------+-----------------------------------------------------------+ +-----------------------------------+-----------------------------------------------------------+
| ``w`` or ``shift-right`` | forward word | | ``w`` or ``shift-right`` | forward word |
+-----------------------------------+-----------------------------------------------------------+ +-----------------------------------+-----------------------------------------------------------+
| ``e`` | forward to end of word |
+-----------------------------------+-----------------------------------------------------------+
| ``b`` or ``shift-left`` | backward word | | ``b`` or ``shift-left`` | backward word |
+-----------------------------------+-----------------------------------------------------------+ +-----------------------------------+-----------------------------------------------------------+
| ``W`` or ``ctrl-right`` | forward WORD (non-whitespace) | | ``W`` or ``ctrl-right`` | forward WORD (non-whitespace) |
+-----------------------------------+-----------------------------------------------------------+ +-----------------------------------+-----------------------------------------------------------+
| ``E`` | forward to end of WORD (non-whitespace) |
+-----------------------------------+-----------------------------------------------------------+
| ``B`` or ``ctrl-left`` | backward WORD (non-whitespace) | | ``B`` or ``ctrl-left`` | backward WORD (non-whitespace) |
+-----------------------------------+-----------------------------------------------------------+ +-----------------------------------+-----------------------------------------------------------+
| ``0`` or ``home`` | move cursor to the first column in the row | | ``0`` or ``home`` | move cursor to the first column in the row |

View File

@ -675,7 +675,7 @@ static void move_to_eol(VteTerminal *vte, select_info *select) {
} }
template<typename F> template<typename F>
static void move_forward(VteTerminal *vte, select_info *select, F is_word) { static void move_forward(VteTerminal *vte, select_info *select, F is_word, bool goto_word_end) {
long cursor_col, cursor_row; long cursor_col, cursor_row;
vte_terminal_get_cursor_position(vte, &cursor_col, &cursor_row); vte_terminal_get_cursor_position(vte, &cursor_col, &cursor_row);
@ -701,15 +701,24 @@ static void move_forward(VteTerminal *vte, select_info *select, F is_word) {
bool end_of_word = false; bool end_of_word = false;
for (long i = 1; i < length; i++) { if (!goto_word_end) {
if (is_word(codepoints[i - 1])) { for (long i = 1; i < length; i++) {
if (end_of_word) { if (is_word(codepoints[i - 1])) {
if (end_of_word) {
break;
}
} else {
end_of_word = true;
}
cursor_col++;
}
} else {
for (long i = 2; i <= length; i++) {
cursor_col++;
if (is_word(codepoints[i - 1]) && !is_word(codepoints[i])) {
break; break;
} }
} else {
end_of_word = true;
} }
cursor_col++;
} }
vte_terminal_set_cursor_position(vte, cursor_col, cursor_row); vte_terminal_set_cursor_position(vte, cursor_col, cursor_row);
update_selection(vte, select); update_selection(vte, select);
@ -717,12 +726,20 @@ static void move_forward(VteTerminal *vte, select_info *select, F is_word) {
g_free(codepoints); g_free(codepoints);
} }
static void move_forward_end_word(VteTerminal *vte, select_info *select) {
move_forward(vte, select, is_word_char, true);
}
static void move_forward_end_blank_word(VteTerminal *vte, select_info *select) {
move_forward(vte, select, std::not1(std::ref(g_unichar_isspace)), true);
}
static void move_forward_word(VteTerminal *vte, select_info *select) { static void move_forward_word(VteTerminal *vte, select_info *select) {
move_forward(vte, select, is_word_char); move_forward(vte, select, is_word_char, false);
} }
static void move_forward_blank_word(VteTerminal *vte, select_info *select) { static void move_forward_blank_word(VteTerminal *vte, select_info *select) {
move_forward(vte, select, std::not1(std::ref(g_unichar_isspace))); move_forward(vte, select, std::not1(std::ref(g_unichar_isspace)), false);
} }
/* {{{ CALLBACKS */ /* {{{ CALLBACKS */
@ -853,6 +870,12 @@ gboolean key_press_cb(VteTerminal *vte, GdkEventKey *event, keybind_info *info)
case GDK_KEY_W: case GDK_KEY_W:
move_forward_blank_word(vte, &info->select); move_forward_blank_word(vte, &info->select);
break; break;
case GDK_KEY_e:
move_forward_end_word(vte, &info->select);
break;
case GDK_KEY_E:
move_forward_end_blank_word(vte, &info->select);
break;
case GDK_KEY_0: case GDK_KEY_0:
case GDK_KEY_Home: case GDK_KEY_Home:
set_cursor_column(vte, &info->select, 0); set_cursor_column(vte, &info->select, 0);