Type Function Object TextField Library native.* Return value none Revision Release 2022.3683 Keywords setSelection See also native.newTextField()
Sets the cursor position if the start and end positions are the same. Alternatively, sets a range of selected text if the start and end positions are different.
object:setSelection( startPosition, endPosition )
Number. The cursor position or the beginning of the selection area. To select the first character, this value should be 0
.
Number. The end of the selection area (if greater than startPosition
). The last character will be used if this number is greater than the length of the current string in the text field.
This API does not work in the Corona Simulator for macOS.
local textField = native.newTextField( 160, 240, 280, 40 ) textField.text = "asdf" native.setKeyboardFocus( textField ) textField:setSelection( 1, 3 ) -- The characters "sd" will be selected textField:setSelection( 1, 1 ) -- Cursor will be placed between "a" and "s"