From 30de262d29d703b0cc31799a4abf84239f3caf22 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 2 Jan 2021 21:20:41 +0100 Subject: selection: wip: update selection word-wise when initial selection was by word --- selection.c | 139 +++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 85 insertions(+), 54 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index db5a0b9f..3653fa1b 100644 --- a/selection.c +++ b/selection.c @@ -238,7 +238,7 @@ selection_to_text(const struct terminal *term) void selection_start(struct terminal *term, int col, int row, - enum selection_kind kind) + enum selection_kind kind, enum selection_semantic semantic) { selection_cancel(term); @@ -248,6 +248,7 @@ selection_start(struct terminal *term, int col, int row, row, col); term->selection.kind = kind; + term->selection.semantic = semantic; term->selection.start = (struct coord){col, term->grid->view + row}; term->selection.end = (struct coord){-1, -1}; term->selection.ongoing = true; @@ -360,6 +361,68 @@ selection_modify(struct terminal *term, struct coord start, struct coord end) render_refresh(term); } +static void +find_word_boundary_left(struct terminal *term, struct coord *pos, + bool spaces_only) +{ + const struct row *r = grid_row_in_view(term->grid, pos->row); + wchar_t c = r->cells[pos->col].wc; + + if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) { + while (true) { + int next_col = pos->col - 1; + int next_row = pos->row; + + /* Linewrap */ + if (next_col < 0) { + next_col = term->cols - 1; + if (--next_row < 0) + break; + } + + const struct row *row = grid_row_in_view(term->grid, next_row); + + c = row->cells[next_col].wc; + if (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters)) + break; + + pos->col = next_col; + pos->row = next_row; + } + } +} + +static void +find_word_boundary_right(struct terminal *term, struct coord *pos, + bool spaces_only) +{ + const struct row *r = grid_row_in_view(term->grid, pos->row); + wchar_t c = r->cells[pos->col].wc; + + if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) { + while (true) { + int next_col = pos->col + 1; + int next_row = pos->row; + + /* Linewrap */ + if (next_col >= term->cols) { + next_col = 0; + if (++next_row >= term->rows) + break; + } + + const struct row *row = grid_row_in_view(term->grid, next_row); + + c = row->cells[next_col].wc; + if (c == '\0' || !isword(c, spaces_only, term->conf->word_delimiters)) + break; + + pos->col = next_col; + pos->row = next_row; + } + } +} + void selection_update(struct terminal *term, int col, int row) { @@ -434,6 +497,22 @@ selection_update(struct terminal *term, int col, int row) } } + if (term->selection.semantic == SELECTION_SEMANTIC_WORD) { + switch (term->selection.direction) { + case SELECTION_LEFT: + find_word_boundary_left(term, &new_end, false); + break; + + case SELECTION_RIGHT: + find_word_boundary_right(term, &new_end, false); + break; + + case SELECTION_UNDIR: + assert(false); + break; + } + } + /* If an end point is in the middle of a multi-column character, * expand the selection to cover the entire character */ if (new_start.row < new_end.row || @@ -742,59 +821,11 @@ selection_mark_word(struct seat *seat, struct terminal *term, int col, int row, struct coord start = {col, row}; struct coord end = {col, row}; - const struct row *r = grid_row_in_view(term->grid, start.row); - wchar_t c = r->cells[start.col].wc; - - if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) { - while (true) { - int next_col = start.col - 1; - int next_row = start.row; - - /* Linewrap */ - if (next_col < 0) { - next_col = term->cols - 1; - if (--next_row < 0) - break; - } - - const struct row *row = grid_row_in_view(term->grid, next_row); - - c = row->cells[next_col].wc; - if (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters)) - break; - - start.col = next_col; - start.row = next_row; - } - } - - r = grid_row_in_view(term->grid, end.row); - c = r->cells[end.col].wc; - - if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) { - while (true) { - int next_col = end.col + 1; - int next_row = end.row; - - /* Linewrap */ - if (next_col >= term->cols) { - next_col = 0; - if (++next_row >= term->rows) - break; - } - - const struct row *row = grid_row_in_view(term->grid, next_row); - - c = row->cells[next_col].wc; - if (c == '\0' || !isword(c, spaces_only, term->conf->word_delimiters)) - break; - - end.col = next_col; - end.row = next_row; - } - } + find_word_boundary_left(term, &start, spaces_only); + find_word_boundary_right(term, &end, spaces_only); - selection_start(term, start.col, start.row, SELECTION_NORMAL); + selection_start(term, start.col, start.row, + SELECTION_NORMAL, SELECTION_SEMANTIC_WORD); selection_update(term, end.col, end.row); selection_finalize(seat, term, serial); } @@ -803,7 +834,7 @@ void selection_mark_row( struct seat *seat, struct terminal *term, int row, uint32_t serial) { - selection_start(term, 0, row, SELECTION_NORMAL); + selection_start(term, 0, row, SELECTION_NORMAL, SELECTION_SEMANTIC_NONE); selection_update(term, term->cols - 1, row); selection_finalize(seat, term, serial); } -- cgit v1.3 From 55ecf29a36ac404ad41eb0050ff01caa35c3cb39 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 2 Jan 2021 21:26:28 +0100 Subject: selection: wip: update selection row-wise when initial selection was by row --- selection.c | 25 +++++++++++++++++++++++-- terminal.h | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 3653fa1b..615088d8 100644 --- a/selection.c +++ b/selection.c @@ -497,7 +497,11 @@ selection_update(struct terminal *term, int col, int row) } } - if (term->selection.semantic == SELECTION_SEMANTIC_WORD) { + switch (term->selection.semantic) { + case SELECTION_SEMANTIC_NONE: + break; + + case SELECTION_SEMANTIC_WORD: switch (term->selection.direction) { case SELECTION_LEFT: find_word_boundary_left(term, &new_end, false); @@ -511,6 +515,23 @@ selection_update(struct terminal *term, int col, int row) assert(false); break; } + break; + + case SELECTION_SEMANTIC_ROW: + switch (term->selection.direction) { + case SELECTION_LEFT: + new_end.col = 0; + break; + + case SELECTION_RIGHT: + new_end.col = term->cols - 1; + break; + + case SELECTION_UNDIR: + assert(false); + break; + } + break; } /* If an end point is in the middle of a multi-column character, @@ -834,7 +855,7 @@ void selection_mark_row( struct seat *seat, struct terminal *term, int row, uint32_t serial) { - selection_start(term, 0, row, SELECTION_NORMAL, SELECTION_SEMANTIC_NONE); + selection_start(term, 0, row, SELECTION_NORMAL, SELECTION_SEMANTIC_ROW); selection_update(term, term->cols - 1, row); selection_finalize(seat, term, serial); } diff --git a/terminal.h b/terminal.h index 8d032d20..c158d214 100644 --- a/terminal.h +++ b/terminal.h @@ -181,7 +181,7 @@ enum mouse_reporting { enum cursor_style { CURSOR_BLOCK, CURSOR_UNDERLINE, CURSOR_BAR }; enum selection_kind { SELECTION_NONE, SELECTION_NORMAL, SELECTION_BLOCK }; -enum selection_semantic { SELECTION_SEMANTIC_NONE, SELECTION_SEMANTIC_WORD}; +enum selection_semantic { SELECTION_SEMANTIC_NONE, SELECTION_SEMANTIC_WORD, SELECTION_SEMANTIC_ROW}; enum selection_direction {SELECTION_UNDIR, SELECTION_LEFT, SELECTION_RIGHT}; enum selection_scroll_direction {SELECTION_SCROLL_NOT, SELECTION_SCROLL_UP, SELECTION_SCROLL_DOWN}; -- cgit v1.3 From bef69cb9610fc296c001974fa85e0289d21f55c2 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 2 Jan 2021 21:38:41 +0100 Subject: selection: remember whether word-wise selection uses spaces only for delimiters --- selection.c | 6 ++++-- terminal.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 615088d8..7e21ecdb 100644 --- a/selection.c +++ b/selection.c @@ -504,11 +504,11 @@ selection_update(struct terminal *term, int col, int row) case SELECTION_SEMANTIC_WORD: switch (term->selection.direction) { case SELECTION_LEFT: - find_word_boundary_left(term, &new_end, false); + find_word_boundary_left(term, &new_end, term->selection.spaces_only); break; case SELECTION_RIGHT: - find_word_boundary_right(term, &new_end, false); + find_word_boundary_right(term, &new_end, term->selection.spaces_only); break; case SELECTION_UNDIR: @@ -847,6 +847,8 @@ selection_mark_word(struct seat *seat, struct terminal *term, int col, int row, selection_start(term, start.col, start.row, SELECTION_NORMAL, SELECTION_SEMANTIC_WORD); + term->selection.spaces_only = spaces_only; + selection_update(term, end.col, end.row); selection_finalize(seat, term, serial); } diff --git a/terminal.h b/terminal.h index c158d214..52eb0a84 100644 --- a/terminal.h +++ b/terminal.h @@ -365,6 +365,7 @@ struct terminal { struct coord start; struct coord end; bool ongoing; + bool spaces_only; /* SELECTION_SEMANTIC_WORD */ struct { int fd; -- cgit v1.3 From 3dd6b7e4ef7204802fa96b4f861a185178cfc447 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 2 Jan 2021 22:40:33 +0100 Subject: selection: don’t finalize selection when starting a word/row-based selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- selection.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 7e21ecdb..c4eeba02 100644 --- a/selection.c +++ b/selection.c @@ -850,7 +850,6 @@ selection_mark_word(struct seat *seat, struct terminal *term, int col, int row, term->selection.spaces_only = spaces_only; selection_update(term, end.col, end.row); - selection_finalize(seat, term, serial); } void @@ -859,7 +858,6 @@ selection_mark_row( { selection_start(term, 0, row, SELECTION_NORMAL, SELECTION_SEMANTIC_ROW); selection_update(term, term->cols - 1, row); - selection_finalize(seat, term, serial); } static bool -- cgit v1.3 From 3afc5a723e10313f956234cfd4251ba7a5a7e99c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 2 Jan 2021 23:00:54 +0100 Subject: selection: use selection_start() to initialize word/row-based selection This removes the selection_mark_word() and selection_mark_row() functions. To start a word/row-based selection, use selection_start() with SELECTION_SEMANTIC_{WORD,ROW} --- input.c | 17 +++--- search.c | 2 +- selection.c | 183 ++++++++++++++++++++++++++++++------------------------------ selection.h | 9 +-- 4 files changed, 104 insertions(+), 107 deletions(-) (limited to 'selection.c') diff --git a/input.c b/input.c index 0b45c5ad..d046bb4a 100644 --- a/input.c +++ b/input.c @@ -276,7 +276,7 @@ execute_binding(struct seat *seat, struct terminal *term, if (selection_enabled(term, seat) && cursor_is_on_grid) { selection_start( term, seat->mouse.col, seat->mouse.row, - SELECTION_NORMAL, SELECTION_SEMANTIC_NONE); + SELECTION_NORMAL, SELECTION_SEMANTIC_NONE, false); return true; } return false; @@ -285,7 +285,7 @@ execute_binding(struct seat *seat, struct terminal *term, if (selection_enabled(term, seat) && cursor_is_on_grid) { selection_start( term, seat->mouse.col, seat->mouse.row, - SELECTION_BLOCK, SELECTION_SEMANTIC_NONE); + SELECTION_BLOCK, SELECTION_SEMANTIC_NONE, false); return true; } return false; @@ -300,23 +300,26 @@ execute_binding(struct seat *seat, struct terminal *term, case BIND_ACTION_SELECT_WORD: if (selection_enabled(term, seat) && cursor_is_on_grid) { - selection_mark_word( - seat, term, seat->mouse.col, seat->mouse.row, false, serial); + selection_start( + term, seat->mouse.col, seat->mouse.row, + SELECTION_NORMAL, SELECTION_SEMANTIC_WORD, false); return true; } return false; case BIND_ACTION_SELECT_WORD_WS: if (selection_enabled(term, seat) && cursor_is_on_grid) { - selection_mark_word( - seat, term, seat->mouse.col, seat->mouse.row, true, serial); + selection_start( + term, seat->mouse.col, seat->mouse.row, + SELECTION_NORMAL, SELECTION_SEMANTIC_WORD, true); return true; } return false; case BIND_ACTION_SELECT_ROW: if (selection_enabled(term, seat) && cursor_is_on_grid) { - selection_mark_row(seat, term, seat->mouse.row, serial); + selection_start(term, seat->mouse.col, seat->mouse.row, + SELECTION_NORMAL, SELECTION_SEMANTIC_ROW, false); return true; } return false; diff --git a/search.c b/search.c index 034fc7c9..c4fd8f05 100644 --- a/search.c +++ b/search.c @@ -223,7 +223,7 @@ search_update_selection(struct terminal *term, assert(selection_row >= 0 && selection_row < term->grid->num_rows); selection_start(term, start_col, selection_row, - SELECTION_NORMAL, SELECTION_SEMANTIC_NONE); + SELECTION_NORMAL, SELECTION_SEMANTIC_NONE, false); } /* Update selection endpoint */ diff --git a/selection.c b/selection.c index c4eeba02..4b7baf13 100644 --- a/selection.c +++ b/selection.c @@ -236,9 +236,73 @@ selection_to_text(const struct terminal *term) return extract_finish(ctx, &text, NULL) ? text : NULL; } +static void +find_word_boundary_left(struct terminal *term, struct coord *pos, + bool spaces_only) +{ + const struct row *r = grid_row_in_view(term->grid, pos->row); + wchar_t c = r->cells[pos->col].wc; + + if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) { + while (true) { + int next_col = pos->col - 1; + int next_row = pos->row; + + /* Linewrap */ + if (next_col < 0) { + next_col = term->cols - 1; + if (--next_row < 0) + break; + } + + const struct row *row = grid_row_in_view(term->grid, next_row); + + c = row->cells[next_col].wc; + if (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters)) + break; + + pos->col = next_col; + pos->row = next_row; + } + } +} + +static void +find_word_boundary_right(struct terminal *term, struct coord *pos, + bool spaces_only) +{ + const struct row *r = grid_row_in_view(term->grid, pos->row); + wchar_t c = r->cells[pos->col].wc; + + if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) { + while (true) { + int next_col = pos->col + 1; + int next_row = pos->row; + + /* Linewrap */ + if (next_col >= term->cols) { + next_col = 0; + if (++next_row >= term->rows) + break; + } + + const struct row *row = grid_row_in_view(term->grid, next_row); + + c = row->cells[next_col].wc; + if (c == '\0' || !isword(c, spaces_only, term->conf->word_delimiters)) + break; + + pos->col = next_col; + pos->row = next_row; + } + } +} + void selection_start(struct terminal *term, int col, int row, - enum selection_kind kind, enum selection_semantic semantic) + enum selection_kind kind, + enum selection_semantic semantic, + bool spaces_only) { selection_cancel(term); @@ -249,9 +313,33 @@ selection_start(struct terminal *term, int col, int row, term->selection.kind = kind; term->selection.semantic = semantic; - term->selection.start = (struct coord){col, term->grid->view + row}; - term->selection.end = (struct coord){-1, -1}; term->selection.ongoing = true; + term->selection.spaces_only = spaces_only; + + + switch (semantic) { + case SELECTION_SEMANTIC_NONE: + term->selection.start = (struct coord){col, term->grid->view + row}; + term->selection.end = (struct coord){-1, -1}; + break; + + case SELECTION_SEMANTIC_WORD: { + struct coord start = {col, row}, end = {col, row}; + find_word_boundary_left(term, &start, spaces_only); + find_word_boundary_right(term, &end, spaces_only); + + term->selection.start = (struct coord){ + start.col, term->grid->view + start.row}; + + selection_update(term, end.col, end.row); + break; + } + + case SELECTION_SEMANTIC_ROW: + term->selection.start = (struct coord){0, term->grid->view + row}; + selection_update(term, term->cols - 1, row); + break; + } } /* Context used while (un)marking selected cells, to be able to @@ -361,68 +449,6 @@ selection_modify(struct terminal *term, struct coord start, struct coord end) render_refresh(term); } -static void -find_word_boundary_left(struct terminal *term, struct coord *pos, - bool spaces_only) -{ - const struct row *r = grid_row_in_view(term->grid, pos->row); - wchar_t c = r->cells[pos->col].wc; - - if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) { - while (true) { - int next_col = pos->col - 1; - int next_row = pos->row; - - /* Linewrap */ - if (next_col < 0) { - next_col = term->cols - 1; - if (--next_row < 0) - break; - } - - const struct row *row = grid_row_in_view(term->grid, next_row); - - c = row->cells[next_col].wc; - if (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters)) - break; - - pos->col = next_col; - pos->row = next_row; - } - } -} - -static void -find_word_boundary_right(struct terminal *term, struct coord *pos, - bool spaces_only) -{ - const struct row *r = grid_row_in_view(term->grid, pos->row); - wchar_t c = r->cells[pos->col].wc; - - if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) { - while (true) { - int next_col = pos->col + 1; - int next_row = pos->row; - - /* Linewrap */ - if (next_col >= term->cols) { - next_col = 0; - if (++next_row >= term->rows) - break; - } - - const struct row *row = grid_row_in_view(term->grid, next_row); - - c = row->cells[next_col].wc; - if (c == '\0' || !isword(c, spaces_only, term->conf->word_delimiters)) - break; - - pos->col = next_col; - pos->row = next_row; - } - } -} - void selection_update(struct terminal *term, int col, int row) { @@ -833,33 +859,6 @@ selection_primary_unset(struct seat *seat) primary->text = NULL; } -void -selection_mark_word(struct seat *seat, struct terminal *term, int col, int row, - bool spaces_only, uint32_t serial) -{ - selection_cancel(term); - - struct coord start = {col, row}; - struct coord end = {col, row}; - - find_word_boundary_left(term, &start, spaces_only); - find_word_boundary_right(term, &end, spaces_only); - - selection_start(term, start.col, start.row, - SELECTION_NORMAL, SELECTION_SEMANTIC_WORD); - term->selection.spaces_only = spaces_only; - - selection_update(term, end.col, end.row); -} - -void -selection_mark_row( - struct seat *seat, struct terminal *term, int row, uint32_t serial) -{ - selection_start(term, 0, row, SELECTION_NORMAL, SELECTION_SEMANTIC_ROW); - selection_update(term, term->cols - 1, row); -} - static bool fdm_scroll_timer(struct fdm *fdm, int fd, int events, void *data) { diff --git a/selection.h b/selection.h index db83ef83..21e983e8 100644 --- a/selection.h +++ b/selection.h @@ -11,7 +11,8 @@ extern const struct zwp_primary_selection_device_v1_listener primary_selection_d bool selection_enabled(const struct terminal *term, struct seat *seat); void selection_start( struct terminal *term, int col, int row, - enum selection_kind kind, enum selection_semantic semantic); + enum selection_kind kind, enum selection_semantic semantic, + bool spaces_only); void selection_update(struct terminal *term, int col, int row); void selection_finalize( struct seat *seat, struct terminal *term, uint32_t serial); @@ -25,12 +26,6 @@ bool selection_on_rows(const struct terminal *term, int start, int end); void selection_view_up(struct terminal *term, int new_view); void selection_view_down(struct terminal *term, int new_view); -void selection_mark_word( - struct seat *seat, struct terminal *term, int col, int row, - bool spaces_only, uint32_t serial); -void selection_mark_row( - struct seat *seat, struct terminal *term, int row, uint32_t serial); - void selection_clipboard_unset(struct seat *seat); void selection_primary_unset(struct seat *seat); -- cgit v1.3 From 736ff0421cc607a315e0bf5264f2633a0d4d80d4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 3 Jan 2021 13:04:31 +0100 Subject: selection: find_word_boundary_{left,right}: treat spacers as word chars --- selection.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 4b7baf13..da89b006 100644 --- a/selection.c +++ b/selection.c @@ -243,7 +243,9 @@ find_word_boundary_left(struct terminal *term, struct coord *pos, const struct row *r = grid_row_in_view(term->grid, pos->row); wchar_t c = r->cells[pos->col].wc; - if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) { + if (!(c != CELL_MULT_COL_SPACER && + (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters)))) + { while (true) { int next_col = pos->col - 1; int next_row = pos->row; @@ -258,8 +260,12 @@ find_word_boundary_left(struct terminal *term, struct coord *pos, const struct row *row = grid_row_in_view(term->grid, next_row); c = row->cells[next_col].wc; - if (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters)) + if (c != CELL_MULT_COL_SPACER && + (c == 0 || + !isword(c, spaces_only, term->conf->word_delimiters))) + { break; + } pos->col = next_col; pos->row = next_row; @@ -274,7 +280,9 @@ find_word_boundary_right(struct terminal *term, struct coord *pos, const struct row *r = grid_row_in_view(term->grid, pos->row); wchar_t c = r->cells[pos->col].wc; - if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) { + if (!(c != CELL_MULT_COL_SPACER && + (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters)))) + { while (true) { int next_col = pos->col + 1; int next_row = pos->row; @@ -289,8 +297,12 @@ find_word_boundary_right(struct terminal *term, struct coord *pos, const struct row *row = grid_row_in_view(term->grid, next_row); c = row->cells[next_col].wc; - if (c == '\0' || !isword(c, spaces_only, term->conf->word_delimiters)) + if (c != CELL_MULT_COL_SPACER && + (c == 0 || + !isword(c, spaces_only, term->conf->word_delimiters))) + { break; + } pos->col = next_col; pos->row = next_row; -- cgit v1.3 From c821914e67d920f4f4a2abdc7a0dc84464ea820b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 3 Jan 2021 13:09:24 +0100 Subject: selection: find_word_boundary{left,right}: handle composed characters --- selection.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'selection.c') diff --git a/selection.c b/selection.c index da89b006..0f856c78 100644 --- a/selection.c +++ b/selection.c @@ -243,6 +243,12 @@ find_word_boundary_left(struct terminal *term, struct coord *pos, const struct row *r = grid_row_in_view(term->grid, pos->row); wchar_t c = r->cells[pos->col].wc; + if (c >= CELL_COMB_CHARS_LO && + c < (CELL_COMB_CHARS_LO + term->composed_count)) + { + c = term->composed[c - CELL_COMB_CHARS_LO].base; + } + if (!(c != CELL_MULT_COL_SPACER && (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters)))) { @@ -260,6 +266,12 @@ find_word_boundary_left(struct terminal *term, struct coord *pos, const struct row *row = grid_row_in_view(term->grid, next_row); c = row->cells[next_col].wc; + if (c >= CELL_COMB_CHARS_LO && + c < (CELL_COMB_CHARS_LO + term->composed_count)) + { + c = term->composed[c - CELL_COMB_CHARS_LO].base; + } + if (c != CELL_MULT_COL_SPACER && (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) @@ -280,6 +292,12 @@ find_word_boundary_right(struct terminal *term, struct coord *pos, const struct row *r = grid_row_in_view(term->grid, pos->row); wchar_t c = r->cells[pos->col].wc; + if (c >= CELL_COMB_CHARS_LO && + c < (CELL_COMB_CHARS_LO + term->composed_count)) + { + c = term->composed[c - CELL_COMB_CHARS_LO].base; + } + if (!(c != CELL_MULT_COL_SPACER && (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters)))) { @@ -297,6 +315,12 @@ find_word_boundary_right(struct terminal *term, struct coord *pos, const struct row *row = grid_row_in_view(term->grid, next_row); c = row->cells[next_col].wc; + if (c >= CELL_COMB_CHARS_LO && + c < (CELL_COMB_CHARS_LO + term->composed_count)) + { + c = term->composed[c - CELL_COMB_CHARS_LO].base; + } + if (c != CELL_MULT_COL_SPACER && (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) -- cgit v1.3 From 2fd7b2fbd46d773ba43ba5acde365d23de4dda90 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 3 Jan 2021 13:11:46 +0100 Subject: selection: allow selections to pivot around a range instead of a point Extend selection pivoting to allow selections to pivot around a range. Use this in word- and row-based selections to pivot around the initial word/row that was selected. This mimics the behavior of at least urxvt and xterm. --- selection.c | 104 +++++++++++++++++++++++++++++++++++++++++++++--------------- terminal.h | 5 +++ 2 files changed, 83 insertions(+), 26 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 0f856c78..37bf5af8 100644 --- a/selection.c +++ b/selection.c @@ -352,11 +352,13 @@ selection_start(struct terminal *term, int col, int row, term->selection.ongoing = true; term->selection.spaces_only = spaces_only; - switch (semantic) { case SELECTION_SEMANTIC_NONE: term->selection.start = (struct coord){col, term->grid->view + row}; term->selection.end = (struct coord){-1, -1}; + + term->selection.pivot.start = term->selection.start; + term->selection.pivot.end = term->selection.end; break; case SELECTION_SEMANTIC_WORD: { @@ -367,15 +369,22 @@ selection_start(struct terminal *term, int col, int row, term->selection.start = (struct coord){ start.col, term->grid->view + start.row}; + term->selection.pivot.start = term->selection.start; + term->selection.pivot.end = (struct coord){end.col, term->grid->view + end.row}; + selection_update(term, end.col, end.row); break; } case SELECTION_SEMANTIC_ROW: term->selection.start = (struct coord){0, term->grid->view + row}; + term->selection.pivot.start = term->selection.start; + term->selection.pivot.end = (struct coord){term->cols - 1, term->grid->view + row}; + selection_update(term, term->cols - 1, row); break; } + } /* Context used while (un)marking selected cells, to be able to @@ -511,50 +520,95 @@ selection_update(struct terminal *term, int col, int row) /* Adjust start point if the selection has changed 'direction' */ if (!(new_end.row == new_start.row && new_end.col == new_start.col)) { - enum selection_direction new_direction; + enum selection_direction new_direction = term->selection.direction; + + struct coord *pivot_start = &term->selection.pivot.start; + struct coord *pivot_end = &term->selection.pivot.end; - if (new_end.row > new_start.row || - (new_end.row == new_start.row && new_end.col > new_start.col)) + if (new_end.row < pivot_start->row || + (new_end.row == pivot_start->row && new_end.col < pivot_start->col)) { - /* New end point is after the start point */ - new_direction = SELECTION_RIGHT; - } else { - /* The new end point is before the start point */ + /* New end point is before the start point */ new_direction = SELECTION_LEFT; + } else { + /* The new end point is after the start point */ + new_direction = SELECTION_RIGHT; } if (term->selection.direction != new_direction) { - if (term->selection.direction != SELECTION_UNDIR) { - if (new_direction == SELECTION_LEFT) { + if (term->selection.direction == SELECTION_UNDIR && + pivot_end->row < 0) + { + /* First, make sure ‘start’ isn’t in the middle of a + * multi-column character */ + while (true) { + const struct row *row = term->grid->rows[pivot_start->row]; + const struct cell *cell = &row->cells[pivot_start->col]; + + if (cell->wc != CELL_MULT_COL_SPACER) + break; + + /* Multi-column chars don’t cross rows */ + assert(pivot_start->col > 0); + if (pivot_start->col == 0) + break; + + pivot_start->col--; + } + + /* + * Setup pivot end to be one character *before* start + * Which one we move, the end or start point, depends + * on the initial selection direction. + */ + + *pivot_end = *pivot_start; + + if (new_direction == SELECTION_RIGHT) { bool keep_going = true; while (keep_going) { - const wchar_t wc = row_start->cells[new_start.col].wc; + const struct row *row = term->grid->rows[pivot_end->row]; + const wchar_t wc = row->cells[pivot_end->col].wc; + keep_going = wc == CELL_MULT_COL_SPACER; - new_start.col--; - if (new_start.col < 0) { - new_start.col = term->cols - 1; - new_start.row--; - } + if (pivot_end->col == 0) { + if (pivot_end->row > 0) { + pivot_end->col = term->cols - 1; + pivot_end->row--; + } + } else + pivot_end->col--; } } else { bool keep_going = true; while (keep_going) { - const wchar_t wc = new_start.col < term->cols - 1 - ? row_start->cells[new_start.col + 1].wc - : 0; + const struct row *row = term->grid->rows[pivot_start->row]; + const wchar_t wc = pivot_start->col < term->cols - 1 + ? row->cells[pivot_start->col + 1].wc : 0; keep_going = wc == CELL_MULT_COL_SPACER; - new_start.col++; - if (new_start.col >= term->cols) { - new_start.col = 0; - new_start.row++; - } + if (pivot_start->col >= term->cols - 1) { + if (pivot_start->row < term->rows - 1) { + pivot_start->col = 0; + pivot_start->row++; + } + } else + pivot_start->col++; } } + + assert(term->grid->rows[pivot_start->row]->cells[pivot_start->col].wc != CELL_MULT_COL_SPACER); + assert(term->grid->rows[pivot_end->row]->cells[pivot_end->col].wc != CELL_MULT_COL_SPACER); } + if (new_direction == SELECTION_LEFT) { + assert(pivot_end->row >= 0); + new_start = *pivot_end; + } else + new_start = *pivot_start; + term->selection.direction = new_direction; } } @@ -574,7 +628,6 @@ selection_update(struct terminal *term, int col, int row) break; case SELECTION_UNDIR: - assert(false); break; } break; @@ -590,7 +643,6 @@ selection_update(struct terminal *term, int col, int row) break; case SELECTION_UNDIR: - assert(false); break; } break; diff --git a/terminal.h b/terminal.h index 52eb0a84..a8bd5b0b 100644 --- a/terminal.h +++ b/terminal.h @@ -367,6 +367,11 @@ struct terminal { bool ongoing; bool spaces_only; /* SELECTION_SEMANTIC_WORD */ + struct { + struct coord start; + struct coord end; + } pivot; + struct { int fd; int col; -- cgit v1.3 From b22091a8c949b32be2c74670ea15e56e372e450c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 3 Jan 2021 13:54:41 +0100 Subject: selection: find_word_boundary{left,right}: what we match depends on initial character If the initial character is a space, find the next non-space character. If the initial character is a delimiter, find the next non-delimiter character (space, or word character). If the initial character is neither (i.e, it is a word character), find the next non-word character. --- selection.c | 120 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 52 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 37bf5af8..dfc5a94a 100644 --- a/selection.c +++ b/selection.c @@ -249,39 +249,47 @@ find_word_boundary_left(struct terminal *term, struct coord *pos, c = term->composed[c - CELL_COMB_CHARS_LO].base; } - if (!(c != CELL_MULT_COL_SPACER && - (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters)))) - { - while (true) { - int next_col = pos->col - 1; - int next_row = pos->row; - - /* Linewrap */ - if (next_col < 0) { - next_col = term->cols - 1; - if (--next_row < 0) - break; - } + bool initial_is_space = c == 0 || iswspace(c); + bool initial_is_delim = c != 0 && c != CELL_MULT_COL_SPACER && + !isword(c, spaces_only, term->conf->word_delimiters); - const struct row *row = grid_row_in_view(term->grid, next_row); + while (true) { + int next_col = pos->col - 1; + int next_row = pos->row; - c = row->cells[next_col].wc; - if (c >= CELL_COMB_CHARS_LO && - c < (CELL_COMB_CHARS_LO + term->composed_count)) - { - c = term->composed[c - CELL_COMB_CHARS_LO].base; - } + /* Linewrap */ + if (next_col < 0) { + next_col = term->cols - 1; + if (--next_row < 0) + break; + } + + const struct row *row = grid_row_in_view(term->grid, next_row); - if (c != CELL_MULT_COL_SPACER && - (c == 0 || - !isword(c, spaces_only, term->conf->word_delimiters))) + c = row->cells[next_col].wc; + if (c >= CELL_COMB_CHARS_LO && + c < (CELL_COMB_CHARS_LO + term->composed_count)) + { + c = term->composed[c - CELL_COMB_CHARS_LO].base; + } + + bool is_space = c == 0 || iswspace(c); + if (initial_is_space && !is_space) + break; + + if (!initial_is_space) { + bool is_word = c != 0 && c != CELL_MULT_COL_SPACER && + isword(c, spaces_only, term->conf->word_delimiters); + + if ((initial_is_delim && (is_word || is_space)) || + (!initial_is_delim && !is_word)) { break; } - - pos->col = next_col; - pos->row = next_row; } + + pos->col = next_col; + pos->row = next_row; } } @@ -298,39 +306,47 @@ find_word_boundary_right(struct terminal *term, struct coord *pos, c = term->composed[c - CELL_COMB_CHARS_LO].base; } - if (!(c != CELL_MULT_COL_SPACER && - (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters)))) - { - while (true) { - int next_col = pos->col + 1; - int next_row = pos->row; - - /* Linewrap */ - if (next_col >= term->cols) { - next_col = 0; - if (++next_row >= term->rows) - break; - } + bool initial_is_space = c == 0 || iswspace(c); + bool initial_is_delim = c != 0 && c != CELL_MULT_COL_SPACER && + !isword(c, spaces_only, term->conf->word_delimiters); - const struct row *row = grid_row_in_view(term->grid, next_row); + while (true) { + int next_col = pos->col + 1; + int next_row = pos->row; - c = row->cells[next_col].wc; - if (c >= CELL_COMB_CHARS_LO && - c < (CELL_COMB_CHARS_LO + term->composed_count)) - { - c = term->composed[c - CELL_COMB_CHARS_LO].base; - } + /* Linewrap */ + if (next_col >= term->cols) { + next_col = 0; + if (++next_row >= term->rows) + break; + } + + const struct row *row = grid_row_in_view(term->grid, next_row); - if (c != CELL_MULT_COL_SPACER && - (c == 0 || - !isword(c, spaces_only, term->conf->word_delimiters))) + c = row->cells[next_col].wc; + if (c >= CELL_COMB_CHARS_LO && + c < (CELL_COMB_CHARS_LO + term->composed_count)) + { + c = term->composed[c - CELL_COMB_CHARS_LO].base; + } + + bool is_space = c == 0 || iswspace(c); + if (initial_is_space && !is_space) + break; + + if (!initial_is_space) { + bool is_word = c != 0 && c != CELL_MULT_COL_SPACER && + isword(c, spaces_only, term->conf->word_delimiters); + + if ((initial_is_delim && (is_word || is_space)) || + (!initial_is_delim && !is_word)) { break; } - - pos->col = next_col; - pos->row = next_row; } + + pos->col = next_col; + pos->row = next_row; } } -- cgit v1.3 From 3863a61ba693540dcce7e6718c7610663ce37859 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 3 Jan 2021 14:07:40 +0100 Subject: selection: find_word_boundary_{left,right}: handle multi-column characters --- selection.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index dfc5a94a..cb154477 100644 --- a/selection.c +++ b/selection.c @@ -243,6 +243,14 @@ find_word_boundary_left(struct terminal *term, struct coord *pos, const struct row *r = grid_row_in_view(term->grid, pos->row); wchar_t c = r->cells[pos->col].wc; + while (c == CELL_MULT_COL_SPACER) { + assert(pos->col > 0); + if (pos->col == 0) + return; + pos->col--; + c = r->cells[pos->col].wc; + } + if (c >= CELL_COMB_CHARS_LO && c < (CELL_COMB_CHARS_LO + term->composed_count)) { @@ -250,8 +258,8 @@ find_word_boundary_left(struct terminal *term, struct coord *pos, } bool initial_is_space = c == 0 || iswspace(c); - bool initial_is_delim = c != 0 && c != CELL_MULT_COL_SPACER && - !isword(c, spaces_only, term->conf->word_delimiters); + bool initial_is_delim = + c != 0 && !isword(c, spaces_only, term->conf->word_delimiters); while (true) { int next_col = pos->col - 1; @@ -267,6 +275,13 @@ find_word_boundary_left(struct terminal *term, struct coord *pos, const struct row *row = grid_row_in_view(term->grid, next_row); c = row->cells[next_col].wc; + while (c == CELL_MULT_COL_SPACER) { + assert(next_col > 0); + if (--next_col < 0) + return; + c = row->cells[next_col].wc; + } + if (c >= CELL_COMB_CHARS_LO && c < (CELL_COMB_CHARS_LO + term->composed_count)) { @@ -278,8 +293,8 @@ find_word_boundary_left(struct terminal *term, struct coord *pos, break; if (!initial_is_space) { - bool is_word = c != 0 && c != CELL_MULT_COL_SPACER && - isword(c, spaces_only, term->conf->word_delimiters); + bool is_word = + c != 0 && isword(c, spaces_only, term->conf->word_delimiters); if ((initial_is_delim && (is_word || is_space)) || (!initial_is_delim && !is_word)) @@ -300,6 +315,14 @@ find_word_boundary_right(struct terminal *term, struct coord *pos, const struct row *r = grid_row_in_view(term->grid, pos->row); wchar_t c = r->cells[pos->col].wc; + while (c == CELL_MULT_COL_SPACER) { + assert(pos->col > 0); + if (pos->col == 0) + return; + pos->col--; + c = r->cells[pos->col].wc; + } + if (c >= CELL_COMB_CHARS_LO && c < (CELL_COMB_CHARS_LO + term->composed_count)) { @@ -307,8 +330,8 @@ find_word_boundary_right(struct terminal *term, struct coord *pos, } bool initial_is_space = c == 0 || iswspace(c); - bool initial_is_delim = c != 0 && c != CELL_MULT_COL_SPACER && - !isword(c, spaces_only, term->conf->word_delimiters); + bool initial_is_delim = + c != 0 && !isword(c, spaces_only, term->conf->word_delimiters); while (true) { int next_col = pos->col + 1; @@ -324,6 +347,15 @@ find_word_boundary_right(struct terminal *term, struct coord *pos, const struct row *row = grid_row_in_view(term->grid, next_row); c = row->cells[next_col].wc; + while (c == CELL_MULT_COL_SPACER) { + if (++next_col >= term->cols) { + next_col = 0; + if (++next_row >= term->rows) + return; + } + c = row->cells[next_col].wc; + } + if (c >= CELL_COMB_CHARS_LO && c < (CELL_COMB_CHARS_LO + term->composed_count)) { @@ -335,8 +367,8 @@ find_word_boundary_right(struct terminal *term, struct coord *pos, break; if (!initial_is_space) { - bool is_word = c != 0 && c != CELL_MULT_COL_SPACER && - isword(c, spaces_only, term->conf->word_delimiters); + bool is_word = + c != 0 && isword(c, spaces_only, term->conf->word_delimiters); if ((initial_is_delim && (is_word || is_space)) || (!initial_is_delim && !is_word)) -- cgit v1.3 From c851aae9d6107e310232fbc18cdf7ffea2a9bf46 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 3 Jan 2021 14:33:35 +0100 Subject: selection: find_word_boundary_{left,right}: try to make the code more readable --- selection.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index cb154477..df643486 100644 --- a/selection.c +++ b/selection.c @@ -259,7 +259,9 @@ find_word_boundary_left(struct terminal *term, struct coord *pos, bool initial_is_space = c == 0 || iswspace(c); bool initial_is_delim = - c != 0 && !isword(c, spaces_only, term->conf->word_delimiters); + !initial_is_space && !isword(c, spaces_only, term->conf->word_delimiters); + bool initial_is_word = + c != 0 && isword(c, spaces_only, term->conf->word_delimiters); while (true) { int next_col = pos->col - 1; @@ -289,19 +291,17 @@ find_word_boundary_left(struct terminal *term, struct coord *pos, } bool is_space = c == 0 || iswspace(c); + bool is_delim = + !is_space && !isword(c, spaces_only, term->conf->word_delimiters); + bool is_word = + c != 0 && isword(c, spaces_only, term->conf->word_delimiters); + if (initial_is_space && !is_space) break; - - if (!initial_is_space) { - bool is_word = - c != 0 && isword(c, spaces_only, term->conf->word_delimiters); - - if ((initial_is_delim && (is_word || is_space)) || - (!initial_is_delim && !is_word)) - { - break; - } - } + if (initial_is_delim && !is_delim) + break; + if (initial_is_word && !is_word) + break; pos->col = next_col; pos->row = next_row; @@ -331,7 +331,9 @@ find_word_boundary_right(struct terminal *term, struct coord *pos, bool initial_is_space = c == 0 || iswspace(c); bool initial_is_delim = - c != 0 && !isword(c, spaces_only, term->conf->word_delimiters); + !initial_is_space && !isword(c, spaces_only, term->conf->word_delimiters); + bool initial_is_word = + c != 0 && isword(c, spaces_only, term->conf->word_delimiters); while (true) { int next_col = pos->col + 1; @@ -363,19 +365,17 @@ find_word_boundary_right(struct terminal *term, struct coord *pos, } bool is_space = c == 0 || iswspace(c); + bool is_delim = + !is_space && !isword(c, spaces_only, term->conf->word_delimiters); + bool is_word = + c != 0 && isword(c, spaces_only, term->conf->word_delimiters); + if (initial_is_space && !is_space) break; - - if (!initial_is_space) { - bool is_word = - c != 0 && isword(c, spaces_only, term->conf->word_delimiters); - - if ((initial_is_delim && (is_word || is_space)) || - (!initial_is_delim && !is_word)) - { - break; - } - } + if (initial_is_delim && !is_delim) + break; + if (initial_is_word && !is_word) + break; pos->col = next_col; pos->row = next_row; -- cgit v1.3 From 683f63c92992da8d9277a0a29c04bbf217241e57 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 3 Jan 2021 15:15:34 +0100 Subject: selection: update: find_word_boundary_{left,right}: coordinates are screen local --- selection.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index df643486..05080561 100644 --- a/selection.c +++ b/selection.c @@ -667,13 +667,19 @@ selection_update(struct terminal *term, int col, int row) case SELECTION_SEMANTIC_WORD: switch (term->selection.direction) { - case SELECTION_LEFT: - find_word_boundary_left(term, &new_end, term->selection.spaces_only); + case SELECTION_LEFT: { + struct coord end = {col, row}; + find_word_boundary_left(term, &end, term->selection.spaces_only); + new_end = (struct coord){end.col, term->grid->view + end.row}; break; + } - case SELECTION_RIGHT: - find_word_boundary_right(term, &new_end, term->selection.spaces_only); + case SELECTION_RIGHT: { + struct coord end = {col, row}; + find_word_boundary_right(term, &end, term->selection.spaces_only); + new_end = (struct coord){end.col, term->grid->view + end.row}; break; + } case SELECTION_UNDIR: break; -- cgit v1.3 From 8113d2205d3a9798f84115f053200005c1a34d75 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 3 Jan 2021 15:25:43 +0100 Subject: selection: cancel: reset pivot coordinates --- selection.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 05080561..61eacf96 100644 --- a/selection.c +++ b/selection.c @@ -945,6 +945,8 @@ selection_cancel(struct terminal *term) term->selection.kind = SELECTION_NONE; term->selection.start = (struct coord){-1, -1}; term->selection.end = (struct coord){-1, -1}; + term->selection.pivot.start = (struct coord){-1, -1}; + term->selection.pivot.end = (struct coord){-1, -1}; term->selection.direction = SELECTION_UNDIR; term->selection.ongoing = false; } -- cgit v1.3 From 2b195d2cc30e213d76e859e4497ea8725bafefc8 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 3 Jan 2021 15:32:00 +0100 Subject: selection: wrap pivot_{start,end}->row before accessing grid row array --- selection.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 61eacf96..78add510 100644 --- a/selection.c +++ b/selection.c @@ -590,7 +590,7 @@ selection_update(struct terminal *term, int col, int row) /* First, make sure ‘start’ isn’t in the middle of a * multi-column character */ while (true) { - const struct row *row = term->grid->rows[pivot_start->row]; + const struct row *row = term->grid->rows[pivot_start->row & (term->grid->num_rows - 1)]; const struct cell *cell = &row->cells[pivot_start->col]; if (cell->wc != CELL_MULT_COL_SPACER) @@ -615,7 +615,7 @@ selection_update(struct terminal *term, int col, int row) if (new_direction == SELECTION_RIGHT) { bool keep_going = true; while (keep_going) { - const struct row *row = term->grid->rows[pivot_end->row]; + const struct row *row = term->grid->rows[pivot_end->row & (term->grid->num_rows - 1)]; const wchar_t wc = row->cells[pivot_end->col].wc; keep_going = wc == CELL_MULT_COL_SPACER; @@ -631,7 +631,7 @@ selection_update(struct terminal *term, int col, int row) } else { bool keep_going = true; while (keep_going) { - const struct row *row = term->grid->rows[pivot_start->row]; + const struct row *row = term->grid->rows[pivot_start->row & (term->grid->num_rows - 1)]; const wchar_t wc = pivot_start->col < term->cols - 1 ? row->cells[pivot_start->col + 1].wc : 0; @@ -647,8 +647,10 @@ selection_update(struct terminal *term, int col, int row) } } - assert(term->grid->rows[pivot_start->row]->cells[pivot_start->col].wc != CELL_MULT_COL_SPACER); - assert(term->grid->rows[pivot_end->row]->cells[pivot_end->col].wc != CELL_MULT_COL_SPACER); + assert(term->grid->rows[pivot_start->row & (term->grid->num_rows - 1)]-> + cells[pivot_start->col].wc != CELL_MULT_COL_SPACER); + assert(term->grid->rows[pivot_end->row & (term->grid->num_rows - 1)]-> + cells[pivot_end->col].wc != CELL_MULT_COL_SPACER); } if (new_direction == SELECTION_LEFT) { -- cgit v1.3 From fb9a95494dd0d6f55ec9ef08115b3b1ad1403305 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 3 Jan 2021 15:37:51 +0100 Subject: selection: update: simplify: multi-column chars don’t span line-wraps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- selection.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 78add510..81baf677 100644 --- a/selection.c +++ b/selection.c @@ -620,13 +620,11 @@ selection_update(struct terminal *term, int col, int row) keep_going = wc == CELL_MULT_COL_SPACER; - if (pivot_end->col == 0) { - if (pivot_end->row > 0) { - pivot_end->col = term->cols - 1; - pivot_end->row--; - } - } else - pivot_end->col--; + /* Multi-col chars shouldn’t span line-wraps */ + assert(pivot_end->col > 0); + if (pivot_end->col == 0) + break; + pivot_end->col--; } } else { bool keep_going = true; @@ -637,13 +635,9 @@ selection_update(struct terminal *term, int col, int row) keep_going = wc == CELL_MULT_COL_SPACER; - if (pivot_start->col >= term->cols - 1) { - if (pivot_start->row < term->rows - 1) { - pivot_start->col = 0; - pivot_start->row++; - } - } else - pivot_start->col++; + if (pivot_start->col >= term->cols - 1) + break; + pivot_start->col++; } } -- cgit v1.3 From 56f6e450b0287545744c27e63972d72b4815e028 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 3 Jan 2021 16:01:05 +0100 Subject: selection: update: get start-row pointer *after* modifying the start row index --- selection.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 81baf677..35212ab2 100644 --- a/selection.c +++ b/selection.c @@ -561,11 +561,6 @@ selection_update(struct terminal *term, int col, int row) struct coord new_start = term->selection.start; struct coord new_end = {col, term->grid->view + row}; - size_t start_row_idx = new_start.row & (term->grid->num_rows - 1); - size_t end_row_idx = new_end.row & (term->grid->num_rows - 1); - const struct row *row_start = term->grid->rows[start_row_idx]; - const struct row *row_end = term->grid->rows[end_row_idx]; - /* Adjust start point if the selection has changed 'direction' */ if (!(new_end.row == new_start.row && new_end.col == new_start.col)) { enum selection_direction new_direction = term->selection.direction; @@ -698,6 +693,12 @@ selection_update(struct terminal *term, int col, int row) break; } + size_t start_row_idx = new_start.row & (term->grid->num_rows - 1); + size_t end_row_idx = new_end.row & (term->grid->num_rows - 1); + + const struct row *row_start = term->grid->rows[start_row_idx]; + const struct row *row_end = term->grid->rows[end_row_idx]; + /* If an end point is in the middle of a multi-column character, * expand the selection to cover the entire character */ if (new_start.row < new_end.row || -- cgit v1.3 From 4849e8f87459be043ddaad3a37e334df03e9209e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 3 Jan 2021 16:06:04 +0100 Subject: selection: update: line-wraps are ok while moving pivot start/end point This fixes an assertion triggered when selecting the upper left cell and dragging down. We would end up trying to decrement the pivot end point, hitting an assertion that only is valid while skipping spacers. Remove the assertion, and allow pivot points to be moved across line wraps, but take care not to move outside the visible screen area. --- selection.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 35212ab2..f9642719 100644 --- a/selection.c +++ b/selection.c @@ -615,11 +615,13 @@ selection_update(struct terminal *term, int col, int row) keep_going = wc == CELL_MULT_COL_SPACER; - /* Multi-col chars shouldn’t span line-wraps */ - assert(pivot_end->col > 0); - if (pivot_end->col == 0) - break; - pivot_end->col--; + if (pivot_end->col == 0) { + if (pivot_end->row - term->grid->view <= 0) + break; + pivot_end->col = term->cols - 1; + pivot_end->row--; + } else + pivot_end->col--; } } else { bool keep_going = true; @@ -630,9 +632,13 @@ selection_update(struct terminal *term, int col, int row) keep_going = wc == CELL_MULT_COL_SPACER; - if (pivot_start->col >= term->cols - 1) - break; - pivot_start->col++; + if (pivot_start->col >= term->cols - 1) { + if (pivot_start->row - term->grid->view >= term->rows - 1) + break; + pivot_start->col = 0; + pivot_start->row++; + } else + pivot_start->col++; } } -- cgit v1.3