context_error Callback Type
Function prototype:
function funcname (doc, opcode, errcode, object)
context_error is called when a context error is detected after certain edit operations, such as inserting tags or text.
context_error must return one of the following values:
• -2 — Handled the error, the operation will return failure status.
• -1 — Handled the error, the operation will return success status.
• 0 — Did not handle the error so normal error processing should be done. That is, the context error message will be displayed.
|
The variable main::ERROR is set before context_error is called to hold the error message to be displayed to the user.
|
context_error will not be called if:
• an attempt to do a pending delete caused a context error
• an auto-inserted tag caused a context error
If pending delete succeeded, but an error occurred, context_error will be called after the delete. If context_error returns 0, the delete will be undone, otherwise it will not be undone.
Arguments:
• doc is the identifier of the document in which the insertion was attempted and can be used to derive the cursor position and/or the selected region.
• opcode specifies the operation being attempted and currently is one of the following values:
◦ 1 — insert tag
◦ 2 — insert character or string
• errcode defines the type of error and is one of the following values:
◦ 1 — selected region is not balanced (for inserting tag pairs only)
◦ 2 — document is read-only
◦ 3 — cursor is in a protected region
◦ 4 — element is invalid at the cursor or at the beginning of the region if tag pairs are being inserted
|
The error codes indicate the order of testing. For example, if the region is not balanced, then the test for a protected region has not yet been done. If in a protected region, the test for a context error has not yet been done.
|
• object is opcode specific:
◦ for insert tag — it is the name of the tag for which insertion failed
◦ for insert character or string — it is the character or string