diff --git a/screen-write.c b/screen-write.c index 3a1fc8c8..1767d9bb 100644 --- a/screen-write.c +++ b/screen-write.c @@ -1141,12 +1141,8 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc) /* Write to the screen. */ if (selected) { - memcpy(&tmp_gc, &s->sel.cell, sizeof tmp_gc); - utf8_copy(&tmp_gc.data, &gc->data); - tmp_gc.attr = tmp_gc.attr & ~GRID_ATTR_CHARSET; - tmp_gc.attr |= gc->attr & GRID_ATTR_CHARSET; - tmp_gc.flags = gc->flags; screen_write_flush(ctx); + screen_select_cell(s, &tmp_gc, gc); ttyctx.cell = &tmp_gc; tty_write(tty_cmd_cell, &ttyctx); ctx->written++; diff --git a/screen.c b/screen.c index 7bde6f9b..3d6b8cdc 100644 --- a/screen.c +++ b/screen.c @@ -371,6 +371,22 @@ screen_check_selection(struct screen *s, u_int px, u_int py) return (1); } +/* Get selected grid cell. */ +void +screen_select_cell(struct screen *s, struct grid_cell *dst, + const struct grid_cell *src) +{ + if (!s->sel.flag) + return; + + memcpy(dst, &s->sel.cell, sizeof *dst); + + utf8_copy(&dst->data, &src->data); + dst->attr = dst->attr & ~GRID_ATTR_CHARSET; + dst->attr |= src->attr & GRID_ATTR_CHARSET; + dst->flags = src->flags; +} + /* Reflow wrapped lines. */ static void screen_reflow(struct screen *s, u_int new_x) diff --git a/tmux.h b/tmux.h index 64393edd..dc5e8712 100644 --- a/tmux.h +++ b/tmux.h @@ -2060,6 +2060,8 @@ void screen_set_selection(struct screen *, u_int, u_int, u_int, u_int, u_int, struct grid_cell *); void screen_clear_selection(struct screen *); int screen_check_selection(struct screen *, u_int, u_int); +void screen_select_cell(struct screen *, struct grid_cell *, + const struct grid_cell *); /* window.c */ extern struct windows windows; diff --git a/tty.c b/tty.c index d8702a2f..c4adfe82 100644 --- a/tty.c +++ b/tty.c @@ -658,7 +658,7 @@ void tty_draw_line(struct tty *tty, const struct window_pane *wp, struct screen *s, u_int py, u_int ox, u_int oy) { - struct grid_cell gc; + struct grid_cell gc, tmp_gc; struct grid_line *gl; u_int i, sx; int flags; @@ -687,7 +687,11 @@ tty_draw_line(struct tty *tty, const struct window_pane *wp, for (i = 0; i < sx; i++) { grid_view_get_cell(s->grid, i, py, &gc); - tty_cell(tty, &gc, wp); + if (gc.flags & GRID_FLAG_SELECTED) { + screen_select_cell(s, &tmp_gc, &gc); + tty_cell(tty, &tmp_gc, wp); + } else + tty_cell(tty, &gc, wp); } if (sx < tty->sx) {