Add API for propagating cursor locations (#61)

This commit is contained in:
Andras Schmelczer 2025-06-08 20:20:52 +01:00 committed by GitHub
commit e8b9bf40c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
80 changed files with 1929 additions and 2228 deletions

View file

@ -7,6 +7,7 @@ import type {
} from "sync-client";
import { lineAndColumnToPosition } from "./utils/line-and-column-to-position";
import { positionToLineAndColumn } from "./utils/position-to-line-and-column";
import { getCursorsFromEditor } from "./views/cursors/get-cursors-from-editor";
export class ObsidianFileSystemOperations implements FileSystemOperations {
public constructor(
@ -78,26 +79,19 @@ export class ObsidianFileSystemOperations implements FileSystemOperations {
if (view?.file?.path === path) {
const text = view.editor.getValue();
const cursors = view.editor
.listSelections()
.flatMap(({ anchor, head }, i) => [
const cursors = getCursorsFromEditor(view.editor).flatMap(
({ id, start: anchor, end: head }) => [
{
id: 2 * i,
characterPosition: lineAndColumnToPosition(
text,
anchor.line,
anchor.ch
)
id: 2 * id,
characterPosition: anchor
},
{
id: 2 * i + 1,
characterPosition: lineAndColumnToPosition(
text,
head.line,
head.ch
)
id: 2 * id + 1,
characterPosition: head
}
]);
]
);
const result = updater({
text,