-
Notifications
You must be signed in to change notification settings - Fork 836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toPlainText method from any Embeddable return text that cannot be used outside of the editor #2065
Comments
@EchoEllet are you familiar with these parts of code? |
I didn't work on them, and I was planning to before. I moved some parts to different files for organization. |
I fix partially to copy just the plain text for custom embeds, but, this could break the feature that let the editor paste the |
|
Copy/paste embed was not supported in the beginning. This is more of enhancement. |
At this case, the OP has an issue where he cannot copy the plain text from his custom implementation of a |
Honestly copy/paste was barely working in the beginning, let alone copy/paste embed. |
I will try to do this. Thanks for the suggestion |
If we can get copy/paste of embed working, it would be a significant new feature |
@CatHood0 |
@singerdmx I already added a method to make the same of
class Embeddable {
const Embeddable(this.type, this.data);
/// The type of this object.
final String type;
/// The data payload of this object.
final dynamic data;
/// Get the plain text from the [Embeddable] data
///
/// By default it's false
bool pasteAsPlaintext() => false;
Map<String, dynamic> toJson() {
return {type: data};
}
static Embeddable fromJson(Map<String, dynamic> json) {
final m = Map<String, dynamic>.from(json);
assert(m.length == 1, 'Embeddable map must only have one key');
return Embeddable(m.keys.first, m.values.first);
}
} I tried this custom embed class ContentTagEmbed extends CustomBlockEmbed {
const ContentTagEmbed(
String value,
) : super(timeStampType, value);
static const String timeStampType = 'content_tag';
@override
bool pasteAsPlaintext() => true;
static ContentTagEmbed fromDocument(Document document) => ContentTagEmbed(jsonEncode(document.toDelta().toJson()));
Document get document => Document.fromJson(jsonDecode(data));
} But always return false. I could be missing something? If you wonder how is working now int _getNodeText(Leaf node, StringBuffer buffer, int offset, int remaining) {
final text = node.toPlainText();
if (text == Embed.kObjectReplacementCharacter) {
final embed = node.value as Embeddable;
if (embed.pasteAsPlaintext()) {
buffer.write(embed.data);
} else {
buffer.write(Embed.kObjectReplacementCharacter);
}
return remaining - node.length;
}
final end = math.min(offset + remaining, text.length);
buffer.write(text.substring(offset, end));
return remaining - (end - offset);
} |
Maybe @EchoEllet knows |
I'm thinking the option where we could have a service (like Clipboard) to this new feature to make more easy extend from it or just override the default operations |
Is there an existing issue for this?
The question
I watch this code on Line class:
It's really useful the
Embed
can be copied and paste multiple times, but, it's difficult if you have just aCustomBlockEmbed
with just plainText and this text is not copied on the clipboard as plainText. I don't know if i already fully explain what is exactly the issue, then you can see this #2050 to undertand better this.If you try to copy any
Embed
, you can see the text is just empty even theEmbed
contains data asString
or thetoPlainText
from theEmbedBuilder
is overrided. I fixed this partially adding this part of code:But i prefer the root error. Could anyone suggest where should i take a look?
The text was updated successfully, but these errors were encountered: