add visual line mode

This commit is contained in:
Daniel Micay 2012-07-06 20:38:46 -04:00
parent 603c99acc7
commit 7443b8fb8b
2 changed files with 27 additions and 12 deletions

View File

@ -36,6 +36,7 @@ TEXT SELECTION MODE
* ``escape``: deactivate selection mode * ``escape``: deactivate selection mode
* ``v``: visual mode * ``v``: visual mode
* ``V``: visual line 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
TODO TODO

View File

@ -25,7 +25,8 @@ typedef enum overlay_mode {
typedef enum select_mode { typedef enum select_mode {
SELECT_OFF = 0, SELECT_OFF = 0,
SELECT_ON, SELECT_ON,
SELECT_VISUAL SELECT_VISUAL,
SELECT_VISUAL_LINE
} select_mode; } select_mode;
typedef struct select_info { typedef struct select_info {
@ -76,7 +77,7 @@ void window_title_cb(VteTerminal *vte, GtkWindow *window) {
} }
static void cursor_moved_cb(VteTerminal *vte, select_info *select) { static void cursor_moved_cb(VteTerminal *vte, select_info *select) {
if (select->mode != SELECT_VISUAL) { if (select->mode == SELECT_OFF || select->mode == SELECT_ON) {
return; // not in visual mode return; // not in visual mode
} }
@ -90,12 +91,22 @@ static void cursor_moved_cb(VteTerminal *vte, select_info *select) {
long begin = select->begin_row * n_columns + select->begin_col; long begin = select->begin_row * n_columns + select->begin_col;
long end = end_row * n_columns + end_col; long end = end_row * n_columns + end_col;
if (begin < end) { if (select->mode == SELECT_VISUAL) {
vte_terminal_select_text(vte, select->begin_col, select->begin_row, if (begin < end) {
end_col, end_row, 0, 0); vte_terminal_select_text(vte, select->begin_col, select->begin_row,
} else { end_col, end_row, 0, 0);
vte_terminal_select_text(vte, end_col, end_row, } else {
select->begin_col, select->begin_row, 0, 0); vte_terminal_select_text(vte, end_col, end_row,
select->begin_col, select->begin_row, 0, 0);
}
} else if (select->mode == SELECT_VISUAL_LINE) {
if (begin < end) {
vte_terminal_select_text(vte, 0, select->begin_row,
n_columns - 1, end_row, 0, 0);
} else {
vte_terminal_select_text(vte, 0, end_row,
n_columns - 1, select->begin_row, 0, 0);
}
} }
vte_terminal_copy_primary(vte); vte_terminal_copy_primary(vte);
@ -111,12 +122,12 @@ static void end_selection(VteTerminal *vte, select_info *select) {
select->mode = SELECT_OFF; select->mode = SELECT_OFF;
} }
static void toggle_visual(VteTerminal *vte, select_info *select) { static void toggle_visual(VteTerminal *vte, select_info *select, select_mode mode) {
if (select->mode == SELECT_VISUAL) { if (select->mode == mode) {
select->mode = SELECT_ON; select->mode = SELECT_ON;
vte_terminal_select_none(vte); vte_terminal_select_none(vte);
} else { } else {
select->mode = SELECT_VISUAL; select->mode = mode;
vte_terminal_get_cursor_position(vte, &select->begin_col, &select->begin_row); vte_terminal_get_cursor_position(vte, &select->begin_col, &select->begin_row);
} }
} }
@ -143,7 +154,10 @@ gboolean key_press_cb(VteTerminal *vte, GdkEventKey *event, search_panel_info *i
vte_terminal_feed(vte, CSI "1C", strlen(CSI "1C")); vte_terminal_feed(vte, CSI "1C", strlen(CSI "1C"));
break; break;
case GDK_KEY_v: case GDK_KEY_v:
toggle_visual(vte, &info->select); toggle_visual(vte, &info->select, SELECT_VISUAL);
break;
case GDK_KEY_V:
toggle_visual(vte, &info->select, SELECT_VISUAL_LINE);
break; break;
case GDK_KEY_Escape: case GDK_KEY_Escape:
end_selection(vte, &info->select); end_selection(vte, &info->select);