Fix assertion failure triple-clicking line with quote in last column

By default, triple-click tries to select quoted strings within a
logical line.  This also works if the line spans multiple screen lines.

If there is a quote character in the last column:

	printf %"$COLUMNS"s \'; printf wrapped; sleep inf

and I triple-click on the following soft-wrapped line, there's an
assertion failure because the column next to the quote is out of range.

The quote position has been found by walking at least one cell
backwards from "pos". This means that if the quote position is in
the very last column, there must be a row below.

Also move the assertion to be a pre-condition, though that's debatable.
This commit is contained in:
Johannes Altmanninger 2025-11-07 07:32:11 +01:00 committed by Daniel Eklöf
parent 1fce0e69f5
commit 5cb8ff2e9c
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -19,6 +19,7 @@
#include "char32.h"
#include "commands.h"
#include "config.h"
#include "debug.h"
#include "extract.h"
#include "grid.h"
#include "misc.h"
@ -558,9 +559,15 @@ selection_find_quote_left(struct terminal *term, struct coord *pos,
if (*quote_char == '\0' ? (wc == '"' || wc == '\'')
: wc == *quote_char)
{
xassert(next_col + 1 <= term->cols);
if (next_col + 1 == term->cols) {
xassert(next_row < pos->row);
pos->row = next_row + 1;
pos->col = 0;
} else {
pos->row = next_row;
pos->col = next_col + 1;
xassert(pos->col < term->cols);
}
*quote_char = wc;
return true;