From 9851b26f2250a7b9e8f4f0835902beaeaa31319a Mon Sep 17 00:00:00 2001 From: Vincent Chan Date: Wed, 27 Jul 2022 19:42:09 +0800 Subject: [PATCH] fix: transform error for path --- .../packages/flowy_editor/lib/operation/operation.dart | 2 ++ .../app_flowy/packages/flowy_editor/test/operation_test.dart | 1 + 2 files changed, 3 insertions(+) diff --git a/frontend/app_flowy/packages/flowy_editor/lib/operation/operation.dart b/frontend/app_flowy/packages/flowy_editor/lib/operation/operation.dart index 487844af14..eafa4a31da 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/operation/operation.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/operation/operation.dart @@ -128,6 +128,8 @@ Path transformPath(Path preInsertPath, Path b, [int delta = 1]) { final bAtIndex = b[preInsertPath.length - 1]; if (preInsertLast <= bAtIndex) { prefix.add(bAtIndex + delta); + } else { + prefix.add(bAtIndex); } prefix.addAll(suffix); return prefix; diff --git a/frontend/app_flowy/packages/flowy_editor/test/operation_test.dart b/frontend/app_flowy/packages/flowy_editor/test/operation_test.dart index 683b6df58e..176f00b734 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/operation_test.dart +++ b/frontend/app_flowy/packages/flowy_editor/test/operation_test.dart @@ -19,6 +19,7 @@ void main() { test("transform path not changed", () { expect(transformPath([0, 1, 2], [0, 0, 7, 8, 9]), [0, 0, 7, 8, 9]); expect(transformPath([0, 1, 2], [0, 1]), [0, 1]); + expect(transformPath([1, 1], [1, 0]), [1, 0]); }); test("transform path delta", () { expect(transformPath([0, 1], [0, 1], 5), [0, 6]);