add bindings for jumping to first/last row
This commit is contained in:
parent
6d4f833f03
commit
02d7e42037
|
@ -41,6 +41,8 @@ TEXT SELECTION MODE
|
||||||
* ``h``/``j``/``k``/``l`` or arrow keys: move cursor left/down/up/right
|
* ``h``/``j``/``k``/``l`` or arrow keys: move cursor left/down/up/right
|
||||||
* ``$``: end-of-line
|
* ``$``: end-of-line
|
||||||
* ``^``: beginning-of-line
|
* ``^``: beginning-of-line
|
||||||
|
* ``g``: jump to start of first row
|
||||||
|
* ``G``: jump to start of last row
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
29
termite.c
29
termite.c
|
@ -159,21 +159,32 @@ static long last_row(VteTerminal *vte) {
|
||||||
return (long)scroll_upper - 1;
|
return (long)scroll_upper - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void move(VteTerminal *vte, select_info *select, long col, long row) {
|
static void update_scroll(VteTerminal *vte, const select_info *select) {
|
||||||
GtkAdjustment *adjust = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(vte));
|
GtkAdjustment *adjust = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(vte));
|
||||||
double scroll_row = gtk_adjustment_get_value(adjust);
|
double scroll_row = gtk_adjustment_get_value(adjust);
|
||||||
long n_rows = vte_terminal_get_row_count(vte);
|
long n_rows = vte_terminal_get_row_count(vte);
|
||||||
|
|
||||||
const long end_col = vte_terminal_get_column_count(vte) - 1;
|
|
||||||
|
|
||||||
select->cursor_col = CLAMP(select->cursor_col + col, 0, end_col);
|
|
||||||
select->cursor_row = CLAMP(select->cursor_row + row, first_row(vte), last_row(vte));
|
|
||||||
|
|
||||||
if (select->cursor_row < scroll_row) {
|
if (select->cursor_row < scroll_row) {
|
||||||
gtk_adjustment_set_value(adjust, (double)select->cursor_row);
|
gtk_adjustment_set_value(adjust, (double)select->cursor_row);
|
||||||
} else if (select->cursor_row - n_rows >= (long)scroll_row) {
|
} else if (select->cursor_row - n_rows >= (long)scroll_row) {
|
||||||
gtk_adjustment_set_value(adjust, (double)(select->cursor_row - n_rows + 1));
|
gtk_adjustment_set_value(adjust, (double)(select->cursor_row - n_rows + 1));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void move(VteTerminal *vte, select_info *select, long col, long row) {
|
||||||
|
const long end_col = vte_terminal_get_column_count(vte) - 1;
|
||||||
|
|
||||||
|
select->cursor_col = CLAMP(select->cursor_col + col, 0, end_col);
|
||||||
|
select->cursor_row = CLAMP(select->cursor_row + row, first_row(vte), last_row(vte));
|
||||||
|
|
||||||
|
update_scroll(vte, select);
|
||||||
|
update_selection(vte, select);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void move_to_row_start(VteTerminal *vte, select_info *select, long row) {
|
||||||
|
select->cursor_col = 0;
|
||||||
|
select->cursor_row = row;
|
||||||
|
update_scroll(vte, select);
|
||||||
update_selection(vte, select);
|
update_selection(vte, select);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,6 +223,12 @@ gboolean key_press_cb(VteTerminal *vte, GdkEventKey *event, search_panel_info *i
|
||||||
info->select.cursor_col = vte_terminal_get_column_count(vte) - 1;
|
info->select.cursor_col = vte_terminal_get_column_count(vte) - 1;
|
||||||
update_selection(vte, &info->select);
|
update_selection(vte, &info->select);
|
||||||
break;
|
break;
|
||||||
|
case GDK_KEY_g:
|
||||||
|
move_to_row_start(vte, &info->select, first_row(vte));
|
||||||
|
break;
|
||||||
|
case GDK_KEY_G:
|
||||||
|
move_to_row_start(vte, &info->select, last_row(vte));
|
||||||
|
break;
|
||||||
case GDK_KEY_v:
|
case GDK_KEY_v:
|
||||||
toggle_visual(vte, &info->select, SELECT_VISUAL);
|
toggle_visual(vte, &info->select, SELECT_VISUAL);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue