diff --git a/grid-reader.c b/grid-reader.c index 6cd60c50..be374cd7 100644 --- a/grid-reader.c +++ b/grid-reader.c @@ -180,19 +180,14 @@ grid_reader_handle_wrap(struct grid_reader *gr, u_int *xx, u_int *yy) int grid_reader_in_set(struct grid_reader *gr, const char *set) { - struct grid_cell gc; - - grid_get_cell(gr->gd, gr->cx, gr->cy, &gc); - if (gc.flags & GRID_FLAG_PADDING) - return (0); - return (utf8_cstrhas(set, &gc.data)); + return (grid_in_set(gr->gd, gr->cx, gr->cy, set)); } /* Move cursor to the start of the next word. */ void grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators) { - u_int xx, yy; + u_int xx, yy, width; /* Do not break up wrapped words. */ if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED) @@ -229,8 +224,8 @@ grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators) } } while (grid_reader_handle_wrap(gr, &xx, &yy) && - grid_reader_in_set(gr, WHITESPACE)) - gr->cx++; + (width = grid_reader_in_set(gr, WHITESPACE))) + gr->cx += width; } /* Move cursor to the end of the next word. */ @@ -425,7 +420,9 @@ grid_reader_cursor_back_to_indentation(struct grid_reader *gr) xx = grid_line_length(gr->gd, py); for (px = 0; px < xx; px++) { grid_get_cell(gr->gd, px, py, &gc); - if (gc.data.size != 1 || *gc.data.data != ' ') { + if ((gc.data.size != 1 || *gc.data.data != ' ') && + ~gc.flags & GRID_FLAG_TAB && + ~gc.flags & GRID_FLAG_PADDING) { gr->cx = px; gr->cy = py; return; diff --git a/grid.c b/grid.c index 53002a67..0098c81c 100644 --- a/grid.c +++ b/grid.c @@ -1561,3 +1561,27 @@ grid_line_length(struct grid *gd, u_int py) } return (px); } + +/* Check if character is in set. */ +int +grid_in_set(struct grid *gd, u_int px, u_int py, const char *set) +{ + struct grid_cell gc, tmp_gc; + u_int pxx; + + grid_get_cell(gd, px, py, &gc); + if (strchr(set, '\t')) { + if (gc.flags & GRID_FLAG_PADDING) { + pxx = px; + do + grid_get_cell(gd, --pxx, py, &tmp_gc); + while (pxx > 0 && tmp_gc.flags & GRID_FLAG_PADDING); + if (tmp_gc.flags & GRID_FLAG_TAB) + return (tmp_gc.data.width - (px - pxx)); + } else if (gc.flags & GRID_FLAG_TAB) + return (gc.data.width); + } + if (gc.flags & GRID_FLAG_PADDING) + return (0); + return (utf8_cstrhas(set, &gc.data)); +} diff --git a/tmux.h b/tmux.h index 4640179d..c3d941c2 100644 --- a/tmux.h +++ b/tmux.h @@ -614,7 +614,7 @@ enum tty_code_code { }; /* Character classes. */ -#define WHITESPACE " " +#define WHITESPACE "\t " /* Mode keys. */ #define MODEKEY_EMACS 0 @@ -2988,6 +2988,7 @@ void grid_reflow(struct grid *, u_int); void grid_wrap_position(struct grid *, u_int, u_int, u_int *, u_int *); void grid_unwrap_position(struct grid *, u_int *, u_int *, u_int, u_int); u_int grid_line_length(struct grid *, u_int); +int grid_in_set(struct grid *, u_int, u_int, const char *); /* grid-reader.c */ void grid_reader_start(struct grid_reader *, struct grid *, u_int, u_int); diff --git a/window-copy.c b/window-copy.c index 0d705629..36b9f89c 100644 --- a/window-copy.c +++ b/window-copy.c @@ -5033,12 +5033,8 @@ window_copy_in_set(struct window_mode_entry *wme, u_int px, u_int py, const char *set) { struct window_copy_mode_data *data = wme->data; - struct grid_cell gc; - grid_get_cell(data->backing->grid, px, py, &gc); - if (gc.flags & GRID_FLAG_PADDING) - return (0); - return (utf8_cstrhas(set, &gc.data)); + return (grid_in_set(data->backing->grid, px, py, set)); } static u_int