fix: there's an extra line-ending while copy multiple lines from text diff view (#1049)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-03-04 16:26:14 +08:00
parent b75676a7f8
commit 96538b9a62
No known key found for this signature in database

View file

@ -1032,18 +1032,32 @@ namespace SourceGit.Views
line.Type == Models.TextDiffLineType.None)
continue;
// The first selected line (partial selection)
if (i == startIdx && startPosition.Column > 1)
{
builder.AppendLine(line.Content.Substring(startPosition.Column - 1));
continue;
}
if (i == endIdx && endPosition.Column < line.Content.Length)
// The selection range is larger than original source.
if (i == lines.Count - 1 && i < endIdx)
{
builder.AppendLine(line.Content.Substring(0, endPosition.Column - 1));
continue;
builder.Append(line.Content);
break;
}
// For the last line (selection range is within original source)
if (i == endIdx)
{
if (endPosition.Column < line.Content.Length)
builder.Append(line.Content.Substring(0, endPosition.Column - 1));
else
builder.Append(line.Content);
break;
}
// Other lines.
builder.AppendLine(line.Content);
}