How do I set a TextEdit caret position? and is there a way to ignore Tab and Enter indentations?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By IHate

I want to change the position of the caret to the end of TextEdit.text I could do this easily with a LineEdit using caret_postion() but TextEdit doesn’t have it and I want to keep the syntax highlight of TextEdit. The only solution I could come up with was to simulate inputs like control+right after setting TextEdit.text to move the caret and I was wondering if there’s a better way to accomplish this.

Also is there a way to turn off things like Tab space or Enter new line for TextEdit? I turned off shortcuts but it seem to be unrelated to these. My current solution is to yield for a frame and set Textedit.textafter the Tab or Enter keys Input has already gone through so it doesn’t display the indentations.

Edit:
The solution for the second question is to manually set the inputs as handled.

func _input(event):
  if event.is_action_pressed("ui_accept") && get_focus_owner() is TextEdit:
    alternative_func()
    get_tree().set_input_as_handled()

This will give you the ability to change the functionality of the key on that Control node.

:bust_in_silhouette: Reply From: jgodfrey

You can set the cursor position in a TextEdit by line and column as shown below…

$TextEdit.cursor_set_line(2)
$TextEdit.cursor_set_column(5)
$TextEdit.insert_text_at_cursor("new_text")

When I was reading the documentation the word column set me off my bad.

IHate | 2020-11-01 23:32