Skip to content

Commit 821063e

Browse files
authored
Swap selection start and end index if selection is created from bottom to top (#967)
1 parent aebfffe commit 821063e

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/Views/TextDiffView.axaml.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -970,8 +970,19 @@ private void CopyWithoutIndicators()
970970
}
971971

972972
var lines = GetLines();
973-
var startIdx = Math.Min(selection.StartPosition.Line - 1, lines.Count - 1);
974-
var endIdx = Math.Min(selection.EndPosition.Line - 1, lines.Count - 1);
973+
974+
var startPosition = selection.StartPosition;
975+
var endPosition = selection.EndPosition;
976+
977+
if (startPosition.Line > endPosition.Line
978+
|| startPosition.Line == endPosition.Line && startPosition.Column > endPosition.Column)
979+
{
980+
// swap start and end
981+
(startPosition, endPosition) = (endPosition, startPosition);
982+
}
983+
984+
var startIdx = Math.Min(startPosition.Line - 1, lines.Count - 1);
985+
var endIdx = Math.Min(endPosition.Line - 1, lines.Count - 1);
975986

976987
if (startIdx == endIdx)
977988
{
@@ -995,15 +1006,15 @@ private void CopyWithoutIndicators()
9951006
line.Type == Models.TextDiffLineType.None)
9961007
continue;
9971008

998-
if (i == startIdx && selection.StartPosition.Column > 1)
1009+
if (i == startIdx && startPosition.Column > 1)
9991010
{
1000-
builder.AppendLine(line.Content.Substring(selection.StartPosition.Column - 1));
1011+
builder.AppendLine(line.Content.Substring(startPosition.Column - 1));
10011012
continue;
10021013
}
10031014

1004-
if (i == endIdx && selection.EndPosition.Column < line.Content.Length)
1015+
if (i == endIdx && endPosition.Column < line.Content.Length)
10051016
{
1006-
builder.AppendLine(line.Content.Substring(0, selection.EndPosition.Column));
1017+
builder.AppendLine(line.Content.Substring(0, endPosition.Column));
10071018
continue;
10081019
}
10091020

0 commit comments

Comments
 (0)