url-mode: snapshot screen state when entering URL mode

Previously, we automatically exited URL mode whenever we received data
on the PTY. This was done since we don’t know _what_ has changed on
the screen, and we don’t want to display misleading jump labels.

However, this becomes a problem in curses-like applications that
periodically updates part of the screen. For example, a statusbar with
a clock.

This patch changes this behavior; instead of cancelling URL mode when
receiving PTY data, we snapshot the grid when entering URL mode.

When *rendering*, we use the snapshot:ed grid, while PTY updates
modify the “real” grid.

Snapshot:ing the grid means taking a full/deep copy of the current
grid, including sixel images etc.

Finally, it isn’t necessary to “damage” the entire view
when *entering* URL mode, since we’re at that point the renderer is in
sync with the grid. But we *do* need to damage the entire view when
exiting URL mode, since the grid changes on the “real” grid hasn’t
been tracked by the renderer.
This commit is contained in:
Daniel Eklöf 2021-02-22 10:22:41 +01:00
parent ae3ec52507
commit 54b5ae95c1
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 31 additions and 3 deletions

View file

@ -637,6 +637,9 @@ urls_render(struct terminal *term)
tag_cells_for_url(term, &it->item, true);
}
/* Snapshot the current grid */
term->url_grid_snapshot = grid_snapshot(term->grid);
render_refresh_urls(term);
render_refresh(term);
}
@ -651,8 +654,15 @@ url_destroy(struct url *url)
void
urls_reset(struct terminal *term)
{
if (likely(tll_length(term->urls) == 0))
if (likely(tll_length(term->urls) == 0)) {
xassert(term->url_grid_snapshot == NULL);
return;
}
grid_free(term->url_grid_snapshot);
free(term->url_grid_snapshot);
term->url_grid_snapshot = NULL;
term->render.last_cursor.row = NULL;
if (term->window != NULL) {
tll_foreach(term->window->urls, it) {
@ -669,5 +679,7 @@ urls_reset(struct terminal *term)
term->urls_show_uri_on_jump_label = false;
memset(term->url_keys, 0, sizeof(term->url_keys));
term_damage_view(term);
render_refresh(term);
}