Swap selection start and end index if selection is created from bottom to top (#967)

This commit is contained in:
Doodeletion 2025-02-11 03:57:20 +01:00 committed by GitHub
parent aebfffee00
commit 821063e3ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -970,8 +970,19 @@ namespace SourceGit.Views
} }
var lines = GetLines(); var lines = GetLines();
var startIdx = Math.Min(selection.StartPosition.Line - 1, lines.Count - 1);
var endIdx = Math.Min(selection.EndPosition.Line - 1, lines.Count - 1); var startPosition = selection.StartPosition;
var endPosition = selection.EndPosition;
if (startPosition.Line > endPosition.Line
|| startPosition.Line == endPosition.Line && startPosition.Column > endPosition.Column)
{
// swap start and end
(startPosition, endPosition) = (endPosition, startPosition);
}
var startIdx = Math.Min(startPosition.Line - 1, lines.Count - 1);
var endIdx = Math.Min(endPosition.Line - 1, lines.Count - 1);
if (startIdx == endIdx) if (startIdx == endIdx)
{ {
@ -995,15 +1006,15 @@ namespace SourceGit.Views
line.Type == Models.TextDiffLineType.None) line.Type == Models.TextDiffLineType.None)
continue; continue;
if (i == startIdx && selection.StartPosition.Column > 1) if (i == startIdx && startPosition.Column > 1)
{ {
builder.AppendLine(line.Content.Substring(selection.StartPosition.Column - 1)); builder.AppendLine(line.Content.Substring(startPosition.Column - 1));
continue; continue;
} }
if (i == endIdx && selection.EndPosition.Column < line.Content.Length) if (i == endIdx && endPosition.Column < line.Content.Length)
{ {
builder.AppendLine(line.Content.Substring(0, selection.EndPosition.Column)); builder.AppendLine(line.Content.Substring(0, endPosition.Column));
continue; continue;
} }