Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Fix index validation

Hakan Shehu09df9bc798cb
diff --git a/desktop/src/hooks/use-document.tsx b/desktop/src/hooks/use-document.tsx
index ae5133e8..019321eb 100644
--- a/desktop/src/hooks/use-document.tsx
+++ b/desktop/src/hooks/use-document.tsx
@@ -253,9 +253,11 @@ const validateIndexes = (nodes: NodeFromEditor[]) => {
}
}
- // extra check to make sure that the beforeIndex and afterIndex are different
- // because if they are the same the fractional index library will throw an error
- if (beforeIndex === afterIndex) {
+ // extra check to make sure that the beforeIndex is less than the afterIndex
+ // because otherwise the fractional index library will throw an error
+ if (afterIndex < beforeIndex) {
+ afterIndex = generateNodeIndex(null, beforeIndex);
+ } else if (beforeIndex === afterIndex) {
afterIndex = generateNodeIndex(beforeIndex, null);
}