|
@@ -4397,9 +4397,12 @@ Point2 TextEdit::get_local_mouse_pos() const {
|
|
}
|
|
}
|
|
|
|
|
|
String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
|
|
String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
|
|
- Point2i pos = get_line_column_at_pos(p_pos);
|
|
|
|
|
|
+ Point2i pos = get_line_column_at_pos(p_pos, false, false);
|
|
int row = pos.y;
|
|
int row = pos.y;
|
|
int col = pos.x;
|
|
int col = pos.x;
|
|
|
|
+ if (row < 0 || col < 0) {
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
|
|
String s = text[row];
|
|
String s = text[row];
|
|
if (s.length() == 0) {
|
|
if (s.length() == 0) {
|
|
@@ -4435,7 +4438,7 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
|
|
return String();
|
|
return String();
|
|
}
|
|
}
|
|
|
|
|
|
-Point2i TextEdit::get_line_column_at_pos(const Point2i &p_pos, bool p_allow_out_of_bounds) const {
|
|
|
|
|
|
+Point2i TextEdit::get_line_column_at_pos(const Point2i &p_pos, bool p_clamp_line, bool p_clamp_column) const {
|
|
float rows = p_pos.y - theme_cache.style_normal->get_margin(SIDE_TOP);
|
|
float rows = p_pos.y - theme_cache.style_normal->get_margin(SIDE_TOP);
|
|
if (!editable) {
|
|
if (!editable) {
|
|
rows -= theme_cache.style_readonly->get_offset().y / 2;
|
|
rows -= theme_cache.style_readonly->get_offset().y / 2;
|
|
@@ -4462,10 +4465,10 @@ Point2i TextEdit::get_line_column_at_pos(const Point2i &p_pos, bool p_allow_out_
|
|
|
|
|
|
int visible_lines = get_visible_line_count_in_range(first_vis_line, row);
|
|
int visible_lines = get_visible_line_count_in_range(first_vis_line, row);
|
|
if (rows > visible_lines) {
|
|
if (rows > visible_lines) {
|
|
- if (!p_allow_out_of_bounds) {
|
|
|
|
- return Point2i(-1, -1);
|
|
|
|
|
|
+ if (p_clamp_line) {
|
|
|
|
+ return Point2i(text[row].length(), row);
|
|
}
|
|
}
|
|
- return Point2i(text[row].length(), row);
|
|
|
|
|
|
+ return Point2i(-1, -1);
|
|
}
|
|
}
|
|
|
|
|
|
int colx = p_pos.x - (theme_cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding);
|
|
int colx = p_pos.x - (theme_cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding);
|
|
@@ -4482,6 +4485,11 @@ Point2i TextEdit::get_line_column_at_pos(const Point2i &p_pos, bool p_allow_out_
|
|
} else {
|
|
} else {
|
|
colx -= wrap_indent;
|
|
colx -= wrap_indent;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (!p_clamp_column && (colx < 0 || colx > TS->shaped_text_get_size(text_rid).x)) {
|
|
|
|
+ return Point2i(-1, -1);
|
|
|
|
+ }
|
|
|
|
+
|
|
int col = TS->shaped_text_hit_test_position(text_rid, colx);
|
|
int col = TS->shaped_text_hit_test_position(text_rid, colx);
|
|
if (!caret_mid_grapheme_enabled) {
|
|
if (!caret_mid_grapheme_enabled) {
|
|
col = TS->shaped_text_closest_character_pos(text_rid, col);
|
|
col = TS->shaped_text_closest_character_pos(text_rid, col);
|
|
@@ -6740,7 +6748,7 @@ void TextEdit::_bind_methods() {
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_word_at_pos", "position"), &TextEdit::get_word_at_pos);
|
|
ClassDB::bind_method(D_METHOD("get_word_at_pos", "position"), &TextEdit::get_word_at_pos);
|
|
|
|
|
|
- ClassDB::bind_method(D_METHOD("get_line_column_at_pos", "position", "allow_out_of_bounds"), &TextEdit::get_line_column_at_pos, DEFVAL(true));
|
|
|
|
|
|
+ ClassDB::bind_method(D_METHOD("get_line_column_at_pos", "position", "clamp_line", "clamp_column"), &TextEdit::get_line_column_at_pos, DEFVAL(true), DEFVAL(true));
|
|
ClassDB::bind_method(D_METHOD("get_pos_at_line_column", "line", "column"), &TextEdit::get_pos_at_line_column);
|
|
ClassDB::bind_method(D_METHOD("get_pos_at_line_column", "line", "column"), &TextEdit::get_pos_at_line_column);
|
|
ClassDB::bind_method(D_METHOD("get_rect_at_line_column", "line", "column"), &TextEdit::get_rect_at_line_column);
|
|
ClassDB::bind_method(D_METHOD("get_rect_at_line_column", "line", "column"), &TextEdit::get_rect_at_line_column);
|
|
|
|
|