export(int) var LIMIT = 10
var current_text = ''
var cursor_line = 0
var cursor_column = 0
func _on_TextEdit_text_changed():
var new_text : String = $Control/TextEdit.text
if new_text.length() > LIMIT:
$Control/TextEdit.text = current_text
# when replacing the text, the cursor will get moved to the beginning of the
# text, so move it back to where it was
$Control/TextEdit.cursor_set_line(cursor_line)
$Control/TextEdit.cursor_set_column(cursor_column)
current_text = $Control/TextEdit.text
# save current position of cursor for when we have reached the limit
cursor_line = $Control/TextEdit.cursor_get_line()
cursor_column = $Control/TextEdit.cursor_get_column()
Thank you that works perfectly!
GoGirlGaming | 2019-04-24 17:01
Are there any disadvantages of ignoring the cursor and all?