Edit:searchdown(findtext, [ iswholeword ], [ matchcase ]) method
Search text withins the Edit content, forward from the current caret position.
Parameters
findtext
A string value, representing the text to search for.
iswholeword
A boolean value, indicating to search only for whole words that match the search text.
matchcase
A boolean value, indicating that the search operation is case-sensitive.
Return value
This function returns two numbers : the position of the character at the start of the search text, and the position at its end.If the search text is not found, the function returns nil
Example
local ui = require "ui"
-- create a simple window
local win = ui.Window("Edit.searchdown sample", "fixed", 520, 460)
local upbtn = ui.Button(win, 'Search up for "it"', 130, 10)
local downbtn = ui.Button(win, 'Search down for "it"', 250, 10)
local edit = ui.Edit(win, "", 10, 44, 500, 410)
-- set edit.properties
edit.font = "Times New Roman"
edit.fontsize = 12
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.]]
edit.caret = 1
-- set search function for each button
upbtn.search = edit.searchup
downbtn.search = edit.searchdown
-- one single onClick event for upbtn and downbtn
function upbtn:onClick()
local from, to = self.search(edit, "it")
if from ~= nil then
edit.selection.from = from
edit.selection.to = to
end
end
downbtn.onClick = upbtn.onClick
win:show()
-- update user interface
repeat
ui.update()
until not win.visible