ViText methods

Document access, mutation, UI, history and plugins.

1.0.0-beta.6 · Local build · desktop

Reading and readiness

MethodResultContract
getHTML / getCSS / getTextstringLast applied content/styles/text
getJSONDocumentNodeIndependent structured snapshot
getConfigurationResolvedConfigurationIndependent configuration copy
whenReadyPromise<void>Initial Markdown/CSS; rejection on error
whenSourceReadyPromise<void>Lazy HTML/CSS UI loading and mount
getModevisual/html/markdownActual active mode
isFullscreenbooleanFullscreen state
getSelectionSelectionInfofrom/to/text/revision
getPluginIdsstringCopy of installed IDs

Call argumentless names as editor.getHTML() and similarly.

Document changes

MethodResultContract
setContent(value, options?)Promise<ImportReport>format/allowLossy/css; checked atomic document+CSS, one history step; HTML/JSON without CSS applies before Promise return
setCSS(css)Promise<void>Checks the whole stylesheet, one history step, keeps selection
setSelection(from, to?)voidStructured positions; to defaults to from; does not mutate content
replaceRange(range, value, options?)Promise<ImportReport>HTML/Markdown, one history step; stale range.revision throws StaleDocumentError
replaceText(edits, revision)booleanSynchronous atomic plain replacements; RangeError or StaleDocumentError
transformText(callback)booleancallback(text, startsBlock) returns text; keeps marks/CSS, one history step
execute(command)booleanFormatting/history/table commands; false when inapplicable
insertTable(rows?, cols?, withHeaderRow?)booleanDefault 3×3/header; integer 1–20, otherwise RangeError
insertImage(attributes)booleanValidated src/dimensions/attributes, one history step
uploadImage(file, options?)Promise<boolean>signal/alt, upload callback and captured range; AbortError/StaleDocumentError

replaceText uses non-overlapping {from,to,text} edits inside individual text blocks, without inline atoms or replacement line breaks. Literal markup remains text. transformText/replaceText in the UI operate only in visual mode. CSS changes increase revision; structured positions are not getText offsets.

Interface, events and extensions

MethodResultContract
setMode(mode)voidErrors can keep the current mode; cannot bypass draft validation
setFullscreen(enabled)voidWithin the browser/iframe document; no native Fullscreen API; disabled feature throws
focus()voidReturns document focus and selection
on(name, listener)unsubscribeEvent subscription
off(name, listener)voidRemove that listener
usePlugin(plugin)disposerAPI 1 installation with ID/version/feature checks
removePlugin(id)voidPlugin cleanup
executePluginCommand(id, name)booleanRegistered command; unknown command throws
destroy()voidIdempotent cleanup; AggregateError possible after resources are released

Reconnecting the editor

getSourceDraft(): SourceDraft | null captures the active HTML+CSS or Markdown draft, including invalid source. Visual mode returns null. restoreSourceDraft(draft): Promise<void> restores it on a fresh visual instance after initial CSS and lazy source loading. Disabled modes reject. Normal validation, autosave and lossy-import confirmation still apply.

Before destroy(), save getJSON(), getCSS() and getSourceDraft(). Create a new instance with the new language, saved JSON/CSS and new plugin instances, then await restoreSourceDraft(draft) when non-null. Site language switching uses this flow. Document text is not translated. Undo history, open dialogs and source cursor position are not transferred.

execute commands

bold, italic, underline, strike, bulletList, orderedList, blockquote, codeBlock, paragraph, h1, h2, h3, undo, redo, insertTable, addRowAfter, addColumnAfter, deleteRow, deleteColumn, toggleHeaderRow, deleteTable. Import accepts H1–H6. Link/image/html/markdown/fullscreen are UI tools; not every toolbar tool is an execute command. Events, errors, document.

editor.execute('bold');
const range = editor.getSelection();
await editor.replaceRange(range, '<strong>New text</strong>');
editor.execute('undo');

Search documentation

No results. Try different words.

All documentation