Fix main & improve cursor sync #101

Merged
schmelczer merged 16 commits from asch/fix-main into main 2025-08-25 17:15:52 +01:00
6 changed files with 13 additions and 11 deletions
Showing only changes of commit 49f2d69e59 - Show all commits

Rename types

Andras Schmelczer 2025-08-23 09:49:48 +01:00
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C

View file

@ -9,10 +9,7 @@ import type {
ViewUpdate ViewUpdate
} from "@codemirror/view"; } from "@codemirror/view";
import { RemoteCursorWidget } from "./remote-cursor-widget"; import { RemoteCursorWidget } from "./remote-cursor-widget";
import type { import type { CursorSpan, MaybeOutdatedClientCursors } from "sync-client";
CursorSpan,
DocumentWithMaybeOutdatedClientCursors
} from "sync-client";
import type { App } from "obsidian"; import type { App } from "obsidian";
import { MarkdownView } from "obsidian"; import { MarkdownView } from "obsidian";
@ -120,7 +117,7 @@ export const remoteCursorsPlugin = ViewPlugin.fromClass(
); );
export function setCursors( export function setCursors(
clients: DocumentWithMaybeOutdatedClientCursors[], clients: MaybeOutdatedClientCursors[],
app: App app: App
): void { ): void {
cursors = [ cursors = [

View file

@ -1,7 +1,7 @@
import type { Workspace } from "obsidian"; import type { Workspace } from "obsidian";
import { FileView, setIcon } from "obsidian"; import { FileView, setIcon } from "obsidian";
import type { SyncClient } from "sync-client"; import type { SyncClient } from "sync-client";
import { DocumentUpdateStatus } from "sync-client"; import { DocumentSyncStatus } from "sync-client";
import "./editor-sync-line.scss"; import "./editor-sync-line.scss";
export function updateEditorStatusDisplay( export function updateEditorStatusDisplay(
@ -35,7 +35,7 @@ export function updateEditorStatusDisplay(
const isLoading = const isLoading =
client.getDocumentSyncingStatus(filePath) == client.getDocumentSyncingStatus(filePath) ==
DocumentUpdateStatus.SYNCING; DocumentSyncStatus.SYNCING;
if (isLoading) { if (isLoading) {
element.classList.add("loading"); element.classList.add("loading");

View file

@ -18,8 +18,8 @@ export type { PersistenceProvider } from "./persistence/persistence";
export type { CursorSpan } from "./services/types/CursorSpan"; export type { CursorSpan } from "./services/types/CursorSpan";
export type { ClientCursors } from "./services/types/ClientCursors"; export type { ClientCursors } from "./services/types/ClientCursors";
export type { NetworkConnectionStatus } from "./types/network-connection-status"; export type { NetworkConnectionStatus } from "./types/network-connection-status";
export type { DocumentWithMaybeOutdatedClientCursors } from "./types/maybe-outdated-client-cursors"; export type { MaybeOutdatedClientCursors } from "./types/maybe-outdated-client-cursors";
export { DocumentUpdateStatus } from "./types/document-update-status"; export { DocumentSyncStatus } from "./types/document-sync-status";
export { SyncClient } from "./sync-client"; export { SyncClient } from "./sync-client";
import { Locks } from "./utils/locks"; import { Locks } from "./utils/locks";

View file

@ -1,4 +1,4 @@
export enum DocumentUpdateStatus { export enum DocumentSyncStatus {
UP_TO_DATE = "UP_TO_DATE", UP_TO_DATE = "UP_TO_DATE",
SYNCING = "SYNCING" SYNCING = "SYNCING"
} }

View file

@ -0,0 +1,5 @@
export enum DocumentUpToDateness {
UpToDate = "UpToDate", // easiest case, the client can just show the cursors as-is
Prior = "Prior", // The cursors are outdated, so the client has to guess the cursor positions based on local updates. This is only possible if this client's cursor has once been up-to-date in a given document.
Later = "Later" // The cursors are from a future version of a document, there's no way we can accuratly show them locally.
}

View file

@ -1,5 +1,5 @@
import type { ClientCursors } from "../services/types/ClientCursors"; import type { ClientCursors } from "../services/types/ClientCursors";
export interface DocumentWithMaybeOutdatedClientCursors extends ClientCursors { export interface MaybeOutdatedClientCursors extends ClientCursors {
isOutdated: boolean; isOutdated: boolean;
} }