terminal: Handle selection for pointer positions outside widget correctly
That is, don't crash and select entire first/last line when the pointer is above or below widget.
This commit is contained in:
+15
-3
@@ -2279,8 +2279,9 @@ recompute_selection(struct terminal *terminal)
|
|||||||
side_margin = allocation.x + (allocation.width - width) / 2;
|
side_margin = allocation.x + (allocation.width - width) / 2;
|
||||||
top_margin = allocation.y + (allocation.height - height) / 2;
|
top_margin = allocation.y + (allocation.height - height) / 2;
|
||||||
|
|
||||||
start_row = (terminal->selection_start_y - top_margin) / ch;
|
start_row = (terminal->selection_start_y - top_margin + ch) / ch - 1;
|
||||||
end_row = (terminal->selection_end_y - top_margin) / ch;
|
end_row = (terminal->selection_end_y - top_margin + ch) / ch - 1;
|
||||||
|
|
||||||
if (start_row < end_row ||
|
if (start_row < end_row ||
|
||||||
(start_row == end_row &&
|
(start_row == end_row &&
|
||||||
terminal->selection_start_x < terminal->selection_end_x)) {
|
terminal->selection_start_x < terminal->selection_end_x)) {
|
||||||
@@ -2295,8 +2296,13 @@ recompute_selection(struct terminal *terminal)
|
|||||||
end_x = terminal->selection_start_x;
|
end_x = terminal->selection_start_x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (terminal->selection_start_row < 0) {
|
||||||
|
terminal->selection_start_row = 0;
|
||||||
|
terminal->selection_start_col = 0;
|
||||||
|
} else {
|
||||||
x = side_margin + cw / 2;
|
x = side_margin + cw / 2;
|
||||||
data = terminal_get_row(terminal, terminal->selection_start_row);
|
data = terminal_get_row(terminal,
|
||||||
|
terminal->selection_start_row);
|
||||||
word_start = 0;
|
word_start = 0;
|
||||||
for (col = 0; col < terminal->width; col++, x += cw) {
|
for (col = 0; col < terminal->width; col++, x += cw) {
|
||||||
if (col == 0 || wordsep(data[col - 1].ch))
|
if (col == 0 || wordsep(data[col - 1].ch))
|
||||||
@@ -2316,7 +2322,12 @@ recompute_selection(struct terminal *terminal)
|
|||||||
terminal->selection_start_col = col;
|
terminal->selection_start_col = col;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (terminal->selection_end_row >= terminal->height) {
|
||||||
|
terminal->selection_end_row = terminal->height;
|
||||||
|
terminal->selection_end_col = 0;
|
||||||
|
} else {
|
||||||
x = side_margin + cw / 2;
|
x = side_margin + cw / 2;
|
||||||
data = terminal_get_row(terminal, terminal->selection_end_row);
|
data = terminal_get_row(terminal, terminal->selection_end_row);
|
||||||
for (col = 0; col < terminal->width; col++, x += cw) {
|
for (col = 0; col < terminal->width; col++, x += cw) {
|
||||||
@@ -2328,6 +2339,7 @@ recompute_selection(struct terminal *terminal)
|
|||||||
}
|
}
|
||||||
|
|
||||||
terminal->selection_end_col = col;
|
terminal->selection_end_col = col;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user