Skip to content

Commit

Permalink
correct library syncing logic in case of conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
pomdtr committed Apr 18, 2022
1 parent fe9aaff commit 6223ccc
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions extension/src/ExcalidrawEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ export class ExcalidrawEditorProvider

class ExcalidrawEditor {
// Allows to pass events between editors
private static eventEmitter = new vscode.EventEmitter<{
type: string;
msg: any;
private static onLibraryChange = new vscode.EventEmitter<{
uri?: vscode.Uri;
content: any;
}>();

private textDecoder = new TextDecoder();
Expand Down Expand Up @@ -160,7 +160,10 @@ class ExcalidrawEditor {
switch (msg.type) {
case "library-change":
await this.saveLibrary(msg.library, libraryUri);
ExcalidrawEditor.eventEmitter.fire(msg);
ExcalidrawEditor.onLibraryChange.fire({
uri: libraryUri,
content: msg.library,
});
return;
case "change":
await this.document.update(new Uint8Array(msg.content));
Expand All @@ -178,8 +181,13 @@ class ExcalidrawEditor {
this
);

const onDidReceiveEvent = ExcalidrawEditor.eventEmitter.event((msg) => {
this.webviewPanel.webview.postMessage(msg);
const onLibraryChange = ExcalidrawEditor.onLibraryChange.event((msg) => {
if (msg.uri?.toString() === libraryUri?.toString()) {
this.webviewPanel.webview.postMessage({
type: "library-change",
library: msg.content,
});
}
});

this.webviewPanel.webview.html = await this.buildHtmlForWebview({
Expand All @@ -195,7 +203,7 @@ class ExcalidrawEditor {

return new vscode.Disposable(() => {
onDidReceiveMessage.dispose();
onDidReceiveEvent.dispose();
onLibraryChange.dispose();
});
}

Expand Down

0 comments on commit 6223ccc

Please sign in to comment.