Edit.caret read/write property


Get or set the Edit current caret position. The caret position starts from 1 (before the first character) and ends after the last character.
Set the caret position to 0 to set it at the last character (without the need to get the Edit's content size).

  • Caret position is expressed in characters : the caret in position 1 is just before the first character.
  • Use caret position 0 to reach end of the Edit's content.

Example

local ui = require "ui" -- create a simple window local win = ui.Window("Edit.caret sample", "fixed", 340, 230) local label = ui.Label(win, "Enter text : ", 10, 10) local edit = ui.Edit(win, "", label.x + label.width + 8, label.y) -- set edit.properties edit.font = "Times New Roman" edit.fontsize = 10 edit.wordwrap = true edit.text = [[Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.]] function edit:onSelect() -- prevent any selection or any caret move edit.caret = 0 end win:show() -- update user interface repeat ui.update() until not win.visible