diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2022-11-30 09:51:45 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2022-11-30 09:51:45 +0000 |
| commit | 76d494484f0b26f7785c0964cc412609d09607ca (patch) | |
| tree | b16682390a49d5b0bf861af91b057e6784edc597 /url-mode.c | |
| parent | doc: ctlseq: add trailing space to fix XTGETTCAP entry in DCS table (diff) | |
url-mode: tag cells after snapshot:ing the grid
Before this patch, hyperlinked cells were tagged with the “URL”
attribute (thus instructing the renderer to draw an
underline) *before* the grid was snapshot.
When exiting URL mode, the cells were once again updated, this time
removing the URL attribute.
But what if an escape sequence had modified the grid _while we were in
URL mode_? Depending on the sequence, it could move cells around in
such a way, that when exiting URL mode, the affected cells weren’t
updated correctly. I.e. we left some cells with the URL attribute
still set.
The fix is simple: tag cells in the snapshot:ed grid only (which isn’t
affected by any escape sequence received while in URL mode). Not in
the *actual* grid (which _is_ affected).
Diffstat (limited to 'url-mode.c')
| -rw-r--r-- | url-mode.c | 32 |
1 files changed, 17 insertions, 15 deletions
@@ -746,15 +746,18 @@ tag_cells_for_url(struct terminal *term, const struct url *url, bool value) if (url->url_mode_dont_change_url_attr) return; + struct grid *grid = term->url_grid_snapshot; + xassert(grid != NULL); + const struct coord *start = &url->range.start; const struct coord *end = &url->range.end; - size_t end_r = end->row & (term->grid->num_rows - 1); + size_t end_r = end->row & (grid->num_rows - 1); - size_t r = start->row & (term->grid->num_rows - 1); + size_t r = start->row & (grid->num_rows - 1); size_t c = start->col; - struct row *row = term->grid->rows[r]; + struct row *row = grid->rows[r]; row->dirty = true; while (true) { @@ -766,10 +769,10 @@ tag_cells_for_url(struct terminal *term, const struct url *url, bool value) break; if (++c >= term->cols) { - r = (r + 1) & (term->grid->num_rows - 1); + r = (r + 1) & (grid->num_rows - 1); c = 0; - row = term->grid->rows[r]; + row = grid->rows[r]; if (row == NULL) { /* Un-allocated scrollback. This most likely means a * runaway OSC-8 URL. */ @@ -788,15 +791,6 @@ urls_render(struct terminal *term) if (tll_length(win->term->urls) == 0) return; - xassert(tll_length(win->urls) == 0); - tll_foreach(win->term->urls, it) { - struct wl_url url = {.url = &it->item}; - wayl_win_subsurface_new(win, &url.surf, false); - - tll_push_back(win->urls, url); - tag_cells_for_url(term, &it->item, true); - } - /* Dirty the last cursor, to ensure it is erased */ { struct row *cursor_row = term->render.last_cursor.row; @@ -819,6 +813,15 @@ urls_render(struct terminal *term) /* Snapshot the current grid */ term->url_grid_snapshot = grid_snapshot(term->grid); + xassert(tll_length(win->urls) == 0); + tll_foreach(win->term->urls, it) { + struct wl_url url = {.url = &it->item}; + wayl_win_subsurface_new(win, &url.surf, false); + + tll_push_back(win->urls, url); + tag_cells_for_url(term, &it->item, true); + } + render_refresh_urls(term); render_refresh(term); } @@ -860,7 +863,6 @@ urls_reset(struct terminal *term) } tll_foreach(term->urls, it) { - tag_cells_for_url(term, &it->item, false); url_destroy(&it->item); tll_remove(term->urls, it); } |
