Add cursor moving (#19)
This commit is contained in:
parent
29d8779786
commit
1f9728d893
49 changed files with 1105 additions and 141 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import type { StoredDatabase } from "sync-client";
|
||||
import type { StoredDatabase, TextWithCursors } from "sync-client";
|
||||
import { assert } from "../utils/assert";
|
||||
import {
|
||||
type RelativePath,
|
||||
|
|
@ -87,14 +87,14 @@ export class MockClient implements FileSystemOperations {
|
|||
|
||||
public async atomicUpdateText(
|
||||
path: RelativePath,
|
||||
updater: (currentContent: string) => string
|
||||
updater: (currentContent: TextWithCursors) => TextWithCursors
|
||||
): Promise<string> {
|
||||
const file = this.localFiles.get(path);
|
||||
if (!file) {
|
||||
throw new Error(`File ${path} does not exist`);
|
||||
}
|
||||
const currentContent = new TextDecoder().decode(file);
|
||||
const newContent = updater(currentContent);
|
||||
const newContent = updater({ text: currentContent, cursors: [] }).text;
|
||||
const newContentUint8Array = new TextEncoder().encode(newContent);
|
||||
this.localFiles.set(path, newContentUint8Array);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue