selection: never highlight selected, empty cells

This fixes a regression, where empty cells "between" non-empty
cells (i.e. non-trailing empty cells) sometimes were incorrectly
highlighted.

The idea has always been to highlight exactly those cells that will
get extracted when they’re copied. This means we’ve not highlighted
trailing empty cells, but we _have_ highlighted other empty cells,
since they are converted to spaces when copied (whereas trailing empty
cells are skipped).

fa2d9f8699 changed how a selection is
updated. That is, which cells gets marked as selected, and which ones
gets unmarked.

Since we no longer walk all the cells, but instead work with pixman
regions representing selection diffs, we can no longer determine (with
certainty) which empty cells should be selected and which shouldn’t.

Before this patch (but after
fa2d9f8699), we sometimes incorrectly
highlighted empty cells that should not have been highlighted. This
happened when we’ve first (correctly) highlighted a region of empty
cells, but then shrink the selection such that all those empty cells
should be de-selected.

This patch changes the selection behavior to *never* highlight empty
cells. This fixes the regression, but also means slightly different
behavior, compared to pre-fa2d9f86996467ba33cc381f810ea966a4323381.

The other alternative is to always highlight all empty cells. But,
since I personally like the fact that we’re skipping trailing empty
cells, I prefer the approach taken by this patch.
This commit is contained in:
Daniel Eklöf 2022-08-17 17:36:10 +02:00
parent a0942f950d
commit 86663522d5
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 25 additions and 2 deletions

View file

@ -51,6 +51,8 @@
### Changed ### Changed
* Window is now dimmed while in Unicode input mode. * Window is now dimmed while in Unicode input mode.
* Selected empty cells are **never** highlighted as being
selected. They used to be, when followed by non-empty cells.
### Deprecated ### Deprecated
@ -61,6 +63,8 @@
* Crash on buggy compositors (GNOME) that sometimes send pointer-enter * Crash on buggy compositors (GNOME) that sometimes send pointer-enter
events with a NULL surface. Foot now ignores these events, and the events with a NULL surface. Foot now ignores these events, and the
subsequent motion and leave events. subsequent motion and leave events.
* Regression: “random” selected empty cells being highlighted as
selected when they should not.
### Security ### Security

View file

@ -737,8 +737,27 @@ mark_selected_region(struct terminal *term, pixman_box32_t *boxes,
row->dirty = true; row->dirty = true;
for (int c = box->x1, empty_count = 0; c < box->x2; c++) { for (int c = box->x1, empty_count = 0; c < box->x2; c++) {
if (selected && row->cells[c].wc == 0) { if (row->cells[c].wc == 0) {
empty_count++; /*
* We used to highlight empty cells *if* they were
* followed by non-empty cell(s), since this
* corresponds to what gets extracted when the
* selection is copied (that is, empty cells
* between non-empty cells are converted to
* spaces).
*
* However, they way we handle selection updates
* (diffing the old selection area against the
* new one, using pixman regions), means we
* cant correctly update the state of empty
* cells. The result is random empty cells being
* rendered as selected when they shouldnt.
*
* Fix by *never* highlighting selected empty
* cells (they still get converted to spaces when
* copied, if followed by non-empty cells).
*/
/* empty_count++; */
continue; continue;
} }