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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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