Writer Methods


Use the Invox Dictation SDK API to implement your own TextWriter.

Essential methods

setEditor()

FunctionDescriptionParametersReturns (sync)Returns (async)
setEditor(editorInstance)Specify the current editor instance.ObjectvoidPromise<void>

Allows you to set the editor instance that you use in your web application.

Tests: INVOX.SetWriterTarget() — sets the current editor instance.

getEditor()

FunctionDescriptionParametersReturns (sync)Returns (async)
getEditor()Get the current editor instance.—ObjectPromise<Object>

Tests: INVOX.GetWriterTarget() — get the current editor instance.

getText()

FunctionDescriptionParametersReturns (sync)Returns (async)
getText()Get the editor text content.—StringPromise<String>
The value returned must be plain text and cannot contain format strings.

Tests: INVOX.GetText() — returns the full plain text from the editor content.

write()

FunctionDescriptionParametersReturns (sync)Returns (async)
write(text)Write in the editor where the caret is.StringvoidPromise<void>

Tests: INVOX.Write(), INVOX.AppendText(), INVOX.PrependText(), INVOX.ClearText()

getSelection()

FunctionDescriptionParametersReturns (sync)Returns (async)
getSelection()Get the range of the current selection.—INVOX.RangePromise<INVOX.Range>

Returns an INVOX.Range object. If there is no selection, returns the current caret position.

e.g: Consider ^ as the caret position, and [ ] the selection.

EDITOR CONTENT: "this [is all text] in the editor"
CALL: getSelection()
OUTPUT: new INVOX.Range(5, 16)

Tests: INVOX.Write() — writes the text at the position of the current selection.

setSelection()

FunctionDescriptionParametersReturns (sync)Returns (async)
setSelection(range)Select text in the current editor.INVOX.RangevoidPromise<void>

If the values of start and end are the same, you are setting the position of the caret.

e.g:
EDITOR CONTENT: "this is all text in the editor^"
CALL: setSelection(new INVOX.Range(5, 16))
EDITOR CONTENT: "this [is all text] in the editor"

Tests: INVOX.SetSelection() — select the range of text passed as a parameter.

getTextContext()

FunctionDescriptionParametersReturns (sync)Returns (async)
getTextContext()Get the context around the caret position.—Array<String>Promise<Array<String>>
If you already have getSelection() and getText() implemented, you can skip this method — it is automatically derived from them.

Returns [leftText, rightText] — the text before and after the caret. Used by Invox Dictation to decide whether to include spaces or capital letters when typing.

Extra methods

undo()

FunctionDescriptionParametersReturns (sync)Returns (async)
undo()Apply undo in the editor.—voidPromise<void>

redo()

FunctionDescriptionParametersReturns (sync)Returns (async)
redo()Apply redo in the editor.—voidPromise<void>

updateRedoUndoStack()

FunctionDescriptionParametersReturns (sync)Returns (async)
updateRedoUndoStack()Manage the redo/undo operations stack.—voidPromise<void>
Only implement this if the editor does not have its own undo/redo stack management.

writeNewLine()

FunctionDescriptionParametersReturns (sync)Returns (async)
writeNewLine()Specify the line break format for the editor.—voidPromise<void>

By default, Invox Dictation writes \n. Override this if your editor uses a different format (e.g. <br>):

myWriter.writeNewLine = function() {
    this.write("<br>");
}

writeNewParagraph()

FunctionDescriptionParametersReturns (sync)Returns (async)
writeNewParagraph()Specify the paragraph break format for the editor.—voidPromise<void>

By default, Invox Dictation writes \n\n. Override this if your editor uses a different format.