import type { FilterOption } from "../../web/types.ts"; import { syscall } from "./syscall.ts"; export function getCurrentPage(): Promise { return syscall("editor.getCurrentPage"); } export function setPage(newName: string): Promise { return syscall("editor.setPage", newName); } export function getText(): Promise { return syscall("editor.getText"); } export function getCursor(): Promise { return syscall("editor.getCursor"); } export function getSelection(): Promise<{ from: number; to: number }> { return syscall("editor.getSelection"); } export function setSelection(from: number, to: number): Promise { return syscall("editor.setSelection", from, to); } export function save(): Promise { return syscall("editor.save"); } export function navigate( name: string, pos?: string | number, replaceState = false, newWindow = false, ): Promise { return syscall("editor.navigate", name, pos, replaceState, newWindow); } export function reloadPage(): Promise { return syscall("editor.reloadPage"); } export function openUrl(url: string, existingWindow = false): Promise { return syscall("editor.openUrl", url, existingWindow); } // Force the client to download the file in dataUrl with filename as file name export function downloadFile(filename: string, dataUrl: string): Promise { return syscall("editor.downloadFile", filename, dataUrl); } export function flashNotification( message: string, type: "info" | "error" = "info", ): Promise { return syscall("editor.flashNotification", message, type); } export function filterBox( label: string, options: FilterOption[], helpText = "", placeHolder = "", ): Promise { return syscall("editor.filterBox", label, options, helpText, placeHolder); } export function showPanel( id: "lhs" | "rhs" | "bhs" | "modal", mode: number, html: string, script = "", ): Promise { return syscall("editor.showPanel", id, mode, html, script); } export function hidePanel(id: "lhs" | "rhs" | "bhs" | "modal"): Promise { return syscall("editor.hidePanel", id); } export function insertAtPos(text: string, pos: number): Promise { return syscall("editor.insertAtPos", text, pos); } export function replaceRange( from: number, to: number, text: string, ): Promise { return syscall("editor.replaceRange", from, to, text); } export function moveCursor(pos: number, center = false): Promise { return syscall("editor.moveCursor", pos, center); } export function insertAtCursor(text: string): Promise { return syscall("editor.insertAtCursor", text); } export function dispatch(change: any): Promise { return syscall("editor.dispatch", change); } export function prompt( message: string, defaultValue = "", ): Promise { return syscall("editor.prompt", message, defaultValue); } export function confirm( message: string, ): Promise { return syscall("editor.confirm", message); } export function getUiOption(key: string): Promise { return syscall("editor.getUiOption", key); } export function setUiOption(key: string, value: any): Promise { return syscall("editor.setUiOption", key, value); } // Vim specific export function vimEx(exCommand: string): Promise { return syscall("editor.vimEx", exCommand); }