godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
86.64k stars 19.32k forks source link

get_pos_at_line_column(line,col) giving incorrect Vector2 if column = 1 #82280

Open yankscally opened 9 months ago

yankscally commented 9 months ago

Godot version

4.1.1

System information

Windows 10

Issue description

using a tool script (not sure if this makes any difference) and using the code edit node from the editor script editor,

@tool
extends EditorPlugin
func _process(delta):
    var code_edit_node = get_editor_interface().get_script_editor().get_current_editor().get_base_editor()

    var line = code_edit_node.get_caret_line(0)
    var column = code_edit_node.get_caret_column(0)

    var caret_pos = code_edit_node.get_pos_at_line_column(line,column)

    print(caret_pos)

get_pos_at_line_column(line,col) giving incorrect Vector2 if column = 1

Steps to reproduce

do that

Minimal reproduction project

n/a

bitsawer commented 9 months ago

Looks like the returned x-position is the same for column 0 and 1 for some reason, other columns seem to work okay. A little easier EditorScript (right mouse button -> Run) for testing:

@tool
extends EditorScript

func _run():
    var code_edit_node = get_editor_interface().get_script_editor().get_current_editor().get_base_editor()

    var line = code_edit_node.get_caret_line(0)
    var column = code_edit_node.get_caret_column(0)

    var caret_pos = code_edit_node.get_pos_at_line_column(line,column)

    print(line + 1, ", ", column, ", ", caret_pos)
jsjtxietian commented 9 months ago

The col_bounds in get_rect_at_line_column is the same for column 0 and 1 :

RID text_rid = text.get_line_data(p_line)->get_line_rid(wrap_index);
Vector2 col_bounds = TS->shaped_text_get_grapheme_bounds(text_rid, p_column);
pos.x += col_bounds.x;
size.x = col_bounds.y - col_bounds.x;