tags: api/syscall references:
The Editor API provides functions for interacting with the editor interface.
editor.acceptCompletion()
Accepts the currently selected completion when the completion popup is active.
Returns:
boolean — Whether an active completion was accepted.editor.alert(message)
Shows a browser alert dialog.
Parameters:
message (string) — The alert message.editor.closeCompletion()
Closes the active editor completion popup.
editor.configureVimMode()
Configures CodeMirror Vim mode from the current SilverBullet Vim settings.
editor.confirm(message, options?)
Prompts the user to confirm or cancel an action.
Parameters:
message (string) — The confirmation message.options? ({ destructive?: boolean }) — Optional dialog styling settings.Returns:
boolean — Whether the user confirmed.editor.copyToClipboard(data)
Copies text or binary Blob data to the system clipboard. Clipboard access requires a secure HTTPS context.
Parameters:
data (string | Blob) — The text or Blob to copy.Example:
editor.copyToClipboard("Copied text")
editor.cursorCharLeft()
Moves the cursor one character left, respecting bidirectional text.
editor.cursorCharRight()
Moves the cursor one character right, respecting bidirectional text.
editor.cursorDocEnd()
Moves the cursor to the end of the document.
editor.cursorDocStart()
Moves the cursor to the start of the document.
editor.cursorGroupLeft()
Moves the cursor left by one character group or word.
editor.cursorGroupRight()
Moves the cursor right by one character group or word.
editor.cursorLineBoundaryLeft()
Moves the cursor to the left visual boundary of the current line.
editor.cursorLineBoundaryRight()
Moves the cursor to the right visual boundary of the current line.
editor.cursorLineDown()
Moves completion selection down when open, otherwise moves the cursor down one visual line.
editor.cursorLineEnd()
Moves the cursor to the end of the current logical line.
editor.cursorLineStart()
Moves the cursor to the start of the current logical line.
editor.cursorLineUp()
Moves completion selection up when open, otherwise moves the cursor up one visual line.
editor.cursorPageDown()
Moves completion selection down one page when open, otherwise moves the cursor down one viewport page.
editor.cursorPageUp()
Moves completion selection up one page when open, otherwise moves the cursor up one viewport page.
editor.deleteCharBackward()
Deletes the selection or the character before the cursor.
editor.deleteCharForward()
Deletes the selection or the character after the cursor.
editor.deleteGroupBackward()
Deletes the selection or the character group before the cursor.
editor.deleteGroupForward()
Deletes the selection or the character group after the cursor.
editor.deleteLine()
Deletes the current line or the lines touched by the selection.
editor.deleteLineBoundaryBackward()
Deletes the selection or text back to the current line boundary.
editor.deleteLineBoundaryForward()
Deletes the selection or text forward to the current line boundary.
editor.dispatch(change)
Dispatches a CodeMirror transaction to the editor view.
Parameters:
change (Transaction) — The CodeMirror transaction to dispatch.editor.downloadFile(filename, dataUrl)
Triggers a browser download of a data URL under the given filename.
Parameters:
filename (string) — The downloaded filename.dataUrl (string) — The data URL to download.Example:
editor.downloadFile("test.txt", "data:text/plain;base64,SGVsbG8=")
editor.filterBox(label, options, helpText?, placeHolder?)
Shows a filterable option picker similar to the page navigator.
Parameters:
label (string) — The label shown beside the filter input.options (FilterOption[]) — The available options.helpText? (string) — Help text shown below the picker.placeHolder? (string) — Placeholder text for the filter input.Returns:
FilterOption | undefined — The selected option, or undefined if dismissed.Example:
local result = editor.filterBox("Select:", {
{name = "Option 1", value = "1"},
{name = "Option 2", value = "2", description = "More details"}
})
editor.flashNotification(message, type?, options?)
Shows a flash notification in the editor UI.
Parameters:
message (string) — The message to display.type? (NotificationType) — The notification severity: "info", "error", or "warning".options? ({ timeout?: number; actions?: NotificationAction[] }) — Optional timeout and action buttons. A timeout of 0 keeps the notification visible until dismissed.Example:
editor.flashNotification("Update available", "warning", {
timeout = 0,
actions = {{
name = "Reload",
run = function() editor.reloadUI() end
}}
})
editor.focus()
Returns focus to the main editor.
editor.fold()
Folds the code or markup region at the cursor.
editor.foldAll()
Folds all foldable regions in the editor.
editor.forceLint()
Forces editor linting to run, including when the content has not changed.
editor.getCurrentEditor()
Returns the name of the currently active editor implementation.
Returns:
string — The editor name, or page for the page editor.editor.getCurrentLine()
Returns the current line's range and text, including a |^| cursor marker variant.
Returns:
{ from: number; to: number; text: string; textWithCursor: string } — The line containing the main selection head.editor.getCurrentPage()
Returns the name of the page or document currently open in the editor.
Returns:
string — The current page name.editor.getCurrentPageMeta()
Returns metadata for the page or document currently open in the editor.
Returns:
PageMeta | undefined — The current page metadata, if indexed.editor.getCurrentPath()
Returns the path of the page or document currently open in the editor.
Returns:
string — The current page path.editor.getCursor()
Returns the cursor position as a character offset from the start of the document.
Returns:
number — The cursor offset.editor.getRecentlyOpenedPages()
Returns page metadata ordered from most to least recently opened.
Returns:
PageMeta[] — Recently opened pages.editor.getSelection()
Returns the current selection range and selected text.
Returns:
{ from: number; to: number; text: string } — The main editor selection.editor.getText()
Returns the full text of the currently open page or document.
Returns:
string — The editor contents.editor.getUiOption(key)
Returns the current value of an editor UI option.
Parameters:
key (string) — The UI option key.Returns:
any — The option value.editor.goHistory(delta)
Moves backward or forward through browser history.
Parameters:
delta (number) — The relative history offset; negative moves backward and positive moves forward.editor.hidePanel(id)
Hides the panel at a specified editor UI location.
Parameters:
id (string) — The panel location identifier.editor.indentLess()
Decreases indentation for the current line or selection.
editor.indentMore()
Increases indentation for the current line or selection.
editor.insertAtCursor(text, scrollIntoView?, cursorPlaceHolder?)
Inserts text at the cursor and moves the cursor after it or to an optional |^| marker.
Parameters:
text (string) — The text to insert.scrollIntoView? (boolean) — Whether to scroll the new cursor position into view.cursorPlaceHolder? (boolean) — Whether to remove |^| and move the cursor to its position.editor.insertAtPos(text, pos, cursorPlaceHolder?)
Inserts text at a character offset, optionally placing the cursor at a |^| marker.
Parameters:
text (string) — The text to insert.pos (number) — The character offset at which to insert.cursorPlaceHolder? (boolean) — Whether to remove |^| and move the cursor to its position.editor.insertNewline()
Accepts the active completion, or inserts a newline with appropriate indentation.
editor.invokeCommand(name, args?)
Invokes a client command by name.
Parameters:
name (string) — The command name.args? (string[]) — Arguments passed to the command.editor.isMobile()
Checks whether the current device lacks a fine pointer and should be treated as mobile.
Returns:
boolean — Whether the editor is running in a mobile-style pointer environment.editor.moveCursor(pos, center?)
Moves and focuses the cursor at a character offset, scrolling it into view.
Parameters:
pos (number) — The character offset to move to.center? (boolean) — Whether to vertically center the cursor.editor.moveCursorToLine(line, column?, center?)
Moves the cursor to a one-based line and column, clamping the column to the line length.
Parameters:
line (number) — The one-based line number.column? (number) — The one-based column number.center? (boolean) — Whether to vertically center the cursor.editor.moveLineDown()
Moves the current line or selected lines downward.
editor.moveLineUp()
Moves the current line or selected lines upward.
editor.navigate(ref, replaceState?, newWindow?)
Navigates to a page reference without restoring its remembered cursor and scroll position.
Parameters:
ref (Ref | string) — The page reference to navigate to.replaceState? (boolean) — Whether to replace the current browser history state.newWindow? (boolean) — Whether to open the reference in a new window.Example:
editor.navigate("CHANGELOG@123")
editor.newWindow()
Opens the current SilverBullet URL in a new browser window.
editor.open(ref, replaceState?, newWindow?)
Opens a page reference and restores its remembered cursor and scroll position when possible.
Parameters:
ref (Ref | string) — The page reference to open.replaceState? (boolean) — Whether to replace the current browser history state.newWindow? (boolean) — Whether to open the reference in a new window.Example:
editor.open("CHANGELOG")
editor.openCommandPalette()
Opens the command palette.
editor.openPageNavigator(mode?)
Opens the page navigator in the requested browsing mode.
Parameters:
mode? (page | meta | document | all) — The navigator mode.editor.openSearchPanel()
Opens the editor's native search panel.
editor.openUrl(url, existingWindow?)
Opens a URL in the browser.
Parameters:
url (string) — The URL to open.existingWindow? (boolean) — Whether to reuse an existing window.editor.prompt(message, defaultValue?)
Prompts the user for text input.
Parameters:
message (string) — The prompt message.defaultValue? (string) — The initial input value.Returns:
string | undefined — The entered text, or undefined if dismissed.editor.rebuildEditorState()
Rebuilds the CodeMirror editor state from the current client configuration.
editor.redo()
Redoes the most recently undone editor change.
editor.reloadConfigAndCommands()
Reloads space scripts and styles, then rebuilds the editor state.
editor.reloadPage()
Force reloads the current page in the editor.
editor.reloadUI()
Force reloads the browser UI.
editor.replaceRange(from, to, text, cursorPlaceHolder?)
Replaces a text range, optionally placing the cursor at a |^| marker in the replacement.
Parameters:
from (number) — The start offset of the range.to (number) — The end offset of the range.text (string) — The replacement text.cursorPlaceHolder? (boolean) — Whether to remove |^| and move the cursor to its position.editor.save()
Forces the current page or document to be saved.
editor.selectAll()
Selects the entire editor document.
editor.selectCharLeft()
Extends the selection one character left, respecting bidirectional text.
editor.selectCharRight()
Extends the selection one character right, respecting bidirectional text.
editor.selectDocEnd()
Extends the selection to the end of the document.
editor.selectDocStart()
Extends the selection to the start of the document.
editor.selectGroupLeft()
Extends the selection left by one character group or word.
editor.selectGroupRight()
Extends the selection right by one character group or word.
editor.selectLineBoundaryLeft()
Extends the selection to the left visual boundary of the current line.
editor.selectLineBoundaryRight()
Extends the selection to the right visual boundary of the current line.
editor.selectLineDown()
Extends the selection downward by one visual line.
editor.selectLineEnd()
Extends the selection to the end of the current logical line.
editor.selectLineStart()
Extends the selection to the start of the current logical line.
editor.selectLineUp()
Extends the selection upward by one visual line.
editor.selectPageDown()
Extends the selection downward by one viewport page.
editor.selectPageUp()
Extends the selection upward by one viewport page.
editor.sendMessage(type, data?)
Sends a public message to the active document editor, if one is open.
Parameters:
type (string) — The message type.data? (any) — Data attached to the message.editor.setSelection(from, to)
Sets the main editor selection to a character range.
Parameters:
from (number) — The selection anchor offset.to (number) — The selection head offset.editor.setText(newText, shouldIsolateHistory?)
Updates the editor text with a minimal diff while preserving the cursor when possible.
Parameters:
newText (string) — The complete replacement text.shouldIsolateHistory? (boolean) — Whether to isolate the change in undo history.editor.setUiOption(key, value)
Sets an editor UI option and reloads the editor.
Parameters:
key (string) — The UI option key.value (any) — The option value.editor.showPanel(id, mode, html, script)
Shows an HTML panel in a specified editor UI location.
Parameters:
id (string) — The panel location identifier.mode (number) — The panel display mode or size.html (HTMLElement | HTMLElement[] | string) — The panel content.script (string) — A script associated with the panel content.editor.showProgress(progressType, progressPercentage?)
Shows, updates, or hides a sync or indexing progress indicator.
Parameters:
progressType (sync | index) — The operation represented by the indicator.progressPercentage? (number) — Completion percentage, or undefined to hide the indicator.editor.startCompletion()
Explicitly starts editor completion at the cursor.
editor.toggleComment()
Comments or uncomments the current line or selection.
editor.toggleFold()
Toggles folding for the region at the cursor.
editor.transposeChars()
Transposes the characters around the cursor.
editor.undo()
Undoes the most recent editor change.
editor.unfold()
Unfolds the folded region at the cursor.
editor.unfoldAll()
Unfolds all folded regions in the editor.
editor.updateBakedSections()
Re-evaluates every baked section on the current page and replaces each body with its latest output.
editor.uploadFile(accept?, capture?)
Opens the browser's native file picker and returns the selected file's bytes and metadata.
Parameters:
accept? (string) — Accepted file types for the file input.capture? (string) — The media capture mode for the file input.Returns:
UploadFile — The selected file's name, content type, and bytes.Example:
local file = editor.uploadFile(".txt")
print(file.name)
editor.vimEx(exCommand)
Executes a Vim Ex command in the active Vim-mode editor.
Parameters:
exCommand (string) — The Ex command to execute.