executeHandleCopy function
Implementation
Future<void> executeHandleCopy(FluentDocument document) async {
final cursor = document.cursor;
if (cursor.isCollapsed) return;
final sel = resolveSelection(
document.content,
cursor.anchorId,
cursor.anchorOffset,
cursor.focusId,
cursor.focusOffset,
cachedStops: document.caretStops,
cachedLines: document.logicalLines,
);
if (sel == null) return;
final clonedNodes = <Map<String, dynamic>>[];
final plainTextBuffer = StringBuffer();
// Group SelectedNode by top-level container
// SelectedNodes refer to Paragraph/ListItem/FluentCell:
// we need to reconstruct the ancestor structure (List, Table, Row)
final topLevelNodes = _groupByTopLevel(document.content, sel);
for (final tlEntry in topLevelNodes) {
final clone = _cloneTopLevel(tlEntry, sel, plainTextBuffer);
if (clone != null) {
clonedNodes.add(clone.toJson());
} else {
}
plainTextBuffer.write('\n');
}
// Remove the last excess \n
final plainText = plainTextBuffer.toString().trimRight();
final payload = _ClipboardPayload(
plainText: plainText,
nodes: clonedNodes,
);
await Clipboard.setData(ClipboardData(text: plainText));
document.clipboardPayload = jsonEncode(payload.toJson());
}