2025-02-06 17:04:45 +08:00
|
|
|
The Editor API provides functions for interacting with the editor interface.
|
2025-01-17 03:41:52 +08:00
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.getCurrentPage()
|
2025-01-17 03:41:52 +08:00
|
|
|
Returns the name of the page currently open in the editor.
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
Example: ${editor.getCurrentPage()}
|
2025-01-17 03:41:52 +08:00
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.getCurrentPageMeta()
|
2025-01-17 03:41:52 +08:00
|
|
|
Returns the meta data of the page currently open in the editor.
|
|
|
|
|
|
|
|
Example:
|
2025-02-06 17:04:45 +08:00
|
|
|
${editor.getCurrentPageMeta()}
|
2025-01-17 03:41:52 +08:00
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.getText()
|
2025-01-17 03:41:52 +08:00
|
|
|
Returns the full text of the currently open page.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local text = editor.getText()
|
2025-01-17 03:41:52 +08:00
|
|
|
print("Document length: " .. #text)
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.setText(text, isolateHistory)
|
2025-01-17 03:41:52 +08:00
|
|
|
Updates the editor text while preserving cursor location.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local text = editor.getText()
|
|
|
|
editor.setText(text:upper(), false) -- Convert to uppercase
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.insertAtPos(text, pos)
|
2025-01-17 03:41:52 +08:00
|
|
|
Insert text at the specified position.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.insertAtPos("Hello!", 0) -- Insert at beginning
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.replaceRange(from, to, text)
|
2025-01-17 03:41:52 +08:00
|
|
|
Replace text in the specified range.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.replaceRange(0, 5, "New text")
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.insertAtCursor(text, scrollIntoView?)
|
2025-01-17 03:41:52 +08:00
|
|
|
Insert text at the current cursor position.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.insertAtCursor("Inserted at cursor")
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.getCursor()
|
2025-01-17 03:41:52 +08:00
|
|
|
Returns the cursor position as character offset.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local pos = editor.getCursor()
|
2025-01-17 03:41:52 +08:00
|
|
|
print("Cursor at position: " .. pos)
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.getSelection()
|
2025-01-17 03:41:52 +08:00
|
|
|
Returns the current selection range.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local sel = editor.getSelection()
|
2025-01-17 03:41:52 +08:00
|
|
|
print("Selection from " .. sel.from .. " to " .. sel.to)
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.setSelection(from, to)
|
2025-01-17 03:41:52 +08:00
|
|
|
Sets the current selection range.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.setSelection(0, 10) -- Select first 10 characters
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.moveCursor(pos, center)
|
2025-01-17 03:41:52 +08:00
|
|
|
Move the cursor to a specific position.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.moveCursor(0, true) -- Move to start and center
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.moveCursorToLine(line, column, center)
|
2025-01-17 03:41:52 +08:00
|
|
|
Move the cursor to a specific line and column.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.moveCursorToLine(1, 1, true) -- Move to start of first line
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.openPageNavigator(mode)
|
2025-01-17 03:41:52 +08:00
|
|
|
Opens the page navigator.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.openPageNavigator("page")
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.openCommandPalette()
|
2025-01-17 03:41:52 +08:00
|
|
|
Opens the command palette.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.openCommandPalette()
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.showPanel(id, mode, html, script)
|
2025-01-17 03:41:52 +08:00
|
|
|
Shows a panel in the editor.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.showPanel("rhs", 1, "<h1>Hello</h1>")
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.hidePanel(id)
|
2025-01-17 03:41:52 +08:00
|
|
|
Hides a panel in the editor.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.hidePanel("rhs")
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.flashNotification(message, type)
|
2025-01-17 03:41:52 +08:00
|
|
|
Shows a flash notification.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.flashNotification("Operation completed", "info")
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.downloadFile(filename, dataUrl)
|
2025-01-17 03:41:52 +08:00
|
|
|
Triggers a file download in the browser.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.downloadFile("test.txt", "data:text/plain;base64,SGVsbG8=")
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.uploadFile(accept, capture)
|
2025-01-17 03:41:52 +08:00
|
|
|
Opens a file upload dialog.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local file = editor.uploadFile(".txt", nil)
|
2025-01-17 03:41:52 +08:00
|
|
|
print("Uploaded: " .. file.name)
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.copyToClipboard(data)
|
2025-01-17 03:41:52 +08:00
|
|
|
Copies data to the clipboard.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.copyToClipboard("Copied text")
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.toggleFold()
|
2025-01-17 03:41:52 +08:00
|
|
|
Toggles code folding at the current position.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.toggleFold()
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.foldAll()
|
2025-01-17 03:41:52 +08:00
|
|
|
Folds all foldable regions.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.foldAll()
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.unfoldAll()
|
2025-01-17 03:41:52 +08:00
|
|
|
Unfolds all folded regions.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.unfoldAll()
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
### editor.openSearchPanel()
|
2025-01-17 03:41:52 +08:00
|
|
|
Opens the editor's search panel.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
editor.openSearchPanel()
|