fixes and functions
This commit is contained in:
@@ -9,10 +9,6 @@
|
||||
|
||||
import { parseAuthorship, serializeAuthorship } from "@rustpad/authorship";
|
||||
|
||||
function utf16Length(value) {
|
||||
return String(value || "").length;
|
||||
}
|
||||
|
||||
function normalizeOwnerSpans(spans, length) {
|
||||
const result = [];
|
||||
const sorted = [...(Array.isArray(spans) ? spans : [])].sort((left, right) => (Number(left?.start) || 0) - (Number(right?.start) || 0) || (Number(left?.end) || 0) - (Number(right?.end) || 0));
|
||||
@@ -244,23 +240,6 @@ export function transformOperations(leftOperation, rightOperation, leftBeforeRig
|
||||
return [{ components: leftPrime }, { components: rightPrime }];
|
||||
}
|
||||
|
||||
export function applyOperation(text, operation) {
|
||||
text = String(text || "");
|
||||
operation = normalizeOperation(operation);
|
||||
if (operationBaseLength(operation) !== text.length) throw new Error("Operation base length does not match document");
|
||||
let cursor = 0;
|
||||
let result = "";
|
||||
for (const component of operation.components) {
|
||||
if (component.kind === "retain") {
|
||||
result += text.slice(cursor, cursor + component.count);
|
||||
cursor += component.count;
|
||||
} else if (component.kind === "delete") cursor += component.count;
|
||||
else result += component.text;
|
||||
}
|
||||
if (cursor !== text.length) throw new Error("Operation did not consume the whole document");
|
||||
return result;
|
||||
}
|
||||
|
||||
function copyRetainedSpans(target, spans, sourceStart, length, outputStart) {
|
||||
const sourceEnd = sourceStart + length;
|
||||
for (const span of spans || []) {
|
||||
@@ -303,10 +282,6 @@ export function applyOperationToDocument(content, ownerMap, operation, ownerRepl
|
||||
return { content: nextContent, ownerMap: serializeAuthorship(model, nextContent.length), authorship: model };
|
||||
}
|
||||
|
||||
export function operationEquals(left, right) {
|
||||
return JSON.stringify(normalizeOperation(left)) === JSON.stringify(normalizeOperation(right));
|
||||
}
|
||||
|
||||
export function compareOperationKeys(left, right) {
|
||||
const leftClient = String(left?.clientId || left?.client_id || "");
|
||||
const rightClient = String(right?.clientId || right?.client_id || "");
|
||||
|
||||
Reference in New Issue
Block a user