fix: the last selected line is missing while trying to copy multiple lines in text diff view (#1044)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-03-03 15:39:59 +08:00
parent 598bba5210
commit 35ee4a47db
No known key found for this signature in database

View file

@ -1007,8 +1007,8 @@ namespace SourceGit.Views
if (startPosition.Location > endPosition.Location) if (startPosition.Location > endPosition.Location)
(startPosition, endPosition) = (endPosition, startPosition); (startPosition, endPosition) = (endPosition, startPosition);
var startIdx = Math.Min(startPosition.Line - 1, lines.Count - 1); var startIdx = startPosition.Line - 1;
var endIdx = Math.Min(endPosition.Line - 1, lines.Count - 1); var endIdx = endPosition.Line - 1;
if (startIdx == endIdx) if (startIdx == endIdx)
{ {
@ -1025,7 +1025,7 @@ namespace SourceGit.Views
} }
var builder = new StringBuilder(); var builder = new StringBuilder();
for (var i = startIdx; i <= endIdx; i++) for (var i = startIdx; i <= endIdx && i <= lines.Count - 1; i++)
{ {
var line = lines[i]; var line = lines[i];
if (line.Type == Models.TextDiffLineType.Indicator || if (line.Type == Models.TextDiffLineType.Indicator ||
@ -1040,7 +1040,7 @@ namespace SourceGit.Views
if (i == endIdx && endPosition.Column < line.Content.Length) if (i == endIdx && endPosition.Column < line.Content.Length)
{ {
builder.AppendLine(line.Content.Substring(0, endPosition.Column)); builder.AppendLine(line.Content.Substring(0, endPosition.Column - 1));
continue; continue;
} }