Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: supported incremental updates #6531

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export const CustomEditor = {

handleMergeBlockBackwardWithTxn(editor, node, point);
} else {

Transforms.collapse(editor, { edge: 'start' });
removeRangeWithTxn(editor, sharedRoot, newAt);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { translateYEvents } from '@/application/slate-yjs/utils/applyToSlate';
import { CollabOrigin, YjsEditorKey, YSharedRoot } from '@/application/types';
import { applyToYjs } from '@/application/slate-yjs/utils/applyToYjs';
import { Editor, Operation, Descendant, Transforms } from 'slate';
Expand Down Expand Up @@ -125,25 +126,45 @@
apply(op);
};

e.applyRemoteEvents = (_events: Array<YEvent>, _transaction: Transaction) => {
e.applyRemoteEvents = (events: Array<YEvent>, transaction: Transaction) => {
console.time('applyRemoteEvents');
// Flush local changes to ensure all local changes are applied before processing remote events
YjsEditor.flushLocalChanges(e);
// Replace the apply function to avoid storing remote changes as local changes
e.interceptLocalChange = true;

// Initialize or update the document content to ensure it is in the correct state before applying remote events
initializeDocumentContent();
if (transaction.origin === CollabOrigin.Remote) {
initializeDocumentContent();
} else {
const selection = editor.selection;

Check warning on line 141 in frontend/appflowy_web_app/src/application/slate-yjs/plugins/withYjs.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/plugins/withYjs.ts#L140-L141

Added lines #L140 - L141 were not covered by tests
Editor.withoutNormalizing(e, () => {
translateYEvents(e, events);
});

Check warning on line 144 in frontend/appflowy_web_app/src/application/slate-yjs/plugins/withYjs.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/plugins/withYjs.ts#L144

Added line #L144 was not covered by tests
if (selection) {
if (!ReactEditor.hasRange(editor, selection)) {
try {
Transforms.select(e, Editor.start(editor, [0]));

} catch (e) {
console.error(e);

Check warning on line 151 in frontend/appflowy_web_app/src/application/slate-yjs/plugins/withYjs.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/plugins/withYjs.ts#L149-L151

Added lines #L149 - L151 were not covered by tests
editor.deselect();
}

Check warning on line 153 in frontend/appflowy_web_app/src/application/slate-yjs/plugins/withYjs.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/plugins/withYjs.ts#L153

Added line #L153 was not covered by tests
} else {
e.select(selection);
}

Check warning on line 156 in frontend/appflowy_web_app/src/application/slate-yjs/plugins/withYjs.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/plugins/withYjs.ts#L156

Added line #L156 was not covered by tests
}
}

// Restore the apply function to store local changes after applying remote changes
e.interceptLocalChange = false;
console.timeEnd('applyRemoteEvents');
};

const handleYEvents = (events: Array<YEvent>, transaction: Transaction) => {
if (transaction.origin !== CollabOrigin.Local) {
YjsEditor.applyRemoteEvents(e, events, transaction);
}
if (transaction.origin === CollabOrigin.Local) return;
YjsEditor.applyRemoteEvents(e, events, transaction);

};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
import { YjsEditor } from '@/application/slate-yjs';
import { BlockJson } from '@/application/slate-yjs/types';
import { blockToSlateNode, deltaInsertToSlateNode } from '@/application/slate-yjs/utils/convert';
import {
dataStringTOJson,
getBlock,
getChildrenArray,
getPageId,
getText,
} from '@/application/slate-yjs/utils/yjsOperations';
import { YBlock, YjsEditorKey } from '@/application/types';
import isEqual from 'lodash-es/isEqual';
import { Editor, Element, NodeEntry } from 'slate';
import { YEvent, YMapEvent, YTextEvent } from 'yjs';
import { YText } from 'yjs/dist/src/types/YText';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type BlockMapEvent = YMapEvent<any>

export function translateYEvents (editor: YjsEditor, events: Array<YEvent>) {

Check warning on line 20 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L20

Added line #L20 was not covered by tests
console.log('=== Translating Yjs events ===', events);

events.forEach((event) => {
console.log(event.path);
if (isEqual(event.path, ['document', 'blocks'])) {

Check warning on line 25 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L22-L25

Added lines #L22 - L25 were not covered by tests
applyBlocksYEvent(editor, event as BlockMapEvent);
}

Check warning on line 28 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L28

Added line #L28 was not covered by tests
if (isEqual((event.path), ['document', 'blocks', event.path[2]])) {
const blockId = event.path[2] as string;

applyUpdateBlockYEvent(editor, blockId, event as YMapEvent<unknown>);
}

if (isEqual(event.path, ['document', 'meta', 'text_map', event.path[3]])) {
const textId = event.path[3] as string;

applyTextYEvent(editor, textId, event as YTextEvent);
}
});

}

Check warning on line 42 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L30-L42

Added lines #L30 - L42 were not covered by tests

function applyUpdateBlockYEvent (editor: YjsEditor, blockId: string, event: YMapEvent<unknown>) {

Check warning on line 44 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L44

Added line #L44 was not covered by tests
const { target } = event;
const block = target as YBlock;
const newData = dataStringTOJson(block.get(YjsEditorKey.block_data));

Check warning on line 47 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L46-L47

Added lines #L46 - L47 were not covered by tests
const [entry] = editor.nodes({
match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.blockId === blockId,
mode: 'all',
});

if (!entry) {
console.error('Block node not found', blockId);
return [];
}

const [node, path] = entry as NodeEntry<Element>;
const oldData = node.data as Record<string, unknown>;

editor.apply({
type: 'set_node',
path,
newProperties: {
data: newData,
},
properties: {
data: oldData,
},
});

Check warning on line 70 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L49-L70

Added lines #L49 - L70 were not covered by tests
}

function applyTextYEvent (editor: YjsEditor, textId: string, event: YTextEvent) {
const { target } = event;

Check warning on line 75 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L75

Added line #L75 was not covered by tests
const yText = target as YText;
const delta = yText.toDelta();
const slateDelta = delta.flatMap(deltaInsertToSlateNode);
const [entry] = editor.nodes({

Check warning on line 79 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L79

Added line #L79 was not covered by tests
match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.textId === textId,
mode: 'all',
});

if (!entry) {
console.error('Text node not found', textId);

Check warning on line 85 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L81-L85

Added lines #L81 - L85 were not covered by tests
return [];
}

editor.apply({
type: 'remove_node',

Check warning on line 90 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L87-L90

Added lines #L87 - L90 were not covered by tests
path: entry[1],
node: entry[0],
});
editor.apply({
type: 'insert_node',
path: entry[1],
node: {
textId,
type: YjsEditorKey.text,
children: slateDelta,
},
});

}

Check warning on line 104 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L92-L104

Added lines #L92 - L104 were not covered by tests

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function applyBlocksYEvent (editor: YjsEditor, event: BlockMapEvent) {
const { changes, keysChanged } = event;

Check warning on line 108 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L107-L108

Added lines #L107 - L108 were not covered by tests
const { keys } = changes;

const keyPath: Record<string, number[]> = {};

keysChanged.forEach((key: string) => {

Check warning on line 113 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L110-L113

Added lines #L110 - L113 were not covered by tests
const value = keys.get(key);

Check warning on line 115 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L115

Added line #L115 was not covered by tests
if (!value) return;

Check warning on line 117 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L117

Added line #L117 was not covered by tests
if (value.action === 'add') {
handleNewBlock(editor, key, keyPath);

Check warning on line 120 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L120

Added line #L120 was not covered by tests
} else if (value.action === 'delete') {
handleDeleteNode(editor, key);
} else if (value.action === 'update') {
console.log('=== Applying block update Yjs event ===', key);
}
});

}

Check warning on line 128 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L126-L128

Added lines #L126 - L128 were not covered by tests

function handleNewBlock (editor: YjsEditor, key: string, keyPath: Record<string, number[]>) {
const block = getBlock(key, editor.sharedRoot);
const parentId = block.get(YjsEditorKey.block_parent);

Check warning on line 132 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L130-L132

Added lines #L130 - L132 were not covered by tests
const pageId = getPageId(editor.sharedRoot);
const parent = getBlock(parentId, editor.sharedRoot);
const parentChildren = getChildrenArray(parent.get(YjsEditorKey.block_children), editor.sharedRoot);
const index = parentChildren.toArray().findIndex((child) => child === key);
const slateNode = blockToSlateNode(block.toJSON() as BlockJson);
const textId = block.get(YjsEditorKey.block_external_id);
const yText = getText(textId, editor.sharedRoot);
const delta = yText.toDelta();
const slateDelta = delta.flatMap(deltaInsertToSlateNode);

Check warning on line 142 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L142

Added line #L142 was not covered by tests
if (slateDelta.length === 0) {
slateDelta.push({
text: '',

Check warning on line 145 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L145

Added line #L145 was not covered by tests
});
}

const textNode: Element = {
textId,

Check warning on line 150 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L147-L150

Added lines #L147 - L150 were not covered by tests
type: YjsEditorKey.text,
children: slateDelta,
};
let path = [index];

if (parentId !== pageId) {

Check warning on line 156 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L152-L156

Added lines #L152 - L156 were not covered by tests
const [parentEntry] = editor.nodes({
match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.blockId === parentId,

Check warning on line 158 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L158

Added line #L158 was not covered by tests
mode: 'all',
});

if (!parentEntry) {
if (keyPath[parentId]) {

Check warning on line 163 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L161-L163

Added lines #L161 - L163 were not covered by tests
path = [...keyPath[parentId], index + 1];
} else {
console.error('Parent block not found', parentId);
return [];
}
} else {
const childrenLength = (parentEntry[0] as Element).children.length;

path = [...parentEntry[1], Math.min(index + 1, childrenLength)];

Check warning on line 172 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L167-L172

Added lines #L167 - L172 were not covered by tests
}
}

editor.apply({

Check warning on line 176 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L175-L176

Added lines #L175 - L176 were not covered by tests
type: 'insert_node',
path,
node: {
...slateNode,
children: [textNode],
},
});

keyPath[key] = path;

}

Check warning on line 187 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L178-L187

Added lines #L178 - L187 were not covered by tests

function handleDeleteNode (editor: YjsEditor, key: string) {
const [entry] = editor.nodes({
at: [],

Check warning on line 191 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L190-L191

Added lines #L190 - L191 were not covered by tests
match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.blockId === key,
});

Check warning on line 194 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L193-L194

Added lines #L193 - L194 were not covered by tests
if (!entry) {
console.error('Block not found');

Check warning on line 196 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L196

Added line #L196 was not covered by tests
return [];
}

Check warning on line 199 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L199

Added line #L199 was not covered by tests
const [node, path] = entry;

editor.apply({

Check warning on line 202 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L201-L202

Added lines #L201 - L202 were not covered by tests
type: 'remove_node',
path,
node,
});

}

Check warning on line 208 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToSlate.ts#L204-L208

Added lines #L204 - L208 were not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,26 @@

const textId = node.textId;

if (!textId) return;
if (!textId) {
console.error('textId not found', node);
return;
}

const sharedRoot = ydoc.getMap(YjsEditorKey.data_section) as YSharedRoot;
const yText = getText(textId, sharedRoot);

if (!yText) return;
if (!yText) {
console.error('yText not found', textId, sharedRoot.toJSON());
return;
}

Check warning on line 137 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToYjs.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToYjs.ts#L134-L137

Added lines #L134 - L137 were not covered by tests

const point = { path, offset };

const relativeOffset = Math.min(calculateOffsetRelativeToParent(node, point), yText.toJSON().length);

yText.delete(relativeOffset, text.length);

console.log('applyRemoveText', op, yText.toDelta());

Check warning on line 145 in frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToYjs.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToYjs.ts#L144-L145

Added lines #L144 - L145 were not covered by tests
}

function applySetNode (ydoc: Y.Doc, editor: Editor, op: SetNodeOperation, slateContent: Descendant[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
const yText = textId ? textMap.get(textId) : undefined;

if (!yText) {

if (children.length === 0) {
children.push({
text: '',
Expand Down Expand Up @@ -185,7 +186,7 @@
}

// Helper function to convert Slate text node to Delta insert
function slateNodeToDeltaInsert (node: Text): YDelta {
export function slateNodeToDeltaInsert (node: Text): YDelta {

Check warning on line 189 in frontend/appflowy_web_app/src/application/slate-yjs/utils/convert.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/convert.ts#L189

Added line #L189 was not covered by tests
const { text, ...attributes } = node;

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getText } from '@/application/slate-yjs/utils/yjsOperations';
import { slateNodeToDeltaInsert } from '@/application/slate-yjs/utils/convert';
import { getText, getTextMap } from '@/application/slate-yjs/utils/yjsOperations';
import { YSharedRoot } from '@/application/types';
import { BasePoint, BaseRange, Node, Element, Editor, NodeEntry, Text } from 'slate';
import { RelativeRange } from '../types';
Expand Down Expand Up @@ -55,10 +56,16 @@
}

const textId = node.textId as string;
const ytext = getText(textId, sharedRoot);
let ytext = getText(textId, sharedRoot);

Check warning on line 59 in frontend/appflowy_web_app/src/application/slate-yjs/utils/positions.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/positions.ts#L59

Added line #L59 was not covered by tests

if (!ytext) {
throw new Error('YText not found');
const newYText = new Y.Text();
const textMap = getTextMap(sharedRoot);
const ops = (node.children as Text[]).map(slateNodeToDeltaInsert);

Check warning on line 65 in frontend/appflowy_web_app/src/application/slate-yjs/utils/positions.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/positions.ts#L63-L65

Added lines #L63 - L65 were not covered by tests
newYText.applyDelta(ops);
textMap.set(textId, newYText);

Check warning on line 67 in frontend/appflowy_web_app/src/application/slate-yjs/utils/positions.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/positions.ts#L67

Added line #L67 was not covered by tests
ytext = newYText;
}

const offset = Math.min(calculateOffsetRelativeToParent(node, point), ytext.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,16 @@
return doc;
}

export function getText (textId: string, sharedRoot: YSharedRoot) {

export function getTextMap (sharedRoot: YSharedRoot) {
const document = sharedRoot.get(YjsEditorKey.document);
const meta = document.get(YjsEditorKey.meta) as YMeta;
const textMap = meta.get(YjsEditorKey.text_map) as YTextMap;

return meta.get(YjsEditorKey.text_map) as YTextMap;
}

export function getText (textId: string, sharedRoot: YSharedRoot) {

const textMap = getTextMap(sharedRoot);

return textMap.get(textId);
}
Expand Down Expand Up @@ -191,6 +196,8 @@
} else {
Transforms.select(editor, Editor.start(editor, at));
}

Check warning on line 199 in frontend/appflowy_web_app/src/application/slate-yjs/utils/yjsOperations.ts

View check run for this annotation

Codecov / codecov/patch

frontend/appflowy_web_app/src/application/slate-yjs/utils/yjsOperations.ts#L199

Added line #L199 was not covered by tests
console.log('handleCollapsedBreakWithTxn', editor.selection);
}

export function removeRangeWithTxn (editor: YjsEditor, sharedRoot: YSharedRoot, range: Range) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function MoreActions () {
];

const importShow = false;

if (importShow) {
items.unshift({
Icon: ImportIcon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ describe('Markdown editing', () => {
// Test 1: heading
cy.get('@editor').type('##');
cy.get('@editor').realPress('Space');
cy.wait(50);

cy.get('@editor').type('Heading 2');
expectedJson = [...expectedJson, {
type: 'heading',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ export const LinkPreview = memo(
</div>
);
}),
);
(prev, next) => prev.node.data.url === next.node.data.url);
export default LinkPreview;
Loading
Loading