Edit.selection readonly property


Returns a proxy table to get/set the current Edit selection properties.
You can get or set the following fields :

  • selection.from: the starting character position of the current selection (1 means the caret is just before the first character)
  • selection.to: the ending character position of the current selection (0 means the caret is after the last character)
  • selection.text: the text of the current selection
  • selection.fgcolor: the text color (a number RGB value) of the current selection (nil means default color)
  • selection.bgcolor: the background color (a number RGB value) of the current selection (nil means default color)
  • selection.font: the font name of the current selection
  • selection.fontsize: the font size, in pixels, of the current selection
  • selection.fontstyle: the fontstyle of the current selection
  • selection.visible: controls the scrolling/visibility when manipulating the selection
  • You can use #edit.selection to get current selection length, in characters.
Edit.selection is a proxy table and should not be used for anything other than setting/getting field values.

Example

local ui = require "ui" -- create a simple window local win = ui.Window("Edit.selection sample", "fixed", 520, 460) local button = ui.Button(win, "Change current selection format", 180, 10) local edit = ui.Edit(win, "", 10, 44, 500, 410) -- 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 button:onClick() edit.selection.font, edit.selection.fontsize, edit.selection.fontstyle, edit.selection.fgcolor = ui.fontdialog(edit, edit.selection.fgcolor) end win:show() -- update user interface repeat ui.update() until not win.visible