From e996c9bd698d48710bfab07cb81696c57cab801f Mon Sep 17 00:00:00 2001 From: Abbas Hussein <112737126+Abbas1Hussein@users.noreply.github.com> Date: Fri, 4 Aug 2023 14:17:32 +0300 Subject: [PATCH] AbbasHussein Avoid pasting the picture, table and box --- lib/src/models/documents/attribute.dart | 1 - .../raw_editor_state_selection_delegate_mixin.dart | 14 +++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/src/models/documents/attribute.dart b/lib/src/models/documents/attribute.dart index 7fd90ccf..37983972 100644 --- a/lib/src/models/documents/attribute.dart +++ b/lib/src/models/documents/attribute.dart @@ -265,7 +265,6 @@ class Attribute { } } - class DataAttribute extends Attribute { const DataAttribute(dynamic data) : super('data', AttributeScope.INLINE, data); } diff --git a/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart b/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart index 363b9d31..9f167569 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart @@ -1,4 +1,4 @@ -import 'dart:math' as math; + import 'dart:math' as math; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; @@ -11,7 +11,7 @@ import '../../utils/delta.dart'; import '../editor.dart'; mixin RawEditorStateSelectionDelegateMixin on EditorState - implements TextSelectionDelegate { +implements TextSelectionDelegate { @override TextEditingValue get textEditingValue { return widget.controller.plainTextEditingValue; @@ -40,8 +40,7 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState _applyPasteStyleAndEmbed(insertedText, diff.start, containsEmbed); } - void _applyPasteStyleAndEmbed( - String insertedText, int start, bool containsEmbed) { + void _applyPasteStyleAndEmbed(String insertedText, int start, bool containsEmbed) { if (insertedText == pastePlainText && pastePlainText != '' || containsEmbed) { final pos = start; @@ -51,7 +50,12 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState final local = pos + offset; if (styleAndEmbed is Embeddable) { - widget.controller.replaceText(local, 0, styleAndEmbed, null); + final hasBox = styleAndEmbed.type.contains('box'); + final hasImage = styleAndEmbed.type.contains('image'); + final hasTable = styleAndEmbed.type.contains('table'); + if (!(hasBox || hasImage || hasTable)){ + widget.controller.replaceText(local, 0, styleAndEmbed, null); + } } else { final style = styleAndEmbed as Style; if (style.isInline) {