Move more logic into sync-client

This commit is contained in:
Andras Schmelczer 2025-08-30 11:02:04 +01:00
parent 3f089bd37e
commit 9177984ff6
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
20 changed files with 68 additions and 143 deletions

View file

@ -7,7 +7,7 @@
span {
border-radius: var(--radius-l);
padding: 0 var(--size-4-1);
border-width: 1px;
border-width: 1.4px;
border-style: solid;
font-size: var(--font-smallest);
font-style: italic;

View file

@ -1,8 +1,11 @@
import "./file-explorer.scss";
import type { App, View } from "obsidian";
import { getRandomColor } from "src/utils/get-random-color";
import type { MaybeOutdatedClientCursors, RelativePath } from "sync-client";
import {
utils,
type MaybeOutdatedClientCursors,
type RelativePath
} from "sync-client";
const REMOTE_USER_CONTAINER_CLASS = "remote-users";
@ -36,7 +39,7 @@ export function renderCursorsInFileExplorer(
createSpan({
text: cursor.userName,
attr: {
style: `border-color: ${getRandomColor(cursor.userName)}`
style: `border-color: ${utils.getRandomColor(cursor.userName)}`
}
})
);

View file

@ -1,5 +1,5 @@
import type { Editor } from "obsidian";
import { lineAndColumnToPosition } from "../../utils/line-and-column-to-position";
import { utils } from "sync-client";
export interface Selection {
id: number;
@ -11,7 +11,7 @@ export function getSelectionsFromEditor(editor: Editor): Selection[] {
const text = editor.getValue();
return editor.listSelections().map(({ anchor, head }, i) => ({
id: i,
start: lineAndColumnToPosition(text, anchor.line, anchor.ch),
end: lineAndColumnToPosition(text, head.line, head.ch)
start: utils.lineAndColumnToPosition(text, anchor.line, anchor.ch),
end: utils.lineAndColumnToPosition(text, head.line, head.ch)
}));
}

View file

@ -9,12 +9,15 @@ import type {
ViewUpdate
} from "@codemirror/view";
import { RemoteCursorWidget } from "./remote-cursor-widget";
import type { CursorSpan, MaybeOutdatedClientCursors } from "sync-client";
import {
utils,
type CursorSpan,
type MaybeOutdatedClientCursors
} from "sync-client";
import type { App } from "obsidian";
import { MarkdownView } from "obsidian";
import { StateEffect } from "@codemirror/state";
import { getRandomColor } from "src/utils/get-random-color";
import type { SpanWithHistory } from "reconcile-text";
import { reconcileWithHistory } from "reconcile-text";
@ -155,7 +158,7 @@ export class RemoteCursorsPluginValue implements PluginValue {
RemoteCursorsPluginValue.cursors.forEach(
({ name, span: { start, end } }) => {
const color = getRandomColor(name);
const color = utils.getRandomColor(name);
const startLine = update.view.state.doc.lineAt(start);
const endLine = update.view.state.doc.lineAt(end);