refactor: move position to core/selection

This commit is contained in:
Lucas.Xu 2022-10-10 09:59:12 +08:00
parent e095fd4181
commit b0257a626d
15 changed files with 50 additions and 26 deletions

View File

@ -5,7 +5,7 @@ export 'src/infra/log.dart';
export 'src/render/style/editor_style.dart';
export 'src/core/document/node.dart';
export 'src/core/document/path.dart';
export 'src/document/position.dart';
export 'src/core/selection/position.dart';
export 'src/document/selection.dart';
export 'src/document/state_tree.dart';
export 'src/core/document/text_delta.dart';

View File

@ -11,17 +11,18 @@ class Position {
@override
bool operator ==(Object other) {
if (other is! Position) {
return false;
}
return path.equals(other.path) && offset == other.offset;
if (identical(this, other)) return true;
return other is Position &&
other.path.equals(path) &&
other.offset == offset;
}
@override
int get hashCode {
final pathHash = Object.hashAll(path);
return Object.hash(pathHash, offset);
}
int get hashCode => Object.hash(offset, Object.hashAll(path));
@override
String toString() => 'path = $path, offset = $offset';
Position copyWith({Path? path, int? offset}) {
return Position(
@ -30,13 +31,10 @@ class Position {
);
}
@override
String toString() => 'path = $path, offset = $offset';
Map<String, dynamic> toJson() {
return {
"path": path.toList(),
"offset": offset,
'path': path,
'offset': offset,
};
}
}

View File

@ -1,5 +1,5 @@
import 'package:appflowy_editor/src/core/document/path.dart';
import 'package:appflowy_editor/src/document/position.dart';
import 'package:appflowy_editor/src/core/selection/position.dart';
/// Selection represents the selected area or the cursor area in the editor.
///

View File

@ -1,6 +1,6 @@
import 'package:appflowy_editor/src/core/document/node.dart';
import 'package:appflowy_editor/src/core/document/path.dart';
import 'package:appflowy_editor/src/document/position.dart';
import 'package:appflowy_editor/src/core/selection/position.dart';
import 'package:appflowy_editor/src/document/selection.dart';
import 'package:appflowy_editor/src/core/document/text_delta.dart';
import 'package:appflowy_editor/src/document/built_in_attribute_keys.dart';

View File

@ -4,7 +4,7 @@ import 'dart:math';
import 'package:appflowy_editor/src/core/document/attributes.dart';
import 'package:appflowy_editor/src/core/document/node.dart';
import 'package:appflowy_editor/src/core/document/path.dart';
import 'package:appflowy_editor/src/document/position.dart';
import 'package:appflowy_editor/src/core/selection/position.dart';
import 'package:appflowy_editor/src/document/selection.dart';
import 'package:appflowy_editor/src/core/document/text_delta.dart';
import 'package:appflowy_editor/src/editor_state.dart';

View File

@ -1,6 +1,6 @@
import 'package:appflowy_editor/src/extensions/object_extensions.dart';
import 'package:appflowy_editor/src/core/document/node.dart';
import 'package:appflowy_editor/src/document/position.dart';
import 'package:appflowy_editor/src/core/selection/position.dart';
import 'package:appflowy_editor/src/document/selection.dart';
import 'package:appflowy_editor/src/infra/flowy_svg.dart';
import 'package:appflowy_editor/src/render/selection/selectable.dart';

View File

@ -1,4 +1,4 @@
import 'package:appflowy_editor/src/document/position.dart';
import 'package:appflowy_editor/src/core/selection/position.dart';
import 'package:appflowy_editor/src/document/selection.dart';
import 'package:appflowy_editor/src/render/selection/selectable.dart';
import 'package:flutter/material.dart';

View File

@ -7,7 +7,7 @@ import 'package:flutter/rendering.dart';
import 'package:appflowy_editor/src/core/document/node.dart';
import 'package:appflowy_editor/src/core/document/path.dart';
import 'package:appflowy_editor/src/document/position.dart';
import 'package:appflowy_editor/src/core/selection/position.dart';
import 'package:appflowy_editor/src/document/selection.dart';
import 'package:appflowy_editor/src/core/document/text_delta.dart';
import 'package:appflowy_editor/src/editor_state.dart';

View File

@ -1,4 +1,4 @@
import 'package:appflowy_editor/src/document/position.dart';
import 'package:appflowy_editor/src/core/selection/position.dart';
import 'package:appflowy_editor/src/document/selection.dart';
import 'package:flutter/material.dart';

View File

@ -1,7 +1,7 @@
import 'package:appflowy_editor/src/core/document/attributes.dart';
import 'package:appflowy_editor/src/core/document/node.dart';
import 'package:appflowy_editor/src/core/document/path.dart';
import 'package:appflowy_editor/src/document/position.dart';
import 'package:appflowy_editor/src/core/selection/position.dart';
import 'package:appflowy_editor/src/document/selection.dart';
import 'package:appflowy_editor/src/editor_state.dart';
import 'package:appflowy_editor/src/extensions/text_node_extensions.dart';

View File

@ -1,5 +1,5 @@
import 'package:appflowy_editor/src/core/document/node.dart';
import 'package:appflowy_editor/src/document/position.dart';
import 'package:appflowy_editor/src/core/selection/position.dart';
import 'package:appflowy_editor/src/document/selection.dart';
import 'package:appflowy_editor/src/service/shortcut_event/shortcut_event_handler.dart';
import 'package:flutter/material.dart';

View File

@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy_editor/src/document/built_in_attribute_keys.dart';
import 'package:appflowy_editor/src/core/document/node.dart';
import 'package:appflowy_editor/src/document/position.dart';
import 'package:appflowy_editor/src/core/selection/position.dart';
import 'package:appflowy_editor/src/document/selection.dart';
import 'package:appflowy_editor/src/editor_state.dart';
import 'package:appflowy_editor/src/operation/transaction_builder.dart';

View File

@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'package:appflowy_editor/src/core/document/node.dart';
import 'package:appflowy_editor/src/core/document/node_iterator.dart';
import 'package:appflowy_editor/src/core/document/path.dart';
import 'package:appflowy_editor/src/document/position.dart';
import 'package:appflowy_editor/src/core/selection/position.dart';
import 'package:appflowy_editor/src/document/selection.dart';
import 'package:appflowy_editor/src/editor_state.dart';
import 'package:appflowy_editor/src/extensions/node_extensions.dart';

View File

@ -0,0 +1,26 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter_test/flutter_test.dart';
void main() async {
group('position.dart', () {
test('test position equality', () {
final positionA = Position(path: [0, 1, 2], offset: 3);
final positionB = Position(path: [0, 1, 2], offset: 3);
expect(positionA, positionB);
final positionC = positionA.copyWith(offset: 4);
final positionD = positionB.copyWith(path: [1, 2, 3]);
expect(positionC.offset, 4);
expect(positionD.path, [1, 2, 3]);
expect(positionA.toJson(), {
'path': [0, 1, 2],
'offset': 3,
});
expect(positionC.toJson(), {
'path': [0, 1, 2],
'offset': 4,
});
});
});
}

View File

@ -1,5 +1,5 @@
import 'package:appflowy_editor/src/core/document/path.dart';
import 'package:appflowy_editor/src/document/position.dart';
import 'package:appflowy_editor/src/core/selection/position.dart';
import 'package:appflowy_editor/src/document/selection.dart';
import 'package:flutter_test/flutter_test.dart';