document
提供给 document 文件 View 和文档命令。声明 document,写入还需 access: write。observe 返回初始快照与订阅。edit 修改工作副本,版本不匹配返回 stale;save 遇到磁盘冲突返回 conflict。这两种结果不是异常。应保留草稿并串行编辑。
签名、参数及返回类型从 SDK 自动生成;可选成员不保证在每个宿主和上下文中存在。
TextDocument
Section titled “TextDocument”TextDocument.read
Section titled “TextDocument.read”支持宿主: Lite Mobile
读取当前工作副本快照,包含未保存的修改。
read(): Promise<TextSnapshot>;返回值: Promise<TextSnapshot>.
TextDocument.observe
Section titled “TextDocument.observe”支持宿主: Lite Mobile
返回初始快照和后续变化的订阅。
observe(listener: (state: TextSnapshot) => void, onError?: ObserverErrorHandler): Promise<{ snapshot: TextSnapshot; subscription: Disposable;}>;| 参数 | 类型 | 必填 |
|---|---|---|
listener |
(state: TextSnapshot) => void |
是 |
onError |
ObserverErrorHandler |
否 |
返回值: Promise<{ snapshot: TextSnapshot; subscription: Disposable; }>.
TextDocument.edit
Section titled “TextDocument.edit”支持宿主: Lite
expectedVersion 匹配时替换工作副本文本,stale 结果不会覆盖较新的内容。
edit(change: { text: string; expectedVersion: string; label?: string; group?: string;}): Promise<{ status: "applied" | "stale"; snapshot: TextSnapshot;}>;| 参数 | 类型 | 必填 |
|---|---|---|
change |
{ text: string; expectedVersion: string; label?: string; group?: string; } |
是 |
返回值: Promise<{ status: "applied" | "stale"; snapshot: TextSnapshot; }>.
TextDocument.save
Section titled “TextDocument.save”支持宿主: Lite
保存工作副本;磁盘冲突时返回 conflict 并保留草稿。
save(): Promise<{ status: "saved" | "conflict"; snapshot: TextSnapshot;}>;返回值: Promise<{ status: "saved" | "conflict"; snapshot: TextSnapshot; }>.
TextDocument.undo
Section titled “TextDocument.undo”支持宿主: Lite
撤销编辑并返回结果快照。
undo(): Promise<TextSnapshot>;返回值: Promise<TextSnapshot>.
TextDocument.redo
Section titled “TextDocument.redo”支持宿主: Lite
重做编辑并返回结果快照。
redo(): Promise<TextSnapshot>;返回值: Promise<TextSnapshot>.
关联类型: TextSnapshot, ObserverErrorHandler, Disposable.