Browse Source

fix: insert row index

appflowy 3 years ago
parent
commit
b9135d26a9

+ 2 - 1
frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart

@@ -213,7 +213,8 @@ class _GridRowsState extends State<_GridRows> {
           key: _key,
           initialItemCount: context.read<GridBloc>().state.rows.length,
           itemBuilder: (BuildContext context, int index, Animation<double> animation) {
-            return _renderRow(context, state.rows[index], animation);
+            final rowData = context.read<GridBloc>().state.rows[index];
+            return _renderRow(context, rowData, animation);
           },
         );
       },

+ 0 - 1
frontend/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/flowy_overlay.dart

@@ -210,7 +210,6 @@ class FlowyOverlayState extends State<FlowyOverlay> {
       _overlayList.remove(firstItem);
       if (firstItem.delegate != null) {
         firstItem.delegate!.didRemove();
-
         if (firstItem.delegate!.asBarrier()) {
           return;
         }

+ 4 - 0
frontend/rust-lib/flowy-grid/src/services/block_meta_editor.rs

@@ -61,6 +61,10 @@ impl ClientGridBlockMetaEditor {
 
                 let change = block_pad.add_row_meta(row, start_row_id)?;
                 row_count = block_pad.number_of_rows();
+
+                if row_index.is_none() {
+                    row_index = Some(row_count - 1);
+                }
                 Ok(change)
             })
             .await?;

+ 5 - 2
frontend/rust-lib/flowy-grid/src/services/block_meta_manager.rs

@@ -92,8 +92,11 @@ impl GridBlockMetaEditorManager {
             let mut row_count = 0;
             for row in row_metas {
                 let _ = self.persistence.insert_or_update(&row.block_id, &row.id)?;
-                inserted_row_orders.push(IndexRowOrder::from(&row));
-                row_count = editor.create_row(row, None).await?.0;
+                let mut row_order = IndexRowOrder::from(&row);
+                let (count, index) = editor.create_row(row, None).await?;
+                row_count = count;
+                row_order.index = index;
+                inserted_row_orders.push(row_order);
             }
             changesets.push(GridBlockMetaChangeset::from_row_count(&block_id, row_count));