D2Editor:registerFilter(handlerTable)
This routine registers a table of handler functions that can filter events
before they are sent to the
2D editor widget, or unregisters if nil is
passed.
Returns the text editor object.
The handlerTable is a table of
event handler functions. Any event described in the section on
Event Handling
can be filtered by a function in the handler table.
In the example code below, if the user presses Tab in the text editor ed, the tabKey filter function moves the focus to text editor ed2. Events charIn and arrowKey simply report which key was pressed and then allow the event to pass on through to the text editor.
Listing 3.4: Example for D2Editor:registerFilter()
-- Create an editor
ed = D2Editor.newRichText()
-- Register filters for events
ed:registerFilter {
tabKey = function()
ed2:setFocus()
return true
end,
charIn = function(ch)
print(ch)
return false
end,
arrowKey = function(key) print(key)
return false
end
}
Introduced in platform.apiLevel = '2.0'