mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: move position to core/selection
This commit is contained in:
parent
e095fd4181
commit
b0257a626d
@ -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';
|
||||
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
@ -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.
|
||||
///
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
@ -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';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user