|
|
@ -3,6 +3,7 @@ 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/leaf.dart'; |
|
|
|
import '../../models/documents/nodes/leaf.dart'; |
|
|
|
import '../../utils/delta.dart'; |
|
|
|
import '../../utils/delta.dart'; |
|
|
@ -10,6 +11,9 @@ 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; |
|
|
@ -26,6 +30,7 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isContainEmbed = false; |
|
|
|
final insertedText = _adjustInsertedText(diff.inserted); |
|
|
|
final insertedText = _adjustInsertedText(diff.inserted); |
|
|
|
|
|
|
|
|
|
|
|
widget.controller.replaceText( |
|
|
|
widget.controller.replaceText( |
|
|
@ -37,15 +42,29 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState |
|
|
|
void _applyPasteStyle(String insertedText, int start) { |
|
|
|
void _applyPasteStyle(String insertedText, int start) { |
|
|
|
if (insertedText == pastePlainText && pastePlainText != '') { |
|
|
|
if (insertedText == pastePlainText && pastePlainText != '') { |
|
|
|
final pos = start; |
|
|
|
final pos = start; |
|
|
|
for (var i = 0; i < pasteStyle.length; i++) { |
|
|
|
for (var i = 0; i < pasteStyleAndEmbed.length; i++) { |
|
|
|
final offset = pasteStyle[i].offset; |
|
|
|
final offset = pasteStyleAndEmbed[i].offset; |
|
|
|
final style = pasteStyle[i].value; |
|
|
|
final styleAndEmbed = pasteStyleAndEmbed[i].value; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (styleAndEmbed is Embeddable) { |
|
|
|
|
|
|
|
widget.controller.replaceText(pos + offset, 0, styleAndEmbed, null); |
|
|
|
|
|
|
|
} else { |
|
|
|
widget.controller.formatTextStyle( |
|
|
|
widget.controller.formatTextStyle( |
|
|
|
pos + offset, |
|
|
|
pos + offset, |
|
|
|
i == pasteStyle.length - 1 |
|
|
|
i == pasteStyleAndEmbed.length - 1 |
|
|
|
? pastePlainText.length - offset |
|
|
|
? pastePlainText.length - offset |
|
|
|
: pasteStyle[i + 1].offset, |
|
|
|
: pasteStyleAndEmbed[i + 1].offset, |
|
|
|
style); |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -61,6 +80,7 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState |
|
|
|
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]); |
|
|
|