Skip to main content

Mountain/Vine/Server/Notification/
ApplyTextEdits.rs

1
2//! Cocoon → Mountain `window.applyTextEdits` notification.
3//!
4//! Fired when an extension calls `editor.edit(editBuilder => { ... })`.
5//! Cocoon's TextEditor shim collects the edits and sends them here.
6//! Mountain emits `sky://editor/apply-text-edits` so Sky can apply them
7//! via `ICodeEditorService.listCodeEditors()` → `editor.executeEdits(...)`.
8//!
9//! Payload shape:
10//! ```json
11//! {
12//!   "uri": "file:///path/to/file.ts",
13//!   "edits": [
14//!     { "range": { "startLineNumber": 1, "startColumn": 1, "endLineNumber": 1, "endColumn": 10 }, "text": "replacement" },
15//!     { "range": { ... }, "text": "" }
16//!   ]
17//! }
18//! ```
19
20use serde_json::Value;
21use tauri::{AppHandle, Emitter};
22
23use crate::{Vine::Server::MountainVinegRPCService::MountainVinegRPCService, dev_log};
24
25pub async fn ApplyTextEdits(Service:&MountainVinegRPCService, Parameter:&Value) {
26	let Uri = Parameter.get("uri").and_then(Value::as_str).unwrap_or("").to_string();
27
28	let EditCount = Parameter.get("edits").and_then(Value::as_array).map(|A| A.len()).unwrap_or(0);
29
30	dev_log!("model", "[ApplyTextEdits] uri={} edits={}", Uri, EditCount);
31
32	if Uri.is_empty() || EditCount == 0 {
33		return;
34	}
35
36	if let Err(E) = Service.ApplicationHandle().emit("sky://editor/apply-text-edits", Parameter) {
37		dev_log!("sky-emit", "[ApplyTextEdits] emit failed: {}", E);
38	}
39}