Skip to content

Commit cf1b50e

Browse files
committed
feat: Add support for multiple files
1 parent f83456d commit cf1b50e

File tree

5 files changed

+28
-31
lines changed

5 files changed

+28
-31
lines changed

backend/src/ws/handlers.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ impl RgWebsocket {
126126
Err(ServerMessageError::None)
127127
}
128128
}
129+
InternalMessage::FileCreate { path, doc } => {
130+
self.sync_docs.insert(path, (doc, 0));
131+
132+
Err(ServerMessageError::None)
133+
}
134+
InternalMessage::FileDelete { path } => {
135+
self.sync_docs.remove(&path);
136+
137+
Err(ServerMessageError::None)
138+
}
129139
}
130140
}
131141

@@ -239,7 +249,12 @@ impl RgWebsocket {
239249
let project = self.app_state.get_project(self.project_id).await?;
240250
let mut project = project.write().await;
241251

242-
project.add_file(file, Document::new());
252+
let new_doc = project.add_file(file.clone(), Document::new());
253+
254+
_ = project.internal.send(InternalMessage::FileCreate {
255+
path: file,
256+
doc: new_doc,
257+
});
243258

244259
let msg = ServerMessage::ProjectFiles {
245260
files: project.get_files().await,
@@ -260,6 +275,10 @@ impl RgWebsocket {
260275
files: project.get_files().await,
261276
};
262277

278+
_ = project
279+
.internal
280+
.send(InternalMessage::FileDelete { path: file });
281+
263282
_ = project.broadcast.send(msg);
264283

265284
Err(ServerMessageError::None)

backend/src/ws/messages.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use std::collections::HashMap;
2+
use std::sync::Arc;
23

34
use operational_transform::OperationSeq;
45
use serde::{Deserialize, Serialize};
56
use uuid::Uuid;
67

7-
use crate::collab::{DocumentInfo, UserOperation};
8+
use crate::collab::{Document, DocumentInfo, UserOperation};
89
use crate::project::AccessLevel;
910
use crate::utils::ArcStr;
1011

@@ -115,4 +116,6 @@ impl From<ServerMessageError> for ServerMessage {
115116
#[derive(Clone)]
116117
pub enum InternalMessage {
117118
FileEdit { path: ArcStr },
119+
FileCreate { path: ArcStr, doc: Arc<Document> },
120+
FileDelete { path: ArcStr },
118121
}

frontend/src/features/editor/services/editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function startReceivingSync() {
3636

3737
let content = unwrap(syncFiles)[msg.file];
3838

39-
if (content) {
39+
if (content != null) {
4040
content = msg.actions.reduce(
4141
(content, action) =>
4242
applyOperationToString(

frontend/src/features/editor/utils/syncExtension.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ import {
1919
setSyncFiles,
2020
} from "../stores";
2121
import { unicodeLength } from "./unicodeLength";
22-
import {
23-
applyOperationToView,
24-
syncAnnotation,
25-
syncAnnotationType,
26-
} from "./applyOperation";
27-
import { batch } from "solid-js";
22+
import { applyOperationToView, syncAnnotationType } from "./applyOperation";
2823

2924
let outstanding: OpSeq | null = null;
3025
let accumulated_changes: OpSeq | null = null;
@@ -122,8 +117,6 @@ function anyEventHandler(file: FileNode) {
122117
file: file.fullPath,
123118
cursors: cursors.map(Cursor.into_rscursor),
124119
});
125-
126-
console.log("CURSORS", cursors);
127120
};
128121

129122
const handleOps = (update: ViewUpdate) => {
@@ -181,7 +174,7 @@ function anyEventHandler(file: FileNode) {
181174
return;
182175
}
183176

184-
if (update.docChanged && update.changes.length) {
177+
if (update.docChanged) {
185178
handleOps(update);
186179
}
187180

frontend/src/features/editor/views/CodeEditor.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,7 @@ export function CodeEditor(props: CodeEditorProps) {
108108
extensions={[
109109
...rustExtensions(styles),
110110
readOnly.of([]),
111-
cursors.of(EditorView.decorations.of(Decoration.set(
112-
[
113-
Decoration.mark({
114-
inclusive: true,
115-
attributes: {
116-
style: "--hue: 140",
117-
},
118-
class: styles.colored_selection,
119-
}).range(0, 10),
120-
121-
Decoration.mark({
122-
inclusive: true,
123-
attributes: {
124-
style: "--hue: 240",
125-
},
126-
class: styles.colored_cursor,
127-
}).range(15, 15 + 1),
128-
],
129-
))),
111+
cursors.of(EditorView.decorations.of(Decoration.set([]))),
130112
syncExtension(file.data),
131113
]}
132114
onEditorMount={(editor) => {

0 commit comments

Comments
 (0)