mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 12:15:00 +00:00
Swap selection start and end index if selection is created from bottom to top (#967)
This commit is contained in:
parent
aebfffee00
commit
821063e3ec
1 changed files with 17 additions and 6 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue