The Editor API provides functions for interacting with the editor interface.
Returns the Names|name of the page (or document) currently open in the editor.
Example: ${editor.getCurrentPage()}
Returns the meta data of the page (or document) currently open in the editor.
Example: ${editor.getCurrentPageMeta()}
Returns the Paths|path of the page or document currently open in the editor.
Example: ${editor.getCurrentPath()}
Returns the name of the currently open editor.
Example:
local editorName = editor.getCurrentEditor()
print(editorName)
Returns the full text of the currently open page.
Example:
local text = editor.getText()
print("Document length: " .. #text)
Returns the current line range and text.
Example:
local line = editor.getCurrentLine()
print("from " .. line.from .. " to " .. line.to .. " text " .. line.text .. " text with cursor " .. line.textWithCursor)
Updates the editor text while preserving cursor location.
Example:
local text = editor.getText()
editor.setText(text:upper(), false) -- Convert to uppercase
Insert text at the specified position.
Example:
editor.insertAtPos("Hello!", 0) -- Insert at beginning
Replace text in the specified range.
Example:
editor.replaceRange(0, 5, "New text")
Insert text at the current cursor position.
Example:
editor.insertAtCursor("Inserted at cursor")
Returns the cursor position as character offset.
Example:
local pos = editor.getCursor()
print("Cursor at position: " .. pos)
Returns the current selection range.
Example:
local sel = editor.getSelection()
print("Selection from " .. sel.from .. " to " .. sel.to)
Sets the current selection range.
Example:
editor.setSelection(0, 10) -- Select first 10 characters
Move the cursor to a specific position.
Example:
editor.moveCursor(0, true) -- Move to start and center
Move the cursor to a specific line and column.
Example:
editor.moveCursorToLine(1, 1, true) -- Move to start of first line
Invokes a client command by name.
Example:
editor.invokeCommand("Stats: Show")
Force saves the current page.
Example:
editor.save()
Navigates to the specified page reference.
Parameters:
- ref: The (string) reference to navigate to, see Links#Link syntax (String refs)|string refs
- replaceState: Whether to replace the current history state
- newWindow: Whether to open in a new window
Example:
editor.navigate("CHANGELOG@123")
Opens the page navigator.
Example:
editor.openPageNavigator("page")
Opens the command palette.
Example:
editor.openCommandPalette()
Force reloads the current page.
Example:
editor.reloadPage()
Force reloads the browser UI.
Example:
editor.reloadUI()
Rebuilds the editor state to ensure the dispatch updates the state.
Example:
editor.rebuildEditorState()
Reloads the config and commands, also in the server.
Example:
editor.reloadConfigAndCommands()
Opens the specified URL in the browser.
Example:
editor.openUrl("https://example.com")
Opens a new window.
Example:
editor.newWindow()
Moves in the browser history.
Example:
editor.goHistory(-1) -- Go back
Shows a panel in the editor.
Example:
editor.showPanel("rhs", 1, "<h1>Hello</h1>")
Hides a panel in the editor.
Example:
editor.hidePanel("rhs")
Shows a flash notification.
Example:
editor.flashNotification("Operation completed", "info")
Triggers a file download in the browser.
Example:
editor.downloadFile("test.txt", "data:text/plain;base64,SGVsbG8=")
Opens a file upload dialog.
Example:
local file = editor.uploadFile(".txt", nil)
print("Uploaded: " .. file.name)
Copies data to the clipboard.
Example:
editor.copyToClipboard("Copied text")
Shows a filter box UI.
Example:
local result = editor.filterBox("Select:", {
{ name="Option 1", value="1" },
{ name="Option 2", value="2", description="More details about 2" }
})
Toggles code folding at the current position.
Example:
editor.toggleFold()
Folds all foldable regions.
Example:
editor.foldAll()
Unfolds all folded regions.
Example:
editor.unfoldAll()
Undoes the last change.
Example:
editor.undo()
Redoes the last undone change.
Example:
editor.redo()
Opens the editor's search panel.
Example:
editor.openSearchPanel()
Deletes the current line.
Example:
editor.deleteLine()
Comments or uncomments the current line.
Example:
editor.toggleComment()
Moves the current line up.
Example:
editor.moveLineUp()
Moves the current line down.
Example:
editor.moveLineDown()
Executes a Vim ex command.
Example:
editor.vimEx(":w")
Sends a message to the editor.
Example:
editor.sendMessage("custom-event", { data: "value" })
Shows a prompt dialog.
Example:
local result = editor.prompt("Enter your name:", "John")
Shows a confirmation dialog.
Example:
local confirmed = editor.confirm("Are you sure?")
Shows an alert dialog.
Example:
editor.alert("Operation completed")
Gets a UI option value.
Example:
local theme = editor.getUiOption("theme")
Sets a UI option value.
Example:
editor.setUiOption("theme", "dark")