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 (388 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 (10,856 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 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 webmaster@godotengine.org with your username.