Merge pull request #787 from AppFlowy-IO/feat/add-default-impl-for-image

Feat: add default impl for image
This commit is contained in:
Nathan.fooo 2022-08-08 18:47:48 +08:00 committed by GitHub
commit 0bf4a79ec9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 32 deletions

View File

@ -55,26 +55,22 @@ class _ImageNodeWidgetState extends State<ImageNodeWidget> with Selectable {
@override @override
Position end() { Position end() {
// TODO: implement end return Position(path: node.path, offset: 0);
throw UnimplementedError();
} }
@override @override
Position start() { Position start() {
// TODO: implement start return Position(path: node.path, offset: 0);
throw UnimplementedError();
} }
@override @override
List<Rect> getRectsInSelection(Selection selection) { List<Rect> getRectsInSelection(Selection selection) {
// TODO: implement getRectsInSelection return [];
throw UnimplementedError();
} }
@override @override
Selection getSelectionInRange(Offset start, Offset end) { Selection getSelectionInRange(Offset start, Offset end) {
// TODO: implement getSelectionInRange return Selection.collapsed(Position(path: node.path, offset: 0));
throw UnimplementedError();
} }
@override @override
@ -82,12 +78,6 @@ class _ImageNodeWidgetState extends State<ImageNodeWidget> with Selectable {
throw UnimplementedError(); throw UnimplementedError();
} }
@override
Rect getCursorRectInPosition(Position position) {
// TODO: implement getCursorRectInPosition
throw UnimplementedError();
}
@override @override
Position getPositionInOffset(Offset start) { Position getPositionInOffset(Offset start) {
return Position(path: node.path, offset: 0); return Position(path: node.path, offset: 0);

View File

@ -32,7 +32,8 @@ class LinkNodeWidget extends StatefulWidget {
State<LinkNodeWidget> createState() => _YouTubeLinkNodeWidgetState(); State<LinkNodeWidget> createState() => _YouTubeLinkNodeWidgetState();
} }
class _YouTubeLinkNodeWidgetState extends State<LinkNodeWidget> with Selectable { class _YouTubeLinkNodeWidgetState extends State<LinkNodeWidget>
with Selectable {
Node get node => widget.node; Node get node => widget.node;
EditorState get editorState => widget.editorState; EditorState get editorState => widget.editorState;
String get src => widget.node.attributes['youtube_link'] as String; String get src => widget.node.attributes['youtube_link'] as String;
@ -66,12 +67,6 @@ class _YouTubeLinkNodeWidgetState extends State<LinkNodeWidget> with Selectable
throw UnimplementedError(); throw UnimplementedError();
} }
@override
Rect getCursorRectInPosition(Position position) {
// TODO: implement getCursorRectInPosition
throw UnimplementedError();
}
@override @override
Position getPositionInOffset(Offset start) { Position getPositionInOffset(Offset start) {
// TODO: implement getPositionInOffset // TODO: implement getPositionInOffset

View File

@ -11,8 +11,8 @@ mixin DefaultSelectable {
Position getPositionInOffset(Offset start) => Position getPositionInOffset(Offset start) =>
forward.getPositionInOffset(start); forward.getPositionInOffset(start);
Rect getCursorRectInPosition(Position position) => Rect? getCursorRectInPosition(Position position) =>
forward.getCursorRectInPosition(position).shift(baseOffset); forward.getCursorRectInPosition(position)?.shift(baseOffset);
List<Rect> getRectsInSelection(Selection selection) => forward List<Rect> getRectsInSelection(Selection selection) => forward
.getRectsInSelection(selection) .getRectsInSelection(selection)

View File

@ -76,7 +76,7 @@ class _FlowyRichTextState extends State<FlowyRichText> with Selectable {
path: widget.textNode.path, offset: widget.textNode.toRawString().length); path: widget.textNode.path, offset: widget.textNode.toRawString().length);
@override @override
Rect getCursorRectInPosition(Position position) { Rect? getCursorRectInPosition(Position position) {
final textPosition = TextPosition(offset: position.offset); final textPosition = TextPosition(offset: position.offset);
final cursorOffset = final cursorOffset =
_renderParagraph.getOffsetForCaret(textPosition, Rect.zero); _renderParagraph.getOffsetForCaret(textPosition, Rect.zero);

View File

@ -25,7 +25,9 @@ mixin Selectable<T extends StatefulWidget> on State<T> {
return null; return null;
} }
Rect getCursorRectInPosition(Position position); Rect? getCursorRectInPosition(Position position) {
return null;
}
Offset localToGlobal(Offset offset); Offset localToGlobal(Offset offset);

View File

@ -246,9 +246,11 @@ class _FlowyInputState extends State<FlowyInput>
final size = renderBox.size; final size = renderBox.size;
final transform = renderBox.getTransformTo(null); final transform = renderBox.getTransformTo(null);
final rect = selectable.getCursorRectInPosition(selection.end); final rect = selectable.getCursorRectInPosition(selection.end);
if (rect != null) {
_textInputConnection _textInputConnection
?..setEditableSizeAndTransform(size, transform) ?..setEditableSizeAndTransform(size, transform)
..setCaretRect(rect); ..setCaretRect(rect);
} }
} }
} }
}

View File

@ -71,6 +71,9 @@ FlowyKeyEventHandler slashShortcutHandler = (editorState, event) {
} }
final rect = selectable.getCursorRectInPosition(selection.start); final rect = selectable.getCursorRectInPosition(selection.start);
if (rect == null) {
return KeyEventResult.ignored;
}
final offset = selectable.localToGlobal(rect.topLeft); final offset = selectable.localToGlobal(rect.topLeft);
TransactionBuilder(editorState) TransactionBuilder(editorState)