Synchronous Editor Template
Use this template when your editor's read/write operations are synchronous (return values directly, not Promises).
// Initialize the Synchronous TextWriter
var myWriter = new INVOX.TextWriterBase()
/* --------- ESSENTIAL METHODS --------- */
// Allows you to specify the current editor instance.
myWriter.setEditor = function(editorInstance) {
if (!editorInstance) {
throw "Parameter editorInstance cannot be null or undefined"
}
this.editor = editorInstance
}
// Allows you to get the current editor instance.
myWriter.getEditor = function() {
return this.editor
}
// Allows you to get the editor text content.
myWriter.getText = function() {
const currentEditor = this.getEditor()
return getTextFromEditor(currentEditor)
function getTextFromEditor(currentEditor) {
let text = ""
// TODO: Here goes your code...
return text
}
}
// Allows you to get current selection range.
myWriter.getSelection = function() {
const currentEditor = this.getEditor()
const { start, end } = getSelectionFromEditor(currentEditor)
return new INVOX.Range(start, end)
function getSelectionFromEditor(currentEditor) {
let start = 0
let end = 0
// TODO: Here goes your code...
return { start, end }
}
}
// Allows you to set current selection range.
myWriter.setSelection = function(range) {
const { start, end } = range
const currentEditor = this.getEditor()
setSelectionInEditor(currentEditor, start, end)
function setSelectionInEditor(currentEditor, start, end) {
// TODO: Here goes your code...
}
}
// Allows you to write in the editor where the caret is.
myWriter.write = function(text) {
const currentEditor = this.getEditor()
writeTextInEditor(currentEditor, text)
function writeTextInEditor(currentEditor, text) {
// TODO: Here goes your code...
}
}
/* --------- EXTRA METHODS --------- */
// Allows you to apply redo in the editor.
myWriter.redo = function() {
const currentEditor = this.getEditor()
applyRedo(currentEditor)
function applyRedo(currentEditor) {
// TODO: Here goes your code...
}
}
// Allows you to apply undo in the editor.
myWriter.undo = function() {
const currentEditor = this.getEditor()
applyUndo(currentEditor)
function applyUndo(currentEditor) {
// TODO: Here goes your code...
}
}
// Allows you to manage the status of redo/undo operations.
myWriter.updateRedoUndoStack = function() {
const currentEditor = this.getEditor()
updateRedoUndoStack(currentEditor)
function updateRedoUndoStack() {
// TODO: Here goes your code...
}
}
// Allows you to specify the line break format by the editor used.
myWriter.writeNewLine = function() {
// By default this function writes "\n".
// Override if your editor uses a different format:
// this.write("<br>")
}
// Allows you to specify the paragraph break format by the editor used.
myWriter.writeNewParagraph = function() {
// By default this function writes two line breaks "\n\n".
// Override if your editor uses a different format:
// this.write("<br><br>")
}