handleCopy function
Implementation
void handleCopy(EditorState editorState) async {
final selection = editorState.selection?.normalized;
if (selection == null) {
return;
}
String text;
String html;
if (selection.isCollapsed) {
final node = editorState.getNodeAtPath(selection.end.path);
if (node == null) {
return;
}
text = node.delta?.toPlainText() ?? '';
html = documentToHTML(
Document(
root: pageNode(children: [node.copyWith()]),
),
);
} else {
text = editorState.getTextInSelection(selection).join('\n');
final nodes = editorState.getSelectedNodes(selection: selection);
if (nodes.isEmpty) {
return;
}
html = documentToHTML(
Document(
root: pageNode(
children: nodes.map((node) => node.copyWith()),
),
),
);
}
return AppFlowyClipboard.setData(
text: text,
html: html.isEmpty ? null : html,
);
}