mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +00:00
LibGUI: Fix bogus TextEditor selection when cursor dragged outside view
If the cursor Y position is < 0 in content coordinate space, we should always map that to the first line of the file. This fixes unexpected cursor behavior when dragging the selection above the top of the document.
This commit is contained in:
parent
8bc1bcb34b
commit
015c5e61a8
1 changed files with 13 additions and 12 deletions
|
@ -157,22 +157,23 @@ TextPosition TextEditor::text_position_at_content_position(const Gfx::IntPoint&
|
|||
|
||||
size_t line_index = 0;
|
||||
|
||||
if (is_wrapping_enabled()) {
|
||||
for (size_t i = 0; i < line_count(); ++i) {
|
||||
auto& rect = m_line_visual_data[i].visual_rect;
|
||||
if (position.y() >= rect.top() && position.y() <= rect.bottom()) {
|
||||
line_index = i;
|
||||
break;
|
||||
if (position.y() >= 0) {
|
||||
if (is_wrapping_enabled()) {
|
||||
for (size_t i = 0; i < line_count(); ++i) {
|
||||
auto& rect = m_line_visual_data[i].visual_rect;
|
||||
if (position.y() >= rect.top() && position.y() <= rect.bottom()) {
|
||||
line_index = i;
|
||||
break;
|
||||
}
|
||||
if (position.y() > rect.bottom())
|
||||
line_index = line_count() - 1;
|
||||
}
|
||||
if (position.y() > rect.bottom())
|
||||
line_index = line_count() - 1;
|
||||
} else {
|
||||
line_index = (size_t)(position.y() / line_height());
|
||||
}
|
||||
} else {
|
||||
line_index = (size_t)(position.y() / line_height());
|
||||
line_index = max((size_t)0, min(line_index, line_count() - 1));
|
||||
}
|
||||
|
||||
line_index = max((size_t)0, min(line_index, line_count() - 1));
|
||||
|
||||
size_t column_index = 0;
|
||||
switch (m_text_alignment) {
|
||||
case Gfx::TextAlignment::CenterLeft:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue