Events
info
Check Related samples RichText Events
Action
Fires on any action in the editor
void Action(string action, [any data, boolean restoreFocus]){ ... };
Parameter | Type | Description |
---|---|---|
action | string | the name of an action |
data | any | optional, the edited data |
restoreFocus | boolean | optional, defines whether focus should be restored |
richtext.events.on("Action", function(action){
console.log("The " + action + " action is implemented");
});
Details
The list of possible actions is given below:
- add - add a character
- remove - remove a character
- update - update styles of text
- undo - revert the last action
- redo - re-apply the last reverted action
- copy - copy text
- paste - paste text
- cut - cut text
- clear - clear the editor
- parse - parse text
- selectAll - select all text
Change
Fires on any change in the editor
void Change(string action, boolean canUndo, boolean canRedo){ ... };
Parameter | Type | Description |
---|---|---|
action | string | the name of an action |
canUndo | boolean | defines whether the change can be reverted |
canRedo | boolean | defines whether the change can be re-applied |
richtext.events.on("Change", function(action){
console.log("The data have been changed by the following action: "+ action);;
});
Details
The list of possible actions is given below:
- add - add a character
- remove - remove a character
- update - update styles of text
- undo - revert the last action
- redo - re-apply the last reverted action
- copy - copy text
- paste - paste text
- cut - cut text
- clear - clear the editor
- parse - parse text
- selectAll - select all text
selectionChange
Fires on change of text selection made by a user
void selectionChange(object state){ ... };
Parameter | Type | Description |
---|---|---|
state | object | the state of selection |
richtext.events.on("selectionChange", function(state){
console.log("The current selection state is ", state);
});
Details
The state
object represents a hash of the following key:value properties:
range
- (boolean) defines whether the selection includes one character (false), or a range of them (true)left
- (object) the left coordinate of selection, contains the following properties:blockIndex
- (number) the index of a text block (a text line), enumeration starts from 0textIndex
- (number) the index of a text node (a text with common styling), enumeration starts from 0offset
- (number) the number of the first character within a text node in the selection
right
- (object) the right coordinate of selection, contains the following properties:blockIndex
- (number) the index of a text block (a text line), enumeration starts from 0textIndex
- (number) the index of a text node (a text with common styling), enumeration starts from 0offset
- (number) the number of the last character within a text node in the selection
For example:
richtext.events.on("selectionChange", function({
"left":{"blockIndex":0,"textIndex":1,"offset":0},
"right":{"blockIndex":0,"textIndex":1,"offset":5},
"range":true}){
// your code here
});
selectionRefresh
Fires on automatic change of selection
void selectionRefresh(){ ... };
richtext.events.on("selectionRefresh", function(){
console.log("Selection is refreshed");
});