Table of contents

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

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

String Caret position at the Block (can be only start or end
Number Caret offset at the node
Boolean Returns true if caret was set
setToFirstBlock(position: string = this.Editor.Caret.positions.DEFAULT, offset: number = 0): boolean
class MyTool { constructor({data, api}){ this.api = api; // ... } setAtTheEnd() { this.api.caret.setToFirstBlock('end', 0); } // ... other methods }

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

String Caret position at the Block (can be only start or end
Number Caret offset at the node
Boolean Returns true if caret was set
setToLastBlock(position: string = this.Editor.Caret.positions.DEFAULT, offset: number = 0): boolean
class MyTool { constructor({data, api}){ this.api = api; // ... } setAtTheStart() { this.api.caret.setToLastBlock('start', 0); } // ... other methods }

Method sets caret to the previous Block

String Caret position at the Block (can be only start or end
Number Caret offset at the node
Boolean Returns true if caret was set
setToPreviousBlock(position: string = this.Editor.Caret.positions.DEFAULT, offset: number = 0): boolean
class MyTool { constructor({data, api}){ this.api = api; // ... } setToPreviousBlock() { this.api.caret.setToPreviousBlock('start', 0); } // ... other methods }

Method sets caret to the next Block

String Caret position at the Block (can be only start or end
Number Caret offset at the node
Boolean Returns true if caret was set
setToNextBlock(position: string = this.Editor.Caret.positions.DEFAULT, offset: number = 0): boolean
class MyTool { constructor({data, api}){ this.api = api; // ... } setToNextBlock() { this.api.caret.setToNextBlock('start', 0); } // ... other methods }

Method sets caret to the Block with passed index

Number index of Block
String Caret position at the Block (can be only start or end
Boolean Returns true if caret was set
setToBlock(index: number, position: string = this.Editor.Caret.positions.DEFAULT, offset: number = 0): boolean
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 }

Method set caret always to the first Block by default

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

Method does not return anything

focus(atEnd: boolean = false)
class MyTool { constructor({data, api}){ this.api = api; // ... } focusEditor() { this.api.caret.focus(true); } // ... other methods }
☝️
Note.
Method has a shorthand