diff --git a/plug-api/silverbullet-syscall/editor.ts b/plug-api/silverbullet-syscall/editor.ts index c4cd240..f31c60a 100644 --- a/plug-api/silverbullet-syscall/editor.ts +++ b/plug-api/silverbullet-syscall/editor.ts @@ -133,10 +133,6 @@ export function vimEx(exCommand: string): Promise { return syscall("editor.vimEx", exCommand); } -export function syncSpace(): Promise { - return syscall("editor.syncSpace"); -} - // Folding export function fold() { diff --git a/plug-api/silverbullet-syscall/sync.ts b/plug-api/silverbullet-syscall/sync.ts index 5acf8cc..e6f24fa 100644 --- a/plug-api/silverbullet-syscall/sync.ts +++ b/plug-api/silverbullet-syscall/sync.ts @@ -11,3 +11,7 @@ export function hasInitialSyncCompleted(): Promise { export function scheduleFileSync(path: string): Promise { return syscall("sync.scheduleFileSync", path); } + +export function scheduleSpaceSync(): Promise { + return syscall("sync.scheduleSpaceSync"); +} diff --git a/plugs/core/sync.ts b/plugs/core/sync.ts index f53576a..3984c97 100644 --- a/plugs/core/sync.ts +++ b/plugs/core/sync.ts @@ -1,7 +1,7 @@ -import { editor } from "$sb/silverbullet-syscall/mod.ts"; +import { editor, sync } from "$sb/silverbullet-syscall/mod.ts"; export async function syncSpaceCommand() { await editor.flashNotification("Syncing space..."); - await editor.syncSpace(); + await sync.scheduleSpaceSync(); await editor.flashNotification("Done."); } diff --git a/web/sync_service.ts b/web/sync_service.ts index a496a14..03efeb6 100644 --- a/web/sync_service.ts +++ b/web/sync_service.ts @@ -166,6 +166,11 @@ export class SyncService { this.filesScheduledForSync.delete(path); } + async scheduleSpaceSync(): Promise { + await this.noOngoingSync(5000); + await this.syncSpace(); + } + start() { this.syncSpace().catch(console.error); diff --git a/web/syscalls/editor.ts b/web/syscalls/editor.ts index 6a37f86..f7fdd2d 100644 --- a/web/syscalls/editor.ts +++ b/web/syscalls/editor.ts @@ -184,10 +184,6 @@ export function editorSyscalls(editor: Client): SysCallMapping { const cm = vimGetCm(editor.editorView)!; return Vim.handleEx(cm, exCommand); }, - // Sync - "editor.syncSpace": () => { - return editor.syncService.syncSpace(); - }, // Folding "editor.fold": () => { foldCode(editor.editorView); diff --git a/web/syscalls/sync.ts b/web/syscalls/sync.ts index c1c2680..a9b357e 100644 --- a/web/syscalls/sync.ts +++ b/web/syscalls/sync.ts @@ -12,5 +12,8 @@ export function syncSyscalls(editor: Client): SysCallMapping { "sync.scheduleFileSync": (_ctx, path: string): Promise => { return editor.syncService.scheduleFileSync(path); }, + "sync.scheduleSpaceSync": () => { + return editor.syncService.scheduleSpaceSync(); + }, }; }