Skip to content

Commit

Permalink
fix: found a bug for splitting usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
squidrye committed Oct 24, 2023
1 parent 7e6c2f2 commit 0093e3a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PanesCubit extends Cubit<PanesState> {
axis: axis,
);

final firstLeafNode = panesService.findFirstLeaf(node: state.root);
final firstLeafNode = panesService.findFirstLeaf(node: root);

emit(
state.copyWith(
Expand All @@ -57,17 +57,19 @@ class PanesCubit extends Cubit<PanesState> {
firstLeafNode: firstLeafNode,
),
);
setActivePane(state.root.children.last);
setActivePane(root.children.last);
}

void closePane({required String paneId, bool closingToMove = false}) {
void closePane({
required String paneId,
}) {
final root = panesService.closePaneHandler(
node: state.root,
targetPaneId: paneId,
closingToMove: closingToMove,
closingToMove: false,
);

final firstLeafNode = panesService.findFirstLeaf(node: state.root);
final firstLeafNode = panesService.findFirstLeaf(node: root);

emit(
state.copyWith(
Expand All @@ -77,8 +79,8 @@ class PanesCubit extends Cubit<PanesState> {
),
);

final children = state.root.children;
setActivePane(children.isEmpty ? state.root : children.last);
final children = root.children;
setActivePane(children.isEmpty ? root : children.last);
}

void openTab({required Plugin plugin}) {
Expand Down Expand Up @@ -111,30 +113,36 @@ class PanesCubit extends Cubit<PanesState> {
) {
final direction = [
FlowyDraggableHoverPosition.top,
FlowyDraggableHoverPosition.left
FlowyDraggableHoverPosition.left,
].contains(position)
? Direction.back
: Direction.front;

final axis = [
FlowyDraggableHoverPosition.left,
FlowyDraggableHoverPosition.right
FlowyDraggableHoverPosition.right,
].contains(position)
? Axis.vertical
: Axis.horizontal;

final root = panesService.movePaneHandler(
toNode: to,
direction: direction,
axis: axis,
root: state.root,
fromNode: from,
);

final firstLeafNode = panesService.findFirstLeaf(node: root);

emit(
state.copyWith(
root: panesService.splitHandler(
node: state.root,
targetPaneId: to.paneId,
direction: direction,
axis: axis,
fromNode: from,
),
count: state.count + 1,
root: root,
firstLeafNode: firstLeafNode,
),
);
closePane(paneId: from.paneId, closingToMove: true);

final children = state.root.children;
setActivePane(children.isEmpty ? state.root : children.last);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class PanesService {
oldChildNode,
],
);
return ret;
return ret.copyWith(
children: ret.children.map((e) => e.copyWith(parent: ret)).toList(),
);
}

/// if we haven't found our target node there is a possibility that our
Expand Down Expand Up @@ -94,10 +96,13 @@ class PanesService {
///reconstructed tabscontroller to trigger build of consecutive
///widget else it won't reflect on ui.
return node.copyWith(
final parent = node.copyWith(
paneId: nanoid(),
children: list.map((e) => e.copyWith()).toList(),
);
return parent.copyWith(
children: list.map((e) => e.copyWith(parent: parent)).toList(),
);
}
}
}
Expand Down Expand Up @@ -141,16 +146,19 @@ class PanesService {

if (node.children.length == 1) {
final ret = node.children.first.copyWith(
paneId: nanoid(),
paneId: closingToMove ? node.children.first.paneId : nanoid(),
parent: node.parent,
);
return ret;
}

return node.copyWith(
paneId: nanoid(),
final parent = node.copyWith(
paneId: closingToMove ? node.paneId : nanoid(),
children: list.map((e) => e.copyWith()).toList(),
);
return parent.copyWith(
children: list.map((e) => e.copyWith(parent: parent)).toList(),
);
}
}

Expand All @@ -162,7 +170,32 @@ class PanesService {
);
}).toList();

return node.copyWith(children: newChildren);
return node.copyWith(
paneId: closingToMove ? node.paneId : nanoid(),
children: newChildren,
);
}

PaneNode movePaneHandler({
required PaneNode root,
required Direction direction,
required Axis axis,
required PaneNode fromNode,
required PaneNode toNode,
}) {
final response = splitHandler(
node: closePaneHandler(
node: root,
targetPaneId: fromNode.paneId,
closingToMove: true,
),
targetPaneId: toNode.paneId,
direction: direction,
axis: axis,
fromNode: fromNode,
);

return response.copyWith(paneId: nanoid());
}

PaneNode findFirstLeaf({required PaneNode node}) {
Expand Down

0 comments on commit 0093e3a

Please sign in to comment.