exportCodeSelection function
String
exportCodeSelection(
- CodeDocument document, {
- required int lineIndex,
- CodeViewCopyOptions options = const CodeViewCopyOptions(),
Exports the selected line or whole source document as sanitized text.
Implementation
String exportCodeSelection(
CodeDocument document, {
required int lineIndex,
CodeViewCopyOptions options = const CodeViewCopyOptions(),
}) {
if (document.lines.isEmpty) return '';
final currentIndex = lineIndex.clamp(0, document.lines.length - 1);
return switch (options.mode) {
CodeViewCopyMode.line => document.lines[currentIndex].text,
CodeViewCopyMode.document => [
for (final line in document.lines) line.text,
].join('\n'),
};
}