Skip to content

Commit 219af36

Browse files
committed
Merge pull request #92505 from bruvzg/te_ro_margins
[TextEdit] Use style margins for selection in read-only mode.
2 parents 05442e8 + 1d0a8ea commit 219af36

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

scene/gui/text_edit.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4237,8 +4237,11 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
42374237
}
42384238

42394239
Point2i TextEdit::get_line_column_at_pos(const Point2i &p_pos, bool p_allow_out_of_bounds) const {
4240-
float rows = p_pos.y;
4241-
rows -= theme_cache.style_normal->get_margin(SIDE_TOP);
4240+
float rows = p_pos.y - theme_cache.style_normal->get_margin(SIDE_TOP);
4241+
if (!editable) {
4242+
rows -= theme_cache.style_readonly->get_offset().y / 2;
4243+
rows += theme_cache.style_normal->get_offset().y / 2;
4244+
}
42424245
rows /= get_line_height();
42434246
rows += _get_v_scroll_offset();
42444247
int first_vis_line = get_first_visible_line();
@@ -4269,6 +4272,10 @@ Point2i TextEdit::get_line_column_at_pos(const Point2i &p_pos, bool p_allow_out_
42694272
int col = 0;
42704273
int colx = p_pos.x - (theme_cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding);
42714274
colx += first_visible_col;
4275+
if (!editable) {
4276+
colx -= theme_cache.style_readonly->get_offset().x / 2;
4277+
colx += theme_cache.style_normal->get_offset().x / 2;
4278+
}
42724279
col = _get_char_pos_for_line(colx, row, wrap_index);
42734280
if (get_line_wrapping_mode() != LineWrappingMode::LINE_WRAPPING_NONE && wrap_index < get_line_wrap_count(row)) {
42744281
// Move back one if we are at the end of the row.

0 commit comments

Comments
 (0)