From d5d112e8bfcd6e4ae123902c80decd302f2f9e05 Mon Sep 17 00:00:00 2001 From: "sunamo.cz" Date: Wed, 20 Aug 2025 23:27:13 +0200 Subject: [PATCH] feat: Get and Set lines --- src/TextCopy/ClipboardService.cs | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/TextCopy/ClipboardService.cs b/src/TextCopy/ClipboardService.cs index 4b2951ea..3e484326 100644 --- a/src/TextCopy/ClipboardService.cs +++ b/src/TextCopy/ClipboardService.cs @@ -28,6 +28,28 @@ public static partial class ClipboardService return getFunc(); } + /// + /// Retrieves text data from the Clipboard and splits it into lines. + /// + public static async Task GetLinesAsync(Cancellation cancellation = default) + { + var text = await GetTextAsync(cancellation); + if (text == null) + return null; + return text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); + } + + /// + /// Retrieves text data from the Clipboard and splits it into lines. + /// + public static string[]? GetLines() + { + var text = GetText(); + if (text == null) + return null; + return text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); + } + static Func setAsyncAction; static Action setAction; @@ -60,4 +82,22 @@ public static void SetText(string text) { setAction(text); } + + /// + /// Clears the Clipboard and then adds lines of text data to it. + /// + public static Task SetLinesAsync(string[] lines, Cancellation cancellation = default) + { + var text = string.Join(Environment.NewLine, lines); + return SetTextAsync(text, cancellation); + } + + /// + /// Clears the Clipboard and then adds lines of text data to it. + /// + public static void SetLines(string[] lines) + { + var text = string.Join(Environment.NewLine, lines); + SetText(text); + } } \ No newline at end of file