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

[SuperEditor][SuperReader] - Change Document from list of nodes to tree of nodes (Resolves #2278) #2385

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Prev Previous commit
Got almost all tests passing, except a couple sending a tree document…
… to the IME. Next: Change DocumentPosition to include a NodePath instead of a nodeId.
matthew-carroll committed Jan 16, 2025
commit e65a5489649b305590d9726ada32bff090461b06
5 changes: 4 additions & 1 deletion super_editor/lib/src/core/document.dart
Original file line number Diff line number Diff line change
@@ -518,6 +518,9 @@ class NodePath {

NodePath addSubPath(String nodeId) => NodePath([...nodeIds, nodeId]);

@override
String toString() => "[NodePath] - ${nodeIds.join(" > ")}";

@override
bool operator ==(Object other) =>
identical(this, other) ||
@@ -526,7 +529,7 @@ class NodePath {
const DeepCollectionEquality().equals(nodeIds, other.nodeIds);

@override
int get hashCode => nodeIds.hashCode;
int get hashCode => const ListEquality().hash(nodeIds);
}

/// A [DocumentNode] that contains other [DocumentNode]s in a hierarchy.
Original file line number Diff line number Diff line change
@@ -453,9 +453,15 @@ class DocumentImeSerializer {

TextPosition _documentToImePosition(DocumentPosition docPosition) {
editorImeLog.fine("Converting DocumentPosition to IME TextPosition: $docPosition");
final imeRange = docTextNodesToImeRanges[docPosition.nodeId];
// FIXME: don't assume top-level node
final nodePath = NodePath.forNode(docPosition.nodeId);
final imeRange = docTextNodesToImeRanges[nodePath];
if (imeRange == null) {
throw Exception("No such document position in the IME content: $docPosition");
print("Available node paths in mapping:");
for (final entry in docTextNodesToImeRanges.entries) {
print(" - ${entry.key}");
}
throw Exception("No such node path in the IME content: $nodePath");
}

final nodePosition = docPosition.nodePosition;
Binary file modified super_editor/test/super_editor/deletme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions super_editor/test/super_editor/infrastructure/document_test.dart
Original file line number Diff line number Diff line change
@@ -3,6 +3,18 @@ import 'package:super_editor/super_editor.dart';

void main() {
group("Document", () {
group("node paths >", () {
test("equality", () {
expect(NodePath.forNode("1"), equals(NodePath.forNode("1")));
expect(NodePath.forNode("1"), isNot(equals(NodePath.forNode("2"))));

final map = <NodePath, String>{
NodePath.forNode("1"): "Hello",
};
expect(map[NodePath.forNode("1")], "Hello");
});
});

group("nodes", () {
group("equality", () {
test("equivalent TextNodes are equal", () {
Original file line number Diff line number Diff line change
@@ -11,6 +11,11 @@ import 'supereditor_test_tools.dart';
void main() {
group("SuperEditor embedded documents >", () {
testWidgetsOnAllPlatforms("displays embedded documents", (tester) async {
tester.view.physicalSize = const Size(600, 600);
addTearDown(() {
tester.view.resetPhysicalSize();
});

await tester
.createDocument()
.withCustomContent(MutableDocument(nodes: [