aboutsummaryrefslogtreecommitdiff
path: root/scene/gui/text_edit.cpp
diff options
context:
space:
mode:
authorneikeq2015-11-07 13:39:03 +0100
committerneikeq2015-11-07 16:04:32 +0100
commitb70e2b754d44eb360c6485029afc589c4476bfe8 (patch)
tree8e9ef5d4cb0d31ce6268acc26f2cbe35141d7d0d /scene/gui/text_edit.cpp
parent51fa997cb56f11a3ea304a8281bbe618195a1e80 (diff)
downloadgodot-b70e2b754d44eb360c6485029afc589c4476bfe8.tar.gz
godot-b70e2b754d44eb360c6485029afc589c4476bfe8.tar.zst
godot-b70e2b754d44eb360c6485029afc589c4476bfe8.zip
TextEdit: Properly scroll vertically when selecting text with mouse drag
Diffstat (limited to 'scene/gui/text_edit.cpp')
-rw-r--r--scene/gui/text_edit.cpp31
1 files changed, 13 insertions, 18 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 4c620c37d..f1172461d 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1091,16 +1091,16 @@ void TextEdit::backspace_at_cursor() {
}
-bool TextEdit::_get_mouse_pos(const Point2i& p_mouse, int &r_row, int &r_col) const {
+void TextEdit::_get_mouse_pos(const Point2i& p_mouse, int &r_row, int &r_col) const {
- int row=p_mouse.y;
- row-=cache.style_normal->get_margin(MARGIN_TOP);
- row/=get_row_height();
-
- if (row<0 || row>=get_visible_rows())
- return false;
-
- row+=cursor.line_ofs;
+ float rows=p_mouse.y;
+ rows-=cache.style_normal->get_margin(MARGIN_TOP);
+ rows/=get_row_height();
+ int row=cursor.line_ofs+rows;
+
+ if (row<0)
+ row=0;
+
int col=0;
if (row>=text.size()) {
@@ -1116,7 +1116,6 @@ bool TextEdit::_get_mouse_pos(const Point2i& p_mouse, int &r_row, int &r_col) co
r_row=row;
r_col=col;
- return true;
}
void TextEdit::_input_event(const InputEvent& p_input_event) {
@@ -1174,8 +1173,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
if (mb.button_index==BUTTON_LEFT) {
int row,col;
- if (!_get_mouse_pos(Point2i(mb.x,mb.y), row,col))
- return;
+ _get_mouse_pos(Point2i(mb.x,mb.y), row,col);
int prev_col=cursor.column;
int prev_line=cursor.line;
@@ -1304,8 +1302,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
if (mm.button_mask&BUTTON_MASK_LEFT) {
int row,col;
- if (!_get_mouse_pos(Point2i(mm.x,mm.y), row,col))
- return;
+ _get_mouse_pos(Point2i(mm.x,mm.y), row,col);
if (selection.selecting_mode!=Selection::MODE_NONE) {
@@ -3505,10 +3502,8 @@ String TextEdit::get_tooltip(const Point2& p_pos) const {
if (!tooltip_obj)
return Control::get_tooltip(p_pos);
int row,col;
- if (!_get_mouse_pos(p_pos, row,col)) {
- return Control::get_tooltip(p_pos);
- }
-
+ _get_mouse_pos(p_pos, row, col);
+
String s = text[row];
if (s.length()==0)
return Control::get_tooltip(p_pos);