Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/TextCopy/ClipboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ public static partial class ClipboardService
return getFunc();
}

/// <summary>
/// Retrieves text data from the Clipboard and splits it into lines.
/// </summary>
public static async Task<string[]?> GetLinesAsync(Cancellation cancellation = default)
{
var text = await GetTextAsync(cancellation);
if (text == null)
return null;
return text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
}

/// <summary>
/// Retrieves text data from the Clipboard and splits it into lines.
/// </summary>
public static string[]? GetLines()
{
var text = GetText();
if (text == null)
return null;
return text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
}

static Func<string, Cancellation, Task> setAsyncAction;
static Action<string> setAction;

Expand Down Expand Up @@ -60,4 +82,22 @@ public static void SetText(string text)
{
setAction(text);
}

/// <summary>
/// Clears the Clipboard and then adds lines of text data to it.
/// </summary>
public static Task SetLinesAsync(string[] lines, Cancellation cancellation = default)
{
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method should validate that the lines parameter is not null to prevent a NullReferenceException when calling string.Join().

Suggested change
{
{
if (lines == null)
throw new ArgumentNullException(nameof(lines));

Copilot uses AI. Check for mistakes.
var text = string.Join(Environment.NewLine, lines);
return SetTextAsync(text, cancellation);
}

/// <summary>
/// Clears the Clipboard and then adds lines of text data to it.
/// </summary>
public static void SetLines(string[] lines)
{
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method should validate that the lines parameter is not null to prevent a NullReferenceException when calling string.Join().

Suggested change
{
{
if (lines == null)
throw new ArgumentNullException(nameof(lines));

Copilot uses AI. Check for mistakes.
var text = string.Join(Environment.NewLine, lines);
SetText(text);
}
}