Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: cannot paste text into the title of the doc (#6821)

Lucas8a7cedd5b428
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_title_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_title_test.dart
index 9b4b5e9ef7..c694ba8d6b 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_title_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_title_test.dart
@@ -347,5 +347,27 @@ void main() {
await tester.pumpAndSettle();
});
+
+ testWidgets('paste text in title, check if the text is updated',
+ (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+
+ await tester.createNewPageWithNameUnderParent();
+
+ await Clipboard.setData(const ClipboardData(text: _testDocumentName));
+
+ final title = tester.editor.findDocumentTitle('');
+ await tester.tapButton(title);
+ await tester.simulateKeyEvent(
+ LogicalKeyboardKey.keyV,
+ isMetaPressed: UniversalPlatform.isMacOS,
+ isControlPressed: !UniversalPlatform.isMacOS,
+ );
+ await tester.pumpAndSettle();
+
+ final newTitle = tester.editor.findDocumentTitle(_testDocumentName);
+ expect(newTitle, findsOneWidget);
+ });
});
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart
index 38fd8dee63..60dd47c42d 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart
@@ -30,6 +30,11 @@ final CommandShortcutEvent customPasteCommand = CommandShortcutEvent(
);
CommandShortcutEventHandler _pasteCommandHandler = (editorState) {
+ final selection = editorState.selection;
+ if (selection == null) {
+ return KeyEventResult.ignored;
+ }
+
doPaste(editorState).then((_) {
final context = editorState.document.root.context;
if (context != null && context.mounted) {