diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2018-01-18 18:30:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-18 18:30:50 +0100 |
commit | b3c66de27f1780ed53ac471190e6ca6a5847bf92 (patch) | |
tree | 8ed0c159efc30564c1ce6cde526329962ebbee44 | |
parent | 05e4303e1d5ace8755c2a101358905bb10f1d69e (diff) | |
parent | 1b837125ce5aa67ba69763da5a340f8e51a98a8c (diff) |
Merge pull request #15843 from ianb96/fold_mouse_ofs_fix
TextEdit fix get_mouse after many folds
-rw-r--r-- | scene/gui/text_edit.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 4d87a6b3ba..179ea5336b 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1775,15 +1775,16 @@ void TextEdit::indent_left() { void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const { float rows = p_mouse.y; + rows -= cache.style_normal->get_margin(MARGIN_TOP); + rows += (CLAMP(v_scroll->get_value() - get_line_scroll_pos(true), 0, 1) * get_row_height()); rows /= get_row_height(); - rows += v_scroll->get_value(); - int row = Math::floor(rows); + int first_vis_line = CLAMP(cursor.line_ofs, 0, text.size() - 1); + int row = first_vis_line + Math::floor(rows); if (is_hiding_enabled()) { // row will be offset by the hidden rows - int lsp = get_line_scroll_pos(true); - int f_ofs = num_lines_from(CLAMP(cursor.line_ofs, 0, text.size() - 1), MIN(row + 1 - cursor.line_ofs, text.size() - cursor.line_ofs)) - 1; - row = cursor.line_ofs + f_ofs; + int f_ofs = num_lines_from(first_vis_line, rows + 1) - 1; + row = first_vis_line + f_ofs; row = CLAMP(row, 0, text.size() - num_lines_from(text.size() - 1, -1)); } |