mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-21 13:20:30 +08:00
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -110,6 +110,29 @@ namespace SourceGit.ViewModels
|
||||
return _blocks[_current];
|
||||
}
|
||||
|
||||
public void UpdateByChunk(TextDiffSelectedChunk chunk)
|
||||
{
|
||||
_current = -1;
|
||||
|
||||
var chunkStart = chunk.StartIdx + 1;
|
||||
var chunkEnd = chunk.EndIdx + 1;
|
||||
|
||||
for (var i = 0; i < _blocks.Count; i++)
|
||||
{
|
||||
var block = _blocks[i];
|
||||
if (chunkStart > block.End)
|
||||
continue;
|
||||
|
||||
if (chunkEnd < block.Start)
|
||||
{
|
||||
_current = i - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
_current = i;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateByCaretPosition(int caretLine)
|
||||
{
|
||||
if (_current >= 0 && _current < _blocks.Count)
|
||||
|
||||
@@ -1464,7 +1464,7 @@ namespace SourceGit.Views
|
||||
|
||||
private async void OnStageChunk(object _1, RoutedEventArgs _2)
|
||||
{
|
||||
if (DataContext is not ViewModels.TextDiffContext { SelectedChunk: { } chunk, Data: { } diff, Option: { IsUnstaged: true, WorkingCopyChange: { } change } })
|
||||
if (DataContext is not ViewModels.TextDiffContext { SelectedChunk: { } chunk, Data: { } diff, Option: { IsUnstaged: true, WorkingCopyChange: { } change } } vm)
|
||||
return;
|
||||
|
||||
var selection = diff.MakeSelection(chunk.StartIdx + 1, chunk.EndIdx + 1, chunk.Combined, chunk.IsOldSide);
|
||||
@@ -1496,12 +1496,13 @@ namespace SourceGit.Views
|
||||
await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", "--cache --index").ExecAsync();
|
||||
File.Delete(tmpFile);
|
||||
|
||||
vm.BlockNavigation.UpdateByChunk(chunk);
|
||||
repo.MarkWorkingCopyDirtyManually();
|
||||
}
|
||||
|
||||
private async void OnUnstageChunk(object _1, RoutedEventArgs _2)
|
||||
{
|
||||
if (DataContext is not ViewModels.TextDiffContext { SelectedChunk: { } chunk, Data: { } diff, Option: { IsUnstaged: false, WorkingCopyChange: { } change } })
|
||||
if (DataContext is not ViewModels.TextDiffContext { SelectedChunk: { } chunk, Data: { } diff, Option: { IsUnstaged: false, WorkingCopyChange: { } change } } vm)
|
||||
return;
|
||||
|
||||
var selection = diff.MakeSelection(chunk.StartIdx + 1, chunk.EndIdx + 1, chunk.Combined, chunk.IsOldSide);
|
||||
@@ -1526,12 +1527,13 @@ namespace SourceGit.Views
|
||||
await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", "--cache --index --reverse").ExecAsync();
|
||||
File.Delete(tmpFile);
|
||||
|
||||
vm.BlockNavigation.UpdateByChunk(chunk);
|
||||
repo.MarkWorkingCopyDirtyManually();
|
||||
}
|
||||
|
||||
private async void OnDiscardChunk(object _1, RoutedEventArgs _2)
|
||||
{
|
||||
if (DataContext is not ViewModels.TextDiffContext { SelectedChunk: { } chunk, Data: { } diff, Option: { IsUnstaged: true, WorkingCopyChange: { } change } })
|
||||
if (DataContext is not ViewModels.TextDiffContext { SelectedChunk: { } chunk, Data: { } diff, Option: { IsUnstaged: true, WorkingCopyChange: { } change } } vm)
|
||||
return;
|
||||
|
||||
var selection = diff.MakeSelection(chunk.StartIdx + 1, chunk.EndIdx + 1, chunk.Combined, chunk.IsOldSide);
|
||||
@@ -1563,6 +1565,7 @@ namespace SourceGit.Views
|
||||
await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", "--reverse").ExecAsync();
|
||||
File.Delete(tmpFile);
|
||||
|
||||
vm.BlockNavigation.UpdateByChunk(chunk);
|
||||
repo.MarkWorkingCopyDirtyManually();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user