Merge pull request #498 from janza/end-of-word-keybinding
Add keybinding to move forward to end of word
This commit is contained in:
commit
5690a82ad0
|
@ -106,10 +106,14 @@ SELECTION MODE
|
|||
+-----------------------------------+-----------------------------------------------------------+
|
||||
| ``w`` or ``shift-right`` | forward word |
|
||||
+-----------------------------------+-----------------------------------------------------------+
|
||||
| ``e`` | forward to end of word |
|
||||
+-----------------------------------+-----------------------------------------------------------+
|
||||
| ``b`` or ``shift-left`` | backward word |
|
||||
+-----------------------------------+-----------------------------------------------------------+
|
||||
| ``W`` or ``ctrl-right`` | forward WORD (non-whitespace) |
|
||||
+-----------------------------------+-----------------------------------------------------------+
|
||||
| ``E`` | forward to end of WORD (non-whitespace) |
|
||||
+-----------------------------------+-----------------------------------------------------------+
|
||||
| ``B`` or ``ctrl-left`` | backward WORD (non-whitespace) |
|
||||
+-----------------------------------+-----------------------------------------------------------+
|
||||
| ``0`` or ``home`` | move cursor to the first column in the row |
|
||||
|
|
29
termite.cc
29
termite.cc
|
@ -675,7 +675,7 @@ static void move_to_eol(VteTerminal *vte, select_info *select) {
|
|||
}
|
||||
|
||||
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;
|
||||
vte_terminal_get_cursor_position(vte, &cursor_col, &cursor_row);
|
||||
|
||||
|
@ -701,6 +701,7 @@ static void move_forward(VteTerminal *vte, select_info *select, F is_word) {
|
|||
|
||||
bool end_of_word = false;
|
||||
|
||||
if (!goto_word_end) {
|
||||
for (long i = 1; i < length; i++) {
|
||||
if (is_word(codepoints[i - 1])) {
|
||||
if (end_of_word) {
|
||||
|
@ -711,18 +712,34 @@ static void move_forward(VteTerminal *vte, select_info *select, F is_word) {
|
|||
}
|
||||
cursor_col++;
|
||||
}
|
||||
} else {
|
||||
for (long i = 2; i <= length; i++) {
|
||||
cursor_col++;
|
||||
if (is_word(codepoints[i - 1]) && !is_word(codepoints[i])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
vte_terminal_set_cursor_position(vte, cursor_col, cursor_row);
|
||||
update_selection(vte, select);
|
||||
|
||||
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) {
|
||||
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) {
|
||||
move_forward(vte, select, std::not1(std::ref(g_unichar_isspace)));
|
||||
move_forward(vte, select, std::not1(std::ref(g_unichar_isspace)), false);
|
||||
}
|
||||
|
||||
/* {{{ CALLBACKS */
|
||||
|
@ -853,6 +870,12 @@ gboolean key_press_cb(VteTerminal *vte, GdkEventKey *event, keybind_info *info)
|
|||
case GDK_KEY_W:
|
||||
move_forward_blank_word(vte, &info->select);
|
||||
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_Home:
|
||||
set_cursor_column(vte, &info->select, 0);
|
||||
|
|
Loading…
Reference in New Issue