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

feat: adding an ability to have a link check before embedding #603

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/src/editor/toolbar/desktop/items/link/link_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import 'package:appflowy_editor/src/editor/toolbar/desktop/items/utils/overlay_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:string_validator/string_validator.dart';

class LinkMenu extends StatefulWidget {
const LinkMenu({
Expand Down Expand Up @@ -90,11 +91,12 @@
widget.onDismiss();
}
},
child: TextField(
child: TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
focusNode: _focusNode,
textAlign: TextAlign.left,
controller: _textEditingController,
onSubmitted: widget.onSubmitted,
onFieldSubmitted: widget.onSubmitted,
decoration: InputDecoration(
hintText: AppFlowyEditorL10n.current.urlHint,
contentPadding: const EdgeInsets.all(16.0),
Expand All @@ -113,6 +115,12 @@
borderRadius: BorderRadius.all(Radius.circular(12.0)),
),
),
validator: (value) {
if (value == null || value.isEmpty || !isURL(value)) {
return AppFlowyEditorL10n.current.incorrectLink;

Check warning on line 120 in lib/src/editor/toolbar/desktop/items/link/link_menu.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/toolbar/desktop/items/link/link_menu.dart#L120

Added line #L120 was not covered by tests
}
return null;
},
),
);
}
Expand Down
11 changes: 7 additions & 4 deletions lib/src/editor/toolbar/desktop/items/link/link_toolbar_item.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/toolbar/desktop/items/link/link_menu.dart';
import 'package:flutter/material.dart';
import 'package:string_validator/string_validator.dart';

const _menuWidth = 300;
const _hasTextHeight = 244;
Expand Down Expand Up @@ -83,10 +84,12 @@ void showLinkMenu(
await safeLaunchUrl(linkText);
},
onSubmitted: (text) async {
await editorState.formatDelta(selection, {
BuiltInAttributeKey.href: text,
});
dismissOverlay();
if (isURL(text)) {
await editorState.formatDelta(selection, {
BuiltInAttributeKey.href: text,
});
dismissOverlay();
}
},
onCopyLink: () {
AppFlowyClipboard.setData(text: linkText);
Expand Down
Loading