From bd109bffcc0a899dd98cdf3369a127cb2702f10c Mon Sep 17 00:00:00 2001 From: li3317 Date: Fri, 27 Aug 2021 22:13:41 -0400 Subject: [PATCH] Skip image when pasting --- lib/src/widgets/raw_editor.dart | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/src/widgets/raw_editor.dart b/lib/src/widgets/raw_editor.dart index 1f350646..4f2ea0ad 100644 --- a/lib/src/widgets/raw_editor.dart +++ b/lib/src/widgets/raw_editor.dart @@ -637,10 +637,25 @@ class RawEditorState extends EditorState if (data != null) { final length = textEditingValue.selection.end - textEditingValue.selection.start; + var str = data.text!; + final codes = data.text!.codeUnits; + // For clip from editor, it may contain image, a.k.a 65532. + // For clip from browser, image is directly ignore. + // Here we skip image when pasting. + if (codes.contains(65532)) { + final sb = StringBuffer(); + for (var i = 0; i < str.length; i++) { + if (str.codeUnitAt(i) == 65532) { + continue; + } + sb.write(str[i]); + } + str = sb.toString(); + } widget.controller.replaceText( value.selection.start, length, - data.text, + str, value.selection, ); // move cursor to the end of pasted text selection