Format and lint

This commit is contained in:
Andras Schmelczer 2025-06-08 12:13:35 +01:00
parent deca4c4dc2
commit 83823b48f2
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
21 changed files with 137 additions and 67 deletions

View file

@ -6,7 +6,7 @@ import type {
Workspace,
WorkspaceLeaf
} from "obsidian";
import { MarkdownView } from "obsidian";
import type { MarkdownView } from "obsidian";
import { Platform, Plugin, TFile } from "obsidian";
import "../manifest.json";
import { HistoryView } from "./views/history/history-view";
@ -91,7 +91,9 @@ export default class VaultLinkPlugin extends Plugin {
this.client,
this.app.workspace
);
this.disposables.push(() => cursorListener.dispose());
this.disposables.push(() => {
cursorListener.dispose();
});
this.app.workspace.updateOptions();
@ -195,7 +197,9 @@ export default class VaultLinkPlugin extends Plugin {
}
}
)
].forEach((event) => this.registerEvent(event));
].forEach((event) => {
this.registerEvent(event);
});
}
private async rateLimitedUpdate(path: string): Promise<void> {

View file

@ -1,12 +1,8 @@
import {
EventRef,
Workspace,
Editor,
MarkdownView,
MarkdownFileInfo
} from "obsidian";
import { SyncClient } from "sync-client";
import { Cursor, getCursorsFromEditor } from "./get-cursors-from-editor";
import type { Workspace } from "obsidian";
import { EventRef, Editor, MarkdownView, MarkdownFileInfo } from "obsidian";
import type { Logger, SyncClient } from "sync-client";
import type { Cursor } from "./get-cursors-from-editor";
import { getCursorsFromEditor } from "./get-cursors-from-editor";
export class LocalCursorUpdateListener {
private static readonly UPDATE_INTERVAL_MS = 50;
@ -17,10 +13,13 @@ export class LocalCursorUpdateListener {
private readonly client: SyncClient,
private readonly workspace: Workspace
) {
this.eventHandle = setInterval(
() => this.updateAllCursors(),
LocalCursorUpdateListener.UPDATE_INTERVAL_MS
);
this.eventHandle = setInterval(() => {
this.updateAllCursors();
}, LocalCursorUpdateListener.UPDATE_INTERVAL_MS);
}
public dispose(): void {
clearInterval(this.eventHandle);
}
private updateAllCursors(): void {
@ -32,7 +31,13 @@ export class LocalCursorUpdateListener {
return;
}
this.lastCursorState = currentCursors;
this.client.updateLocalCursors(currentCursors);
this.client
.updateLocalCursors(currentCursors)
.catch((error: unknown) => {
this.client.logger.error(
`Failed to update local cursors: ${error}`
);
});
}
private getAllCursors(): Record<string, Cursor[]> {
@ -50,8 +55,4 @@ export class LocalCursorUpdateListener {
});
return cursors;
}
public dispose(): void {
clearInterval(this.eventHandle);
}
}

View file

@ -103,15 +103,19 @@ export const remoteCursorsPlugin = ViewPlugin.fromClass(
}
);
export function setCursors(clients: ClientCursors[], app: App) {
export function setCursors(clients: ClientCursors[], app: App): void {
cursors = clients.flatMap((client) => {
return Object.keys(client.cursors).flatMap((path) =>
client.cursors[path]!.map((span) => ({
name: client.userName,
path,
span
}))
);
const clientCursors = client.cursors;
return Object.keys(clientCursors).flatMap((path) => {
const spans = clientCursors[path];
return spans
? spans.map((span) => ({
name: client.userName,
path,
span
}))
: [];
});
});
app.workspace
@ -120,6 +124,7 @@ export function setCursors(clients: ClientCursors[], app: App) {
.filter((view) => view instanceof MarkdownView)
.forEach((view) => {
// @ts-expect-error, not typed
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const editor = view.editor.cm as EditorView;
editor.dispatch({