fix selection

This commit is contained in:
Piotr Kocia 2025-03-30 12:39:06 +02:00
parent 358155ac7d
commit 66a3e53b31
4 changed files with 84 additions and 89 deletions

16
input.c
View file

@ -503,35 +503,35 @@ execute_binding(struct seat *seat, struct terminal *term,
case BIND_ACTION_SELECT_BEGIN: case BIND_ACTION_SELECT_BEGIN:
selection_start( selection_start(
term, seat->mouse.col, seat->mouse.row, SELECTION_CHAR_WISE, false); term, (struct coord){.row = seat->mouse.row, .col = seat->mouse.col}, SELECTION_CHAR_WISE, false);
return true; return true;
case BIND_ACTION_SELECT_BEGIN_BLOCK: case BIND_ACTION_SELECT_BEGIN_BLOCK:
selection_start( selection_start(
term, seat->mouse.col, seat->mouse.row, SELECTION_BLOCK, false); term, (struct coord){.row = seat->mouse.row, .col = seat->mouse.col}, SELECTION_BLOCK, false);
return true; return true;
case BIND_ACTION_SELECT_EXTEND: case BIND_ACTION_SELECT_EXTEND:
selection_extend( selection_extend(
seat, term, seat->mouse.col, seat->mouse.row, term->selection.kind); seat, term, (struct coord){.row = seat->mouse.row, .col = seat->mouse.col}, term->selection.kind);
return true; return true;
case BIND_ACTION_SELECT_EXTEND_CHAR_WISE: case BIND_ACTION_SELECT_EXTEND_CHAR_WISE:
if (term->selection.kind != SELECTION_BLOCK) { if (term->selection.kind != SELECTION_BLOCK) {
selection_extend( selection_extend(
seat, term, seat->mouse.col, seat->mouse.row, SELECTION_CHAR_WISE); seat, term, (struct coord){.row = seat->mouse.row, .col = seat->mouse.col}, SELECTION_CHAR_WISE);
return true; return true;
} }
return false; return false;
case BIND_ACTION_SELECT_WORD: case BIND_ACTION_SELECT_WORD:
selection_start( selection_start(
term, seat->mouse.col, seat->mouse.row, SELECTION_WORD_WISE, false); term, (struct coord){.row = seat->mouse.row, .col = seat->mouse.col}, SELECTION_WORD_WISE, false);
return true; return true;
case BIND_ACTION_SELECT_WORD_WS: case BIND_ACTION_SELECT_WORD_WS:
selection_start( selection_start(
term, seat->mouse.col, seat->mouse.row, SELECTION_WORD_WISE, true); term, (struct coord){.row = seat->mouse.row, .col = seat->mouse.col}, SELECTION_WORD_WISE, true);
return true; return true;
case BIND_ACTION_SELECT_QUOTE: case BIND_ACTION_SELECT_QUOTE:
@ -541,7 +541,7 @@ execute_binding(struct seat *seat, struct terminal *term,
case BIND_ACTION_SELECT_ROW: case BIND_ACTION_SELECT_ROW:
selection_start( selection_start(
term, seat->mouse.col, seat->mouse.row, SELECTION_LINE_WISE, false); term, (struct coord){.row = seat->mouse.row, .col = seat->mouse.col}, SELECTION_LINE_WISE, false);
return true; return true;
case BIND_ACTION_COUNT: case BIND_ACTION_COUNT:
@ -2786,7 +2786,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
seat->mouse.y >= term->margins.top && seat->mouse.y >= term->margins.top &&
seat->mouse.y < term->height - term->margins.bottom))) seat->mouse.y < term->height - term->margins.bottom)))
{ {
selection_update(term, seat->mouse.col, seat->mouse.row); selection_update(term, (struct coord){.row = seat->mouse.row, .col = seat->mouse.col});
} }
} }

View file

@ -665,7 +665,7 @@ static void selection_start_linewise(struct terminal* const term,
term->selection.pivot.start = term->selection.coords.start; term->selection.pivot.start = term->selection.coords.start;
term->selection.pivot.end = (struct coord){end.col, term->grid->view + end.row}; term->selection.pivot.end = (struct coord){end.col, term->grid->view + end.row};
selection_update(term, end.col, end.row); selection_update(term, end);
} }
// TODO (kociap): The function could be extended to match arbitrary // TODO (kociap): The function could be extended to match arbitrary
@ -723,14 +723,14 @@ void selection_start_matching_delimiters(struct terminal* const term,
term->selection.pivot.end = (struct coord){delimiter_end.col, term->grid->view + delimiter_end.row}; term->selection.pivot.end = (struct coord){delimiter_end.col, term->grid->view + delimiter_end.row};
term->selection.kind = SELECTION_WORD_WISE; term->selection.kind = SELECTION_WORD_WISE;
selection_update(term, delimiter_end.col, delimiter_end.row); selection_update(term, delimiter_end);
} else { } else {
selection_start_linewise(term, start); selection_start_linewise(term, start);
} }
} }
void void
selection_start(struct terminal *term, int col, int row, selection_start(struct terminal *term, struct coord const start,
enum selection_kind kind, enum selection_kind kind,
bool spaces_only) bool spaces_only)
{ {
@ -750,7 +750,7 @@ selection_start(struct terminal *term, int col, int row,
switch (kind) { switch (kind) {
case SELECTION_CHAR_WISE: case SELECTION_CHAR_WISE:
case SELECTION_BLOCK: case SELECTION_BLOCK:
term->selection.coords.start = (struct coord){col, term->grid->view + row}; term->selection.coords.start = (struct coord){start.col, term->grid->view + start.row};
term->selection.coords.end = (struct coord){-1, -1}; term->selection.coords.end = (struct coord){-1, -1};
term->selection.pivot.start = term->selection.coords.start; term->selection.pivot.start = term->selection.coords.start;
@ -758,8 +758,8 @@ selection_start(struct terminal *term, int col, int row,
break; break;
case SELECTION_WORD_WISE: { case SELECTION_WORD_WISE: {
struct coord start = {col, term->grid->view + row}; struct coord start = {start.col, term->grid->view + start.row};
struct coord end = {col, term->grid->view + row}; struct coord end = {start.col, term->grid->view + start.row};
selection_find_word_boundary_left(term, &start, spaces_only); selection_find_word_boundary_left(term, &start, spaces_only);
selection_find_word_boundary_right(term, &end, spaces_only, true); selection_find_word_boundary_right(term, &end, spaces_only, true);
@ -777,12 +777,12 @@ selection_start(struct terminal *term, int col, int row,
* view-local. * view-local.
*/ */
selection_update(term, end.col, end.row - term->grid->view); selection_update(term, (struct coord){end.col, end.row - term->grid->view});
break; break;
} }
case SELECTION_LINE_WISE: case SELECTION_LINE_WISE:
selection_start_linewise(term, (struct coord){.row = row, .col = col}); selection_start_linewise(term, start);
break; break;
case SELECTION_NONE: case SELECTION_NONE:
@ -1133,7 +1133,7 @@ set_pivot_point_for_block_and_char_wise(struct terminal *term,
} }
void void
selection_update(struct terminal *term, int col, int row) selection_update(struct terminal *term, struct coord const updated_end)
{ {
if (term->selection.coords.start.row < 0) if (term->selection.coords.start.row < 0)
return; return;
@ -1141,10 +1141,10 @@ selection_update(struct terminal *term, int col, int row)
if (!term->selection.ongoing) if (!term->selection.ongoing)
return; return;
xassert(term->grid->view + row != -1); xassert(term->grid->view + updated_end.row != -1);
struct coord new_start = term->selection.coords.start; struct coord new_start = term->selection.coords.start;
struct coord new_end = {col, term->grid->view + row}; struct coord new_end = {updated_end.col, term->grid->view + updated_end.row};
LOG_DBG("selection updated: start = %d,%d, end = %d,%d -> %d, %d", LOG_DBG("selection updated: start = %d,%d, end = %d,%d -> %d, %d",
term->selection.coords.start.row, term->selection.coords.start.col, term->selection.coords.start.row, term->selection.coords.start.col,
@ -1211,13 +1211,13 @@ selection_update(struct terminal *term, int col, int row)
case SELECTION_WORD_WISE: case SELECTION_WORD_WISE:
switch (term->selection.direction) { switch (term->selection.direction) {
case SELECTION_LEFT: case SELECTION_LEFT:
new_end = (struct coord){col, term->grid->view + row}; new_end = (struct coord){updated_end.col, term->grid->view + updated_end.row};
selection_find_word_boundary_left( selection_find_word_boundary_left(
term, &new_end, term->selection.spaces_only); term, &new_end, term->selection.spaces_only);
break; break;
case SELECTION_RIGHT: case SELECTION_RIGHT:
new_end = (struct coord){col, term->grid->view + row}; new_end = (struct coord){updated_end.col, term->grid->view + updated_end.row};
selection_find_word_boundary_right( selection_find_word_boundary_right(
term, &new_end, term->selection.spaces_only, true); term, &new_end, term->selection.spaces_only, true);
break; break;
@ -1230,14 +1230,14 @@ selection_update(struct terminal *term, int col, int row)
case SELECTION_LINE_WISE: case SELECTION_LINE_WISE:
switch (term->selection.direction) { switch (term->selection.direction) {
case SELECTION_LEFT: { case SELECTION_LEFT: {
struct coord end = {0, row}; struct coord end = {0, updated_end.row};
selection_find_line_boundary_left(term, &end); selection_find_line_boundary_left(term, &end);
new_end = (struct coord){end.col, term->grid->view + end.row}; new_end = (struct coord){end.col, term->grid->view + end.row};
break; break;
} }
case SELECTION_RIGHT: { case SELECTION_RIGHT: {
struct coord end = {col, row}; struct coord end = updated_end;
selection_find_line_boundary_right(term, &end); selection_find_line_boundary_right(term, &end);
new_end = (struct coord){end.col, term->grid->view + end.row}; new_end = (struct coord){end.col, term->grid->view + end.row};
break; break;
@ -1505,7 +1505,7 @@ selection_extend_block(struct terminal *term, int col, int row)
void void
selection_extend(struct seat *seat, struct terminal *term, selection_extend(struct seat *seat, struct terminal *term,
int col, int row, enum selection_kind new_kind) struct coord point, enum selection_kind new_kind)
{ {
if (term->selection.coords.start.row < 0 || term->selection.coords.end.row < 0) { if (term->selection.coords.start.row < 0 || term->selection.coords.end.row < 0) {
/* No existing selection */ /* No existing selection */
@ -1517,10 +1517,10 @@ selection_extend(struct seat *seat, struct terminal *term,
term->selection.ongoing = true; term->selection.ongoing = true;
row += term->grid->view; point.row += term->grid->view;
if ((row == term->selection.coords.start.row && col == term->selection.coords.start.col) || if ((point.row == term->selection.coords.start.row && point.col == term->selection.coords.start.col) ||
(row == term->selection.coords.end.row && col == term->selection.coords.end.col)) (point.row == term->selection.coords.end.row && point.col == term->selection.coords.end.col))
{ {
/* Extension point *is* one of the current end points */ /* Extension point *is* one of the current end points */
return; return;
@ -1534,11 +1534,11 @@ selection_extend(struct seat *seat, struct terminal *term,
case SELECTION_CHAR_WISE: case SELECTION_CHAR_WISE:
case SELECTION_WORD_WISE: case SELECTION_WORD_WISE:
case SELECTION_LINE_WISE: case SELECTION_LINE_WISE:
selection_extend_normal(term, col, row, new_kind); selection_extend_normal(term, point.col, point.row, new_kind);
break; break;
case SELECTION_BLOCK: case SELECTION_BLOCK:
selection_extend_block(term, col, row); selection_extend_block(term, point.col, point.row);
break; break;
} }
} }
@ -1700,12 +1700,12 @@ fdm_scroll_timer(struct fdm *fdm, int fd, int events, void *data)
case SELECTION_SCROLL_UP: case SELECTION_SCROLL_UP:
cmd_scrollback_up(term, expiration_count); cmd_scrollback_up(term, expiration_count);
selection_update(term, term->selection.auto_scroll.col, 0); selection_update(term, (struct coord){.col = term->selection.auto_scroll.col, .row = 0});
break; break;
case SELECTION_SCROLL_DOWN: case SELECTION_SCROLL_DOWN:
cmd_scrollback_down(term, expiration_count); cmd_scrollback_down(term, expiration_count);
selection_update(term, term->selection.auto_scroll.col, term->rows - 1); selection_update(term, (struct coord){.col = term->selection.auto_scroll.col, .row = term->rows - 1});
break; break;
} }

View file

@ -8,9 +8,8 @@
extern const struct wl_data_device_listener data_device_listener; extern const struct wl_data_device_listener data_device_listener;
extern const struct zwp_primary_selection_device_v1_listener primary_selection_device_listener; extern const struct zwp_primary_selection_device_v1_listener primary_selection_device_listener;
void selection_start( void selection_start(struct terminal *term, struct coord start,
struct terminal *term, int col, int row, enum selection_kind kind, bool spaces_only);
enum selection_kind new_kind, bool spaces_only);
// selection_start_matching_delimiters // selection_start_matching_delimiters
// //
@ -20,18 +19,21 @@ void selection_start(
// Currently, the delimiters are restricted to single quote (') and // Currently, the delimiters are restricted to single quote (') and
// double quote ("). // double quote (").
// //
void selection_start_matching_delimiters(struct terminal* const term, // Parameters:
struct coord const start, // start - coordinate (view-relative) of the start of the selection.
//
void selection_start_matching_delimiters(struct terminal* term,
struct coord start,
bool spaces_only); bool spaces_only);
void selection_update(struct terminal *term, int col, int row); void selection_update(struct terminal *term, struct coord updated_end);
void selection_finalize( void selection_finalize(
struct seat *seat, struct terminal *term, uint32_t serial); struct seat *seat, struct terminal *term, uint32_t serial);
void selection_dirty_cells(struct terminal *term); void selection_dirty_cells(struct terminal *term);
void selection_cancel(struct terminal *term); void selection_cancel(struct terminal *term);
void selection_extend( void selection_extend(
struct seat *seat, struct terminal *term, struct seat *seat, struct terminal *term,
int col, int row, enum selection_kind kind); struct coord point, enum selection_kind kind);
bool selection_on_rows(const struct terminal *term, int start, int end); bool selection_on_rows(const struct terminal *term, int start, int end);
@ -90,11 +92,5 @@ void selection_start_scroll_timer(
enum selection_scroll_direction direction, int col); enum selection_scroll_direction direction, int col);
void selection_stop_scroll_timer(struct terminal *term); void selection_stop_scroll_timer(struct terminal *term);
void selection_find_word_boundary_left(
const struct terminal *term, struct coord *pos, bool spaces_only);
void selection_find_word_boundary_right(
const struct terminal *term, struct coord *pos, bool spaces_only,
bool stop_on_space_to_word_boundary);
struct coord selection_get_start(const struct terminal *term); struct coord selection_get_start(const struct terminal *term);
struct coord selection_get_end(const struct terminal *term); struct coord selection_get_end(const struct terminal *term);

View file

@ -42,11 +42,12 @@ static enum search_direction invert_direction(enum search_direction direction) {
return direction == SEARCH_FORWARD ? SEARCH_BACKWARD : SEARCH_FORWARD; return direction == SEARCH_FORWARD ? SEARCH_BACKWARD : SEARCH_FORWARD;
} }
static struct coord offset_to_view_relative(struct terminal *const term, static struct coord cursor_to_view_relative(struct terminal *const term,
struct coord coord) { struct coord cursor) {
coord.row += term->grid->offset; cursor.row += term->grid->offset;
coord.row -= term->grid->view; cursor.row -= term->grid->view;
return coord; return cursor;
}
} }
static struct coord view_to_offset_relative(struct terminal *const term, static struct coord view_to_offset_relative(struct terminal *const term,
@ -86,7 +87,7 @@ static struct coord delta_cursor_to_abs_coord(struct terminal *const term,
static void damage_cursor_cell(struct terminal *const term) { static void damage_cursor_cell(struct terminal *const term) {
struct coord const cursor = struct coord const cursor =
offset_to_view_relative(term, term->vimode.cursor); cursor_to_view_relative(term, term->vimode.cursor);
term_damage_cell_in_view(term, cursor.row, cursor.col); term_damage_cell_in_view(term, cursor.row, cursor.col);
render_refresh(term); render_refresh(term);
} }
@ -131,30 +132,31 @@ static void center_view_on_cursor(struct terminal *const term) {
} }
} }
static void update_selection(struct seat *const seat, static void update_selection(struct terminal *const term) {
struct terminal *const term) {
enum vi_mode const mode = term->vimode.mode; enum vi_mode const mode = term->vimode.mode;
if (is_mode_visual(mode)) { if (is_mode_visual(mode)) {
struct coord const cursor = term->grid->cursor.point; struct coord const cursor =
printf("UPDATING SELECTION [row=%d; col=%d]\n", cursor.row, cursor.col); cursor_to_view_relative(term, term->vimode.cursor);
selection_update(term, cursor.col, cursor.row); selection_update(term, cursor);
printf("UPDATING SELECTION [row=%d; col=%d; selection.start=(%d,%d); "
"selection.end=(%d,%d)]\n",
cursor.row, cursor.col, term->selection.coords.start.row,
term->selection.coords.start.col, term->selection.coords.end.row,
term->selection.coords.end.col);
} }
} }
static void damage_highlights(struct terminal *const term) { static void damage_highlights(struct terminal *const term) {
struct highlight_location const *location = term->vimode.highlights; struct highlight_location const *location = term->vimode.highlights;
int const offset = term->grid->offset; int const offset = term->grid->offset;
printf("DAMAGING HIGHLIGHT CELLS: ");
while (location != NULL) { while (location != NULL) {
struct coord const start = location->range.start; struct coord const start = location->range.start;
struct coord const end = location->range.end; struct coord const end = location->range.end;
for (int col = start.col; col <= end.col; col += 1) { for (int col = start.col; col <= end.col; col += 1) {
printf("(%d, %d) ", start.row, col);
term_damage_cell(term, start.row - offset, col); term_damage_cell(term, start.row - offset, col);
} }
location = location->next; location = location->next;
} }
printf("\n");
render_refresh(term); render_refresh(term);
} }
@ -225,15 +227,10 @@ static void update_highlights(struct terminal *const term) {
clear_highlights(term); clear_highlights(term);
calculate_highlight_regions(term); calculate_highlight_regions(term);
struct highlight_location const *location = term->vimode.highlights; struct highlight_location const *location = term->vimode.highlights;
printf("NEW HIGHLIGHT REGIONS: ");
while (location != NULL) { while (location != NULL) {
struct highlight_location const *next = location->next; struct highlight_location const *next = location->next;
printf("[(%d, %d) - (%d, %d)] ", location->range.start.row,
location->range.start.col, location->range.end.row,
location->range.end.col);
location = next; location = next;
} }
printf("\n");
damage_highlights(term); damage_highlights(term);
} }
@ -407,6 +404,7 @@ void vimode_cancel(struct terminal *term) {
cancel_search(term, false); cancel_search(term, false);
clear_highlights(term); clear_highlights(term);
selection_cancel(term);
term->is_vimming = false; term->is_vimming = false;
@ -416,7 +414,6 @@ void vimode_cancel(struct terminal *term) {
term_ime_enable(term); term_ime_enable(term);
} }
selection_cancel(term);
struct grid *const grid = term->grid; struct grid *const grid = term->grid;
grid->view = grid->offset; grid->view = grid->offset;
term_damage_view(term); term_damage_view(term);
@ -810,7 +807,7 @@ void vimode_view_down(struct terminal *const term, int const delta) {
static void move_cursor_delta(struct terminal *const term, static void move_cursor_delta(struct terminal *const term,
struct coord const delta) { struct coord const delta) {
damage_cursor_cell(term); damage_cursor_cell(term);
struct coord cursor = offset_to_view_relative(term, term->vimode.cursor); struct coord cursor = cursor_to_view_relative(term, term->vimode.cursor);
cursor.row += delta.row; cursor.row += delta.row;
cursor.col += delta.col; cursor.col += delta.col;
@ -872,72 +869,73 @@ static void execute_vimode_binding(struct seat *seat, struct terminal *term,
if (term->grid != &term->normal) { if (term->grid != &term->normal) {
return; return;
} }
printf("PRE-ACTION DATA [offset=%d; view=%d]\n", term->grid->offset,
term->grid->view);
switch (action) { switch (action) {
case BIND_ACTION_VIMODE_NONE: case BIND_ACTION_VIMODE_NONE:
break; break;
case BIND_ACTION_VIMODE_UP: case BIND_ACTION_VIMODE_UP:
move_cursor_vertical(term, -1); move_cursor_vertical(term, -1);
update_selection(seat, term); update_selection(term);
update_highlights(term); update_highlights(term);
break; break;
case BIND_ACTION_VIMODE_DOWN: case BIND_ACTION_VIMODE_DOWN:
move_cursor_vertical(term, 1); move_cursor_vertical(term, 1);
update_selection(seat, term); update_selection(term);
update_highlights(term); update_highlights(term);
break; break;
case BIND_ACTION_VIMODE_LEFT: case BIND_ACTION_VIMODE_LEFT:
move_cursor_horizontal(term, -1); move_cursor_horizontal(term, -1);
update_selection(seat, term); update_selection(term);
break; break;
case BIND_ACTION_VIMODE_RIGHT: case BIND_ACTION_VIMODE_RIGHT:
move_cursor_horizontal(term, 1); move_cursor_horizontal(term, 1);
update_selection(seat, term); update_selection(term);
break; break;
case BIND_ACTION_VIMODE_UP_PAGE: case BIND_ACTION_VIMODE_UP_PAGE:
cmd_scrollback_up(term, term->rows); cmd_scrollback_up(term, term->rows);
clip_cursor_to_view(term); clip_cursor_to_view(term);
update_selection(seat, term); update_selection(term);
update_highlights(term); update_highlights(term);
break; break;
case BIND_ACTION_VIMODE_DOWN_PAGE: case BIND_ACTION_VIMODE_DOWN_PAGE:
cmd_scrollback_down(term, term->rows); cmd_scrollback_down(term, term->rows);
clip_cursor_to_view(term); clip_cursor_to_view(term);
update_selection(seat, term); update_selection(term);
update_highlights(term); update_highlights(term);
break; break;
case BIND_ACTION_VIMODE_UP_HALF_PAGE: case BIND_ACTION_VIMODE_UP_HALF_PAGE:
cmd_scrollback_up(term, max(term->rows / 2, 1)); cmd_scrollback_up(term, max(term->rows / 2, 1));
clip_cursor_to_view(term); clip_cursor_to_view(term);
update_selection(seat, term); update_selection(term);
update_highlights(term); update_highlights(term);
break; break;
case BIND_ACTION_VIMODE_DOWN_HALF_PAGE: case BIND_ACTION_VIMODE_DOWN_HALF_PAGE:
cmd_scrollback_down(term, max(term->rows / 2, 1)); cmd_scrollback_down(term, max(term->rows / 2, 1));
clip_cursor_to_view(term); clip_cursor_to_view(term);
update_selection(seat, term); update_selection(term);
update_highlights(term); update_highlights(term);
break; break;
case BIND_ACTION_VIMODE_UP_LINE: case BIND_ACTION_VIMODE_UP_LINE:
cmd_scrollback_up(term, 1); cmd_scrollback_up(term, 1);
clip_cursor_to_view(term); clip_cursor_to_view(term);
update_selection(seat, term); update_selection(term);
update_highlights(term); update_highlights(term);
break; break;
case BIND_ACTION_VIMODE_DOWN_LINE: case BIND_ACTION_VIMODE_DOWN_LINE:
cmd_scrollback_down(term, 1); cmd_scrollback_down(term, 1);
clip_cursor_to_view(term); clip_cursor_to_view(term);
update_selection(seat, term); update_selection(term);
update_highlights(term); update_highlights(term);
break; break;
@ -947,7 +945,7 @@ static void execute_vimode_binding(struct seat *seat, struct terminal *term,
int const view_row = view_to_scrollback_relative(term); int const view_row = view_to_scrollback_relative(term);
term->vimode.cursor.row = cursor_from_scrollback_relative(term, view_row); term->vimode.cursor.row = cursor_from_scrollback_relative(term, view_row);
damage_cursor_cell(term); damage_cursor_cell(term);
update_selection(seat, term); update_selection(term);
update_highlights(term); update_highlights(term);
break; break;
} }
@ -957,7 +955,7 @@ static void execute_vimode_binding(struct seat *seat, struct terminal *term,
damage_cursor_cell(term); damage_cursor_cell(term);
term->vimode.cursor.row = term->rows - 1; term->vimode.cursor.row = term->rows - 1;
damage_cursor_cell(term); damage_cursor_cell(term);
update_selection(seat, term); update_selection(term);
update_highlights(term); update_highlights(term);
break; break;
@ -1003,8 +1001,8 @@ static void execute_vimode_binding(struct seat *seat, struct terminal *term,
grid_row_abs_to_sb(term->grid, term->rows, match.start.row), grid_row_abs_to_sb(term->grid, term->rows, match.start.row),
cursor_to_scrollback_relative(term, term->vimode.cursor.row), cursor_to_scrollback_relative(term, term->vimode.cursor.row),
match.start.row, match.start.col); match.start.row, match.start.col);
// TODO (kociap): update selection.
move_cursor_delta(term, delta); move_cursor_delta(term, delta);
update_selection(term);
} }
update_highlights(term); update_highlights(term);
break; break;
@ -1030,19 +1028,20 @@ static void execute_vimode_binding(struct seat *seat, struct terminal *term,
} else { } else {
selection_cancel(term); selection_cancel(term);
struct coord const start = term->vimode.selection.start; struct coord const start = term->vimode.selection.start;
selection_start(term, start.col, start.row, selection, false); selection_start(term, start, selection, false);
struct coord const cursor = term->grid->cursor.point; struct coord const cursor =
selection_update(term, cursor.col, cursor.row); cursor_to_view_relative(term, term->vimode.cursor);
selection_update(term, cursor);
term->vimode.mode = mode; term->vimode.mode = mode;
} }
} else if (term->vimode.mode == VI_MODE_NORMAL) { } else if (term->vimode.mode == VI_MODE_NORMAL) {
struct coord const cursor = term->grid->cursor.point; struct coord const cursor =
selection_start(term, cursor.col, cursor.row, selection, false); cursor_to_view_relative(term, term->vimode.cursor);
selection_update(term, cursor.col, cursor.row); selection_start(term, cursor, selection, false);
// selection_update(term, cursor.col, cursor.row);
term->vimode.selection.start = cursor; term->vimode.selection.start = cursor;
term->vimode.mode = mode; term->vimode.mode = mode;
} }
// render_refresh(term);
break; break;
} }
@ -1050,8 +1049,8 @@ static void execute_vimode_binding(struct seat *seat, struct terminal *term,
// TODO (kociap): Should yank executed in non-visual mode copy the // TODO (kociap): Should yank executed in non-visual mode copy the
// current line? // current line?
if (is_mode_visual(term->vimode.mode)) { if (is_mode_visual(term->vimode.mode)) {
// Copy, clear the selection and exit the visual mode.
selection_finalize(seat, term, serial); selection_finalize(seat, term, serial);
// finalize only copies, but we also want to clear the selection
selection_cancel(term); selection_cancel(term);
term->vimode.mode = VI_MODE_NORMAL; term->vimode.mode = VI_MODE_NORMAL;
} }
@ -1113,9 +1112,9 @@ static void execute_vimode_search_binding(struct seat *seat,
grid_row_abs_to_sb(term->grid, term->rows, search->match.row), grid_row_abs_to_sb(term->grid, term->rows, search->match.row),
cursor_to_scrollback_relative(term, term->vimode.cursor.row), cursor_to_scrollback_relative(term, term->vimode.cursor.row),
search->match.row, search->match.col); search->match.row, search->match.col);
// TODO (kociap): update selection.
move_cursor_delta(term, delta); move_cursor_delta(term, delta);
center_view_on_cursor(term); center_view_on_cursor(term);
update_selection(term);
} }
confirm_search(term); confirm_search(term);
break; break;
@ -1265,12 +1264,12 @@ void vimode_input(struct seat *seat, struct terminal *term,
term->vimode.search.match_len = term->vimode.search.len; term->vimode.search.match_len = term->vimode.search.len;
struct coord const delta = struct coord const delta =
delta_cursor_to_abs_coord(term, term->vimode.search.match); delta_cursor_to_abs_coord(term, term->vimode.search.match);
// TODO (kociap): update selection.
move_cursor_delta(term, delta); move_cursor_delta(term, delta);
center_view_on_cursor(term); center_view_on_cursor(term);
} else { } else {
restore_pre_search_state(term); restore_pre_search_state(term);
} }
update_selection(term);
update_highlights(term); update_highlights(term);
} }
} }