Caret

Module provides with methods to work with Caret built-in class

setToFirstBlock — sets caret to the first Block

setToLastBlock — sets caret to the last Block

setToPreviousBlock — sets caret to the previous Block

setToNextBlock — sets caret to the next Block

setToBlock — sets caret to the Block

focus — focus Editor

By default, caret will be set at the start with zero offset. You can choose position passing start or end and pass offset parameter

setToFirstBlock

Method sets caret to the first Block (with index = 0)

Parameters

String Caret position at the Block (can be only start or end
Number Caret offset at the node

Return value

Boolean Returns true if caret was set
setToFirstBlock(position: string = this.Editor.Caret.positions.DEFAULT, offset: number = 0): boolean

Example

class MyTool { constructor({data, api}){ this.api = api; // ... } setAtTheEnd() { this.api.caret.setToFirstBlock('end', 0); } // ... other methods }

setToLastBlock

Method sets caret to the last Block (with index = length - 1)

Parameters

String Caret position at the Block (can be only start or end
Number Caret offset at the node

Return value

Boolean Returns true if caret was set
setToLastBlock(position: string = this.Editor.Caret.positions.DEFAULT, offset: number = 0): boolean

Example

class MyTool { constructor({data, api}){ this.api = api; // ... } setAtTheStart() { this.api.caret.setToLastBlock('start', 0); } // ... other methods }

setToPreviousBlock

Method sets caret to the previous Block

Parameters

String Caret position at the Block (can be only start or end
Number Caret offset at the node

Return value

Boolean Returns true if caret was set
setToPreviousBlock(position: string = this.Editor.Caret.positions.DEFAULT, offset: number = 0): boolean

Example

class MyTool { constructor({data, api}){ this.api = api; // ... } setToPreviousBlock() { this.api.caret.setToPreviousBlock('start', 0); } // ... other methods }

setToNextBlock

Method sets caret to the next Block

Parameters

String Caret position at the Block (can be only start or end
Number Caret offset at the node

Return value

Boolean Returns true if caret was set
setToNextBlock(position: string = this.Editor.Caret.positions.DEFAULT, offset: number = 0): boolean

Example

class MyTool { constructor({data, api}){ this.api = api; // ... } setToNextBlock() { this.api.caret.setToNextBlock('start', 0); } // ... other methods }

setToBlock

Method sets caret to the Block with passed index

Parameters

Number index of Block
String Caret position at the Block (can be only start or end

Return value

Boolean Returns true if caret was set
setToBlock(index: number, position: string = this.Editor.Caret.positions.DEFAULT, offset: number = 0): boolean

Example

class MyTool { constructor({data, api}){ this.api = api; // ... } setToBlock() { this.api.caret.setToBlock('start', 0); // set caret at the start of first Block } // ... other methods }

focus

Method set caret always to the first Block by default

Parameters

Boolean set caret at the end or not. By default it is false

Return value

Method does not return anything

focus(atEnd: boolean = false)

Example

class MyTool { constructor({data, api}){ this.api = api; // ... } focusEditor() { this.api.caret.focus(true); } // ... other methods }