This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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.

in Engine by (406 points)
edited by

1 Answer

+2 votes
Best answer

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")
by (22,704 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.