From 4df6c259a5e0dfef744b582da9cec50dc2a00aab Mon Sep 17 00:00:00 2001 From: Angelo Silvestre Date: Fri, 29 Nov 2024 21:50:22 -0300 Subject: [PATCH] [super_editor_markdown] Fix compilation error (#2406) --- .../lib/src/super_editor_paste_markdown.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/super_editor_markdown/lib/src/super_editor_paste_markdown.dart b/super_editor_markdown/lib/src/super_editor_paste_markdown.dart index 8dd59b178b..f9797ce720 100644 --- a/super_editor_markdown/lib/src/super_editor_paste_markdown.dart +++ b/super_editor_markdown/lib/src/super_editor_paste_markdown.dart @@ -40,15 +40,19 @@ Future pasteMarkdown({ required Document document, required DocumentComposer composer, }) async { - DocumentPosition pastePosition = composer.selection!.extent; - // Delete all currently selected content. if (!composer.selection!.isCollapsed) { - pastePosition = CommonEditorOperations.getDocumentPositionAfterExpandedDeletion( + final pastePosition = CommonEditorOperations.getDocumentPositionAfterExpandedDeletion( document: document, selection: composer.selection!, ); + if (pastePosition == null) { + // A null pastePosition means that the selection can't be deleted. This might happen + // when the selection contains only non-deletable nodes. Therefore, we cannot paste. + return; + } + // Delete the selected content. editor.execute([ DeleteContentRequest(documentRange: composer.selection!), @@ -67,7 +71,7 @@ Future pasteMarkdown({ editor.execute([ PasteStructuredContentEditorRequest( content: deserializedMarkdown, - pastePosition: pastePosition, + pastePosition: composer.selection!.extent, ), ]); }