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

feat: deep copy the node #995

Merged
merged 1 commit into from
Dec 24, 2024
Merged
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
15 changes: 13 additions & 2 deletions lib/src/core/document/node.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'dart:collection';

import 'package:flutter/material.dart';

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:nanoid/non_secure.dart';

abstract class NodeExternalValues {
Expand Down Expand Up @@ -254,6 +253,11 @@
return map;
}

/// Copy the node
///
/// If the parameters are not provided, the original value will be used.
///
/// Be careful of the children, they will be deep copied if not provided.
Node copyWith({
String? type,
Iterable<Node>? children,
Expand All @@ -277,6 +281,13 @@
return node;
}

/// Deep copy the node
///
/// This is a deep copy of the node, including the children.
Node deepCopy() {
return copyWith();

Check warning on line 288 in lib/src/core/document/node.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/core/document/node.dart#L287-L288

Added lines #L287 - L288 were not covered by tests
}

Path _computePath([Path previous = const []]) {
final parent = this.parent;
if (parent == null) {
Expand Down
Loading