Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions crates/typst-preview/src/actor/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub enum EditorActorRequest {
DocToSrcJump(DocToSrcJumpInfo),
Outline(Outline),
CompileStatus(CompileStatus),
AnnotationSave(String), // JSON annotation data to save
AnnotationLoad, // Request to load annotations
AnnotationUpdate(String), // JSON annotation update
}

pub struct ControlPlaneTx {
Expand Down Expand Up @@ -197,6 +200,21 @@ impl<T: EditorServer> EditorActor<T> {
EditorActorRequest::Outline(outline) => {
self.editor_conn.resp_ctl_plane("Outline", ControlPlaneResponse::Outline(outline)).await
}
EditorActorRequest::AnnotationSave(data) => {
// Send annotation data to webview for saving
self.webview_sender.send(WebviewActorRequest::AnnotationData(data)).log_error("EditorActor");
false
}
EditorActorRequest::AnnotationLoad => {
// Request annotation load - this could trigger loading from storage
self.webview_sender.send(WebviewActorRequest::AnnotationCommand("load".to_string(), "".to_string())).log_error("EditorActor");
false
}
EditorActorRequest::AnnotationUpdate(data) => {
// Send annotation update to webview
self.webview_sender.send(WebviewActorRequest::AnnotationCommand("update".to_string(), data)).log_error("EditorActor");
false
}
};

if !sent {
Expand Down
23 changes: 23 additions & 0 deletions crates/typst-preview/src/actor/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub enum WebviewActorRequest {
SrcToDocJump(Vec<SrcToDocJumpInfo>),
// CursorPosition(CursorPosition),
CursorPaths(Vec<Vec<ElementPoint>>),
AnnotationData(String), // JSON annotation data
AnnotationCommand(String, String), // Command type and JSON data
}

fn position_req(
Expand Down Expand Up @@ -107,6 +109,16 @@ where
self.webview_websocket_conn.send(WsMessage::Binary(msg.into_bytes()))
.await.log_error("WebViewActor");
}
WebviewActorRequest::AnnotationData(data) => {
let msg = format!("annotation-data,{}", data);
self.webview_websocket_conn.send(WsMessage::Binary(msg.into_bytes()))
.await.log_error("WebViewActor");
}
WebviewActorRequest::AnnotationCommand(command, data) => {
let msg = format!("annotation-command,{},{}", command, data);
self.webview_websocket_conn.send(WsMessage::Binary(msg.into_bytes()))
.await.log_error("WebViewActor");
}
}
}
Some(svg) = self.svg_receiver.recv() => {
Expand Down Expand Up @@ -159,6 +171,17 @@ where
if let Ok(path) = path {
self.render_sender.send(RenderActorRequest::WebviewResolveFrameLoc(path)).log_error("WebViewActor");
};
} else if msg.starts_with("annotation-save") {
// Handle annotation save request from frontend
let data = msg.strip_prefix("annotation-save ").unwrap_or("");
self.editor_sender.send(EditorActorRequest::AnnotationSave(data.to_string())).log_error("WebViewActor");
} else if msg.starts_with("annotation-load") {
// Handle annotation load request from frontend
self.editor_sender.send(EditorActorRequest::AnnotationLoad).log_error("WebViewActor");
} else if msg.starts_with("annotation-update") {
// Handle annotation update from frontend
let data = msg.strip_prefix("annotation-update ").unwrap_or("");
self.editor_sender.send(EditorActorRequest::AnnotationUpdate(data.to_string())).log_error("WebViewActor");
} else {
let err = self.webview_websocket_conn.send(WsMessage::Text(format!("error, received unknown message: {msg}"))).await;
log::info!("WebviewActor: received unknown message from websocket: {msg} {err:?}");
Expand Down
Loading