From 96538b9a6246ceebbb259cbdfd7abc3dc8239132 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 4 Mar 2025 16:26:14 +0800 Subject: [PATCH] fix: there's an extra line-ending while copy multiple lines from text diff view (#1049) Signed-off-by: leo --- src/Views/TextDiffView.axaml.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index 958e803e..30034bc6 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -1032,18 +1032,32 @@ private void CopyWithoutIndicators() 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); }