|
|
@ -3,17 +3,14 @@ import 'dart:math' as math; |
|
|
|
import 'package:flutter/rendering.dart'; |
|
|
|
import 'package:flutter/rendering.dart'; |
|
|
|
import 'package:flutter/widgets.dart'; |
|
|
|
import 'package:flutter/widgets.dart'; |
|
|
|
|
|
|
|
|
|
|
|
import '../../../flutter_quill.dart'; |
|
|
|
|
|
|
|
import '../../models/documents/document.dart'; |
|
|
|
import '../../models/documents/document.dart'; |
|
|
|
|
|
|
|
import '../../models/documents/nodes/embeddable.dart'; |
|
|
|
import '../../models/documents/nodes/leaf.dart'; |
|
|
|
import '../../models/documents/nodes/leaf.dart'; |
|
|
|
import '../../utils/delta.dart'; |
|
|
|
import '../../utils/delta.dart'; |
|
|
|
import '../editor.dart'; |
|
|
|
import '../editor.dart'; |
|
|
|
|
|
|
|
|
|
|
|
mixin RawEditorStateSelectionDelegateMixin on EditorState |
|
|
|
mixin RawEditorStateSelectionDelegateMixin on EditorState |
|
|
|
implements TextSelectionDelegate { |
|
|
|
implements TextSelectionDelegate { |
|
|
|
|
|
|
|
|
|
|
|
bool isContainEmbed = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
TextEditingValue get textEditingValue { |
|
|
|
TextEditingValue get textEditingValue { |
|
|
|
return widget.controller.plainTextEditingValue; |
|
|
|
return widget.controller.plainTextEditingValue; |
|
|
@ -30,17 +27,22 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isContainEmbed = false; |
|
|
|
var insertedText = diff.inserted; |
|
|
|
final insertedText = _adjustInsertedText(diff.inserted); |
|
|
|
final containsEmbed = |
|
|
|
|
|
|
|
insertedText.codeUnits.contains(Embed.kObjectReplacementInt); |
|
|
|
|
|
|
|
insertedText = |
|
|
|
|
|
|
|
containsEmbed ? _adjustInsertedText(diff.inserted) : diff.inserted; |
|
|
|
|
|
|
|
|
|
|
|
widget.controller.replaceText( |
|
|
|
widget.controller.replaceText( |
|
|
|
diff.start, diff.deleted.length, insertedText, value.selection); |
|
|
|
diff.start, diff.deleted.length, insertedText, value.selection); |
|
|
|
|
|
|
|
|
|
|
|
_applyPasteStyle(insertedText, diff.start); |
|
|
|
_applyPasteStyleAndEmbed(insertedText, diff.start, containsEmbed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void _applyPasteStyle(String insertedText, int start) { |
|
|
|
void _applyPasteStyleAndEmbed( |
|
|
|
if (insertedText == pastePlainText && pastePlainText != '') { |
|
|
|
String insertedText, int start, bool containsEmbed) { |
|
|
|
|
|
|
|
if (insertedText == pastePlainText && pastePlainText != '' || |
|
|
|
|
|
|
|
containsEmbed) { |
|
|
|
final pos = start; |
|
|
|
final pos = start; |
|
|
|
for (var i = 0; i < pasteStyleAndEmbed.length; i++) { |
|
|
|
for (var i = 0; i < pasteStyleAndEmbed.length; i++) { |
|
|
|
final offset = pasteStyleAndEmbed[i].offset; |
|
|
|
final offset = pasteStyleAndEmbed[i].offset; |
|
|
@ -57,30 +59,13 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState |
|
|
|
styleAndEmbed); |
|
|
|
styleAndEmbed); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}else if(isContainEmbed){ |
|
|
|
|
|
|
|
final pos = start; |
|
|
|
|
|
|
|
for (var i = 0; i < pasteStyleAndEmbed.length; i++) { |
|
|
|
|
|
|
|
final offset = pasteStyleAndEmbed[i].offset; |
|
|
|
|
|
|
|
final style = pasteStyleAndEmbed[i].value; |
|
|
|
|
|
|
|
if (style is Embeddable) { |
|
|
|
|
|
|
|
widget.controller.replaceText(pos + offset, 0, style, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String _adjustInsertedText(String text) { |
|
|
|
String _adjustInsertedText(String text) { |
|
|
|
// For clip from editor, it may contain image, a.k.a 65532 or '\uFFFC'. |
|
|
|
|
|
|
|
// For clip from browser, image is directly ignore. |
|
|
|
|
|
|
|
// Here we skip image when pasting. |
|
|
|
|
|
|
|
if (!text.codeUnits.contains(Embed.kObjectReplacementInt)) { |
|
|
|
|
|
|
|
return text; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final sb = StringBuffer(); |
|
|
|
final sb = StringBuffer(); |
|
|
|
for (var i = 0; i < text.length; i++) { |
|
|
|
for (var i = 0; i < text.length; i++) { |
|
|
|
if (text.codeUnitAt(i) == Embed.kObjectReplacementInt) { |
|
|
|
if (text.codeUnitAt(i) == Embed.kObjectReplacementInt) { |
|
|
|
isContainEmbed = true; |
|
|
|
|
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
sb.write(text[i]); |
|
|
|
sb.write(text[i]); |
|
|
|