Compare commits

...

35 commits

Author SHA1 Message Date
Göran W
3e5764a031
Merge 408ece148e into 7a9c8d7444 2024-11-19 10:07:30 -03:00
leo
7a9c8d7444
ux: enable TextTrimming for author name in FileHistories
Some checks are pending
Continuous Integration / Build (push) Waiting to run
Continuous Integration / Prepare version string (push) Waiting to run
Continuous Integration / Package (push) Blocked by required conditions
Localization Check / localization-check (push) Waiting to run
Signed-off-by: leo <longshuang@msn.cn>
2024-11-19 20:07:49 +08:00
aikawayataro
8021cd8566
enhance: introduce template engine for commit templates (#704) (#719) 2024-11-19 19:46:44 +08:00
leo
73687689ce
ux: min height of change block in minimap
Signed-off-by: leo <longshuang@msn.cn>
2024-11-19 16:45:07 +08:00
leo
b452e13453
localization: update Text.Repository.HistoriesOrder.ByDate
Signed-off-by: leo <longshuang@msn.cn>
2024-11-19 14:42:59 +08:00
leo
814529a690
feature: add hotkeys to stage/unstage/discard block or selected lines in text diff view (#718)
Signed-off-by: leo <longshuang@msn.cn>
2024-11-19 12:12:54 +08:00
github-actions[bot]
00804e453e doc: Update translation status and missing keys 2024-11-19 03:33:55 +00:00
leo
b25f9bdb6c
feature: supports switch histories order mode (#705)
Signed-off-by: leo <longshuang@msn.cn>
2024-11-19 11:32:13 +08:00
leo
f45bed6f92
fix: avoid NRE
Signed-off-by: leo <longshuang@msn.cn>
2024-11-19 10:31:17 +08:00
leo
3be90b2ef6
Merge branch 'master' into develop 2024-11-19 09:53:24 +08:00
leo
f7ef61f1ce
Merge branch 'release/8.39' 2024-11-19 09:53:03 +08:00
leo
0da46cb90b
version: Release 8.39
Signed-off-by: leo <longshuang@msn.cn>
2024-11-19 09:52:52 +08:00
leo
8b3d129890
code_review: PR #711
* SourceGit.Commands.* should not reference code in SourceGit.ViewModels.

Signed-off-by: leo <longshuang@msn.cn>
2024-11-19 09:46:06 +08:00
Dmitrij D. Czarkoff
309db6e362
enhance: slightly improve statistics (#711)
* use preference MaxHistoryCommits
* use current culture to adjust first days of the week
2024-11-19 09:35:32 +08:00
leo
5b55e3530d
ux: better drop shadow effect for notifications
Signed-off-by: leo <longshuang@msn.cn>
2024-11-19 09:34:09 +08:00
leo
d07a664166
code_review: PR #714
* remove `string.ToLower` warning
* override `OnLoaded` method directly
* clean namespace using

Signed-off-by: leo <longshuang@msn.cn>
2024-11-19 09:27:31 +08:00
Enner Pérez
ea1d966d27
feat: Reset Mode Hotkey (#714) 2024-11-19 09:14:53 +08:00
goran-w
408ece148e Added ToggleTwoSideDiff(), so we can refresh change-block indicator 2024-11-17 23:24:04 +01:00
goran-w
11a02343a0 Added safeguards for edge cases 2024-11-17 22:41:25 +01:00
goran-w
aeea77078b Merge remote-tracking branch 'origin/develop' into diff-prev-next-change-616 2024-11-17 22:21:12 +01:00
goran-w
760e240db7 The 2 implementations can now be switched
Added a bool property DiffView.UseChangeBlocks.
It's not bound from UI yet, but could be used for runtime switching between the two different implementations of prev/next change.
The buttons are now using the OnGoto[Prev|Next]Change Click-handler, regardless of implementation.
2024-11-16 18:39:04 +01:00
goran-w
636be4a7a8 Merge branch 'develop' into diff-prev-next-change-616 2024-11-16 18:09:56 +01:00
goran-w
4882ad0ad6 Added indicator of current/total change-blocks in Diff toolbar 2024-11-16 13:33:10 +01:00
goran-w
dc5bd42477 Make sure SyncScrollOffset is updated after JumpToChangeBlock() 2024-11-16 13:31:39 +01:00
goran-w
5597d25313 Re-enabled my implementation, after merge from pushed alternative 2024-11-16 11:36:10 +01:00
goran-w
07cf4e6fe0 Corrected method duplication mistake, from rebase conflict resolve 2024-11-16 10:47:10 +01:00
goran-w
57e147e84c Revert "Added icons for "Previous/Next Difference""
This reverts commit 1f8dc29de20708a78cba26a341d3451d11304ef9.
2024-11-16 10:43:13 +01:00
goran-w
1a99ce54d3 Cherrypick - feature: add buttons to go to prev/next change in text diff view (#616)
Signed-off-by: leo <longshuang@msn.cn>
(cherry picked from commit 134c71064e)

# Conflicts:
#	src/Views/DiffView.axaml
#	src/Views/TextDiffView.axaml.cs
2024-11-16 10:43:13 +01:00
goran-w
96a9019487 Prev/next will (re-)scroll to first/last change-block in edge-cases
I.e when unset or already at first/last change-block (or the only one).
2024-11-16 10:43:13 +01:00
goran-w
e0c219b46d Unset current change-block in RefreshContent() 2024-11-16 10:43:13 +01:00
goran-w
0007072789 Implemented change-block navigation 2024-11-16 10:43:13 +01:00
goran-w
d0dc9ac1fe Corrected misspelled local variable nextHigh(t)light 2024-11-16 10:41:33 +01:00
goran-w
fbb07cf75f Added 2 new buttons for prev/next change in Diff
These new buttons in DiffView toolbar are visible when IsTextDiff.
They invoke new (and currently empty) methods PrevChange() / NextChange() in DiffContext.
2024-11-16 10:41:33 +01:00
goran-w
875d4b5382 Added icons for "Previous/Next Difference"
New StreamGeometry "Icons.Diff.Prev" / "Icons.Diff.Next" using SVG paths from "arrow_up_regular" / "arrow_down_regular" at https://avaloniaui.github.io/icons.html.
2024-11-16 10:39:46 +01:00
leo
13805f794a
Merge branch 'develop' 2024-11-11 10:29:09 +08:00
30 changed files with 905 additions and 138 deletions

View file

@ -47,7 +47,7 @@
## Translation Status ## Translation Status
[![en_US](https://img.shields.io/badge/en__US-100%25-brightgreen)](TRANSLATION.md) [![de__DE](https://img.shields.io/badge/de__DE-100.00%25-brightgreen)](TRANSLATION.md) [![es__ES](https://img.shields.io/badge/es__ES-99.14%25-yellow)](TRANSLATION.md) [![fr__FR](https://img.shields.io/badge/fr__FR-98.42%25-yellow)](TRANSLATION.md) [![pt__BR](https://img.shields.io/badge/pt__BR-99.14%25-yellow)](TRANSLATION.md) [![ru__RU](https://img.shields.io/badge/ru__RU-100.00%25-brightgreen)](TRANSLATION.md) [![zh__CN](https://img.shields.io/badge/zh__CN-100.00%25-brightgreen)](TRANSLATION.md) [![zh__TW](https://img.shields.io/badge/zh__TW-100.00%25-brightgreen)](TRANSLATION.md) [![en_US](https://img.shields.io/badge/en__US-100%25-brightgreen)](TRANSLATION.md) [![de__DE](https://img.shields.io/badge/de__DE-99.57%25-yellow)](TRANSLATION.md) [![es__ES](https://img.shields.io/badge/es__ES-98.71%25-yellow)](TRANSLATION.md) [![fr__FR](https://img.shields.io/badge/fr__FR-97.99%25-yellow)](TRANSLATION.md) [![pt__BR](https://img.shields.io/badge/pt__BR-98.71%25-yellow)](TRANSLATION.md) [![ru__RU](https://img.shields.io/badge/ru__RU-99.57%25-yellow)](TRANSLATION.md) [![zh__CN](https://img.shields.io/badge/zh__CN-100.00%25-brightgreen)](TRANSLATION.md) [![zh__TW](https://img.shields.io/badge/zh__TW-100.00%25-brightgreen)](TRANSLATION.md)
## How to Use ## How to Use

View file

@ -1,14 +1,16 @@
### de_DE.axaml: 100.00% ### de_DE.axaml: 99.57%
<details> <details>
<summary>Missing Keys</summary> <summary>Missing Keys</summary>
- Text.Repository.HistoriesOrder
- Text.Repository.HistoriesOrder.ByDate
- Text.Repository.HistoriesOrder.Topo
</details> </details>
### es_ES.axaml: 99.14% ### es_ES.axaml: 98.71%
<details> <details>
@ -20,10 +22,13 @@
- Text.Repository.FilterCommits.Default - Text.Repository.FilterCommits.Default
- Text.Repository.FilterCommits.Exclude - Text.Repository.FilterCommits.Exclude
- Text.Repository.FilterCommits.Include - Text.Repository.FilterCommits.Include
- Text.Repository.HistoriesOrder
- Text.Repository.HistoriesOrder.ByDate
- Text.Repository.HistoriesOrder.Topo
</details> </details>
### fr_FR.axaml: 98.42% ### fr_FR.axaml: 97.99%
<details> <details>
@ -39,11 +44,14 @@
- Text.Repository.FilterCommits.Default - Text.Repository.FilterCommits.Default
- Text.Repository.FilterCommits.Exclude - Text.Repository.FilterCommits.Exclude
- Text.Repository.FilterCommits.Include - Text.Repository.FilterCommits.Include
- Text.Repository.HistoriesOrder
- Text.Repository.HistoriesOrder.ByDate
- Text.Repository.HistoriesOrder.Topo
- Text.ScanRepositories - Text.ScanRepositories
</details> </details>
### pt_BR.axaml: 99.14% ### pt_BR.axaml: 98.71%
<details> <details>
@ -55,16 +63,21 @@
- Text.Repository.FilterCommits.Default - Text.Repository.FilterCommits.Default
- Text.Repository.FilterCommits.Exclude - Text.Repository.FilterCommits.Exclude
- Text.Repository.FilterCommits.Include - Text.Repository.FilterCommits.Include
- Text.Repository.HistoriesOrder
- Text.Repository.HistoriesOrder.ByDate
- Text.Repository.HistoriesOrder.Topo
</details> </details>
### ru_RU.axaml: 100.00% ### ru_RU.axaml: 99.57%
<details> <details>
<summary>Missing Keys</summary> <summary>Missing Keys</summary>
- Text.Repository.HistoriesOrder
- Text.Repository.HistoriesOrder.ByDate
- Text.Repository.HistoriesOrder.Topo
</details> </details>

View file

@ -1 +1 @@
8.38 8.39

View file

@ -51,6 +51,9 @@ namespace SourceGit.Commands
_result.TextDiff.MaxLineNumber = Math.Max(_newLine, _oldLine); _result.TextDiff.MaxLineNumber = Math.Max(_newLine, _oldLine);
} }
if (_result.TextDiff != null)
_result.TextDiff.ProcessChangeBlocks();
return _result; return _result;
} }

View file

@ -6,11 +6,13 @@ namespace SourceGit.Commands
{ {
public class QueryCommits : Command public class QueryCommits : Command
{ {
public QueryCommits(string repo, string limits, bool needFindHead = true) public QueryCommits(string repo, bool useTopoOrder, string limits, bool needFindHead = true)
{ {
var order = useTopoOrder ? "--topo-order" : "--date-order";
WorkingDirectory = repo; WorkingDirectory = repo;
Context = repo; Context = repo;
Args = "log --date-order --no-show-signature --decorate=full --pretty=format:%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%s " + limits; Args = $"log {order} --no-show-signature --decorate=full --pretty=format:%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%s {limits}";
_findFirstMerged = needFindHead; _findFirstMerged = needFindHead;
} }

View file

@ -4,11 +4,11 @@ namespace SourceGit.Commands
{ {
public class Statistics : Command public class Statistics : Command
{ {
public Statistics(string repo) public Statistics(string repo, int max)
{ {
WorkingDirectory = repo; WorkingDirectory = repo;
Context = repo; Context = repo;
Args = $"log --date-order --branches --remotes -40000 --pretty=format:\"%ct$%aN\""; Args = $"log --date-order --branches --remotes -{max} --pretty=format:\"%ct$%aN\"";
} }
public Models.Statistics Result() public Models.Statistics Result()

View file

@ -1,7 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
@ -9,9 +6,6 @@ namespace SourceGit.Models
{ {
public partial class CommitTemplate : ObservableObject public partial class CommitTemplate : ObservableObject
{ {
[GeneratedRegex(@"\$\{files(\:\d+)?\}")]
private static partial Regex REG_COMMIT_TEMPLATE_FILES();
public string Name public string Name
{ {
get => _name; get => _name;
@ -26,55 +20,8 @@ namespace SourceGit.Models
public string Apply(Branch branch, List<Change> changes) public string Apply(Branch branch, List<Change> changes)
{ {
var content = _content var te = new TemplateEngine();
.Replace("${files_num}", $"{changes.Count}") return te.Eval(_content, branch, changes);
.Replace("${branch_name}", branch.Name);
var matches = REG_COMMIT_TEMPLATE_FILES().Matches(content);
if (matches.Count == 0)
return content;
var builder = new StringBuilder();
var last = 0;
for (int i = 0; i < matches.Count; i++)
{
var match = matches[i];
if (!match.Success)
continue;
var start = match.Index;
if (start != last)
builder.Append(content.Substring(last, start - last));
var countStr = match.Groups[1].Value;
var paths = new List<string>();
var more = string.Empty;
if (countStr is { Length: <= 1 })
{
foreach (var c in changes)
paths.Add(c.Path);
}
else
{
var count = Math.Min(int.Parse(countStr.Substring(1)), changes.Count);
for (int j = 0; j < count; j++)
paths.Add(changes[j].Path);
if (count < changes.Count)
more = $" and {changes.Count - count} other files";
}
builder.Append(string.Join(", ", paths));
if (!string.IsNullOrEmpty(more))
builder.Append(more);
last = start + match.Length;
}
if (last != content.Length - 1)
builder.Append(content.Substring(last));
return builder.ToString();
} }
private string _name = string.Empty; private string _name = string.Empty;

View file

@ -2,6 +2,8 @@
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using CommunityToolkit.Mvvm.ComponentModel;
using Avalonia; using Avalonia;
using Avalonia.Media.Imaging; using Avalonia.Media.Imaging;
@ -59,16 +61,70 @@ namespace SourceGit.Models
} }
} }
public partial class TextDiff public class TextDiffChangeBlock
{
public TextDiffChangeBlock(int startLine, int endLine)
{
StartLine = startLine;
EndLine = endLine;
}
public int StartLine { get; set; } = 0;
public int EndLine { get; set; } = 0;
public bool IsInRange(int line)
{
return line >= StartLine && line <= EndLine;
}
}
public partial class TextDiff : ObservableObject
{ {
public string File { get; set; } = string.Empty; public string File { get; set; } = string.Empty;
public List<TextDiffLine> Lines { get; set; } = new List<TextDiffLine>(); public List<TextDiffLine> Lines { get; set; } = new List<TextDiffLine>();
public Vector ScrollOffset { get; set; } = Vector.Zero; public Vector ScrollOffset { get; set; } = Vector.Zero;
public int MaxLineNumber = 0; public int MaxLineNumber = 0;
public int CurrentChangeBlockIdx
{
get => _currentChangeBlockIdx;
set => SetProperty(ref _currentChangeBlockIdx, value);
}
public string Repo { get; set; } = null; public string Repo { get; set; } = null;
public DiffOption Option { get; set; } = null; public DiffOption Option { get; set; } = null;
public List<TextDiffChangeBlock> ChangeBlocks { get; set; } = [];
public void ProcessChangeBlocks()
{
ChangeBlocks.Clear();
int lineIdx = 0, blockStartIdx = 0;
bool isNewBlock = true;
foreach (var line in Lines)
{
lineIdx++;
if (line.Type == Models.TextDiffLineType.Added ||
line.Type == Models.TextDiffLineType.Deleted ||
line.Type == Models.TextDiffLineType.None) // Empty
{
if (isNewBlock)
{
isNewBlock = false;
blockStartIdx = lineIdx;
}
}
else
{
if (!isNewBlock)
{
ChangeBlocks.Add(new TextDiffChangeBlock(blockStartIdx, lineIdx - 1));
isNewBlock = true;
}
}
}
}
public TextDiffSelection MakeSelection(int startLine, int endLine, bool isCombined, bool isOldSide) public TextDiffSelection MakeSelection(int startLine, int endLine, bool isCombined, bool isOldSide)
{ {
var rs = new TextDiffSelection(); var rs = new TextDiffSelection();
@ -626,6 +682,8 @@ namespace SourceGit.Models
return true; return true;
} }
private int _currentChangeBlockIdx = -1; // NOTE: Use -1 as "not set".
[GeneratedRegex(@"^@@ \-(\d+),?\d* \+(\d+),?\d* @@")] [GeneratedRegex(@"^@@ \-(\d+),?\d* \+(\d+),?\d* @@")]
private static partial Regex REG_INDICATOR(); private static partial Regex REG_INDICATOR();
} }

View file

@ -6,23 +6,25 @@ namespace SourceGit.Models
{ {
public static readonly ResetMode[] Supported = public static readonly ResetMode[] Supported =
[ [
new ResetMode("Soft", "Keep all changes. Stage differences", "--soft", Brushes.Green), new ResetMode("Soft", "Keep all changes. Stage differences", "--soft", "S", Brushes.Green),
new ResetMode("Mixed", "Keep all changes. Unstage differences", "--mixed", Brushes.Orange), new ResetMode("Mixed", "Keep all changes. Unstage differences", "--mixed", "M", Brushes.Orange),
new ResetMode("Merge", "Reset while keeping unmerged changes", "--merge", Brushes.Purple), new ResetMode("Merge", "Reset while keeping unmerged changes", "--merge", "G", Brushes.Purple),
new ResetMode("Keep", "Reset while keeping local modifications", "--keep", Brushes.Purple), new ResetMode("Keep", "Reset while keeping local modifications", "--keep", "K", Brushes.Purple),
new ResetMode("Hard", "Discard all changes", "--hard", Brushes.Red), new ResetMode("Hard", "Discard all changes", "--hard", "H", Brushes.Red),
]; ];
public string Name { get; set; } public string Name { get; set; }
public string Desc { get; set; } public string Desc { get; set; }
public string Arg { get; set; } public string Arg { get; set; }
public string Key { get; set; }
public IBrush Color { get; set; } public IBrush Color { get; set; }
public ResetMode(string n, string d, string a, IBrush b) public ResetMode(string n, string d, string a, string k, IBrush b)
{ {
Name = n; Name = n;
Desc = d; Desc = d;
Arg = a; Arg = a;
Key = k;
Color = b; Color = b;
} }
} }

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using LiveChartsCore; using LiveChartsCore;
using LiveChartsCore.Defaults; using LiveChartsCore.Defaults;
@ -138,7 +139,8 @@ namespace SourceGit.Models
public Statistics() public Statistics()
{ {
_today = DateTime.Now.ToLocalTime().Date; _today = DateTime.Now.ToLocalTime().Date;
_thisWeekStart = _today.AddSeconds(-(int)_today.DayOfWeek * 3600 * 24); var weekOffset = (7 + (int)_today.DayOfWeek - (int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek) % 7;
_thisWeekStart = _today.AddDays(-weekOffset);
_thisMonthStart = _today.AddDays(1 - _today.Day); _thisMonthStart = _today.AddDays(1 - _today.Day);
All = new StatisticsReport(StaticsticsMode.All, DateTime.MinValue); All = new StatisticsReport(StaticsticsMode.All, DateTime.MinValue);

View file

@ -0,0 +1,410 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace SourceGit.Models
{
public class TemplateEngine
{
private class Context(Branch branch, IReadOnlyList<Change> changes)
{
public Branch branch = branch;
public IReadOnlyList<Change> changes = changes;
}
private class Text(string text)
{
public string text = text;
}
private class Variable(string name)
{
public string name = name;
}
private class SlicedVariable(string name, int count)
{
public string name = name;
public int count = count;
}
private class RegexVariable(string name, Regex regex, string replacement)
{
public string name = name;
public Regex regex = regex;
public string replacement = replacement;
}
private const char ESCAPE = '\\';
private const char VARIABLE_ANCHOR = '$';
private const char VARIABLE_START = '{';
private const char VARIABLE_END = '}';
private const char VARIABLE_SLICE = ':';
private const char VARIABLE_REGEX = '/';
private const char NEWLINE = '\n';
private const RegexOptions REGEX_OPTIONS = RegexOptions.Singleline | RegexOptions.IgnoreCase;
public string Eval(string text, Branch branch, IReadOnlyList<Change> changes)
{
Reset();
_chars = text.ToCharArray();
Parse();
var context = new Context(branch, changes);
var sb = new StringBuilder();
sb.EnsureCapacity(text.Length);
foreach (var token in _tokens)
{
switch (token)
{
case Text text_token:
sb.Append(text_token.text);
break;
case Variable var_token:
sb.Append(EvalVariable(context, var_token));
break;
case SlicedVariable sliced_var:
sb.Append(EvalVariable(context, sliced_var));
break;
case RegexVariable regex_var:
sb.Append(EvalVariable(context, regex_var));
break;
}
}
return sb.ToString();
}
private void Reset()
{
_pos = 0;
_chars = [];
_tokens.Clear();
}
private char? Next()
{
var c = Peek();
if (c is not null)
{
_pos++;
}
return c;
}
private char? Peek()
{
return (_pos >= _chars.Length) ? null : _chars[_pos];
}
private int? Integer()
{
var start = _pos;
while (Peek() is char c && c >= '0' && c <= '9')
{
_pos++;
}
if (start >= _pos)
return null;
var chars = new ReadOnlySpan<char>(_chars, start, _pos - start);
return int.Parse(chars);
}
private void Parse()
{
// text token start
var tok = _pos;
bool esc = false;
while (Next() is char c)
{
if (esc)
{
esc = false;
continue;
}
switch (c)
{
case ESCAPE:
// allow to escape only \ and $
if (Peek() is char nc && (nc == ESCAPE || nc == VARIABLE_ANCHOR))
{
esc = true;
FlushText(tok, _pos - 1);
tok = _pos;
}
break;
case VARIABLE_ANCHOR:
// backup the position
var bak = _pos;
var variable = TryParseVariable();
if (variable is null)
{
// no variable found, rollback
_pos = bak;
}
else
{
// variable found, flush a text token
FlushText(tok, bak - 1);
_tokens.Add(variable);
tok = _pos;
}
break;
}
}
// flush text token
FlushText(tok, _pos);
}
private void FlushText(int start, int end)
{
int len = end - start;
if (len <= 0)
return;
var text = new string(_chars, start, len);
_tokens.Add(new Text(text));
}
private object TryParseVariable()
{
if (Next() != VARIABLE_START)
return null;
int name_start = _pos;
while (Next() is char c)
{
// name character, continue advancing
if (IsNameChar(c))
continue;
var name_end = _pos - 1;
// not a name character but name is empty, cancel
if (name_start >= name_end)
return null;
var name = new string(_chars, name_start, name_end - name_start);
return c switch
{
// variable
VARIABLE_END => new Variable(name),
// sliced variable
VARIABLE_SLICE => TryParseSlicedVariable(name),
// regex variable
VARIABLE_REGEX => TryParseRegexVariable(name),
_ => null,
};
}
return null;
}
private object TryParseSlicedVariable(string name)
{
int? n = Integer();
if (n is null)
return null;
if (Next() != VARIABLE_END)
return null;
return new SlicedVariable(name, (int)n);
}
private object TryParseRegexVariable(string name)
{
var regex = ParseRegex();
if (regex == null)
return null;
var replacement = ParseReplacement();
if (replacement == null)
return null;
return new RegexVariable(name, regex, replacement);
}
private Regex ParseRegex()
{
var sb = new StringBuilder();
var tok = _pos;
var esc = false;
while (Next() is char c)
{
if (esc)
{
esc = false;
continue;
}
switch (c)
{
case ESCAPE:
// allow to escape only / as \ and { used frequently in regexes
if (Peek() == VARIABLE_REGEX)
{
esc = true;
sb.Append(_chars, tok, _pos - 1 - tok);
tok = _pos;
}
break;
case VARIABLE_REGEX:
// goto is fine
goto Loop_exit;
case NEWLINE:
// no newlines allowed
return null;
}
}
Loop_exit:
sb.Append(_chars, tok, _pos - 1 - tok);
try
{
var pattern = sb.ToString();
if (pattern.Length == 0)
return null;
var regex = new Regex(pattern, REGEX_OPTIONS);
return regex;
}
catch (RegexParseException)
{
return null;
}
}
private string ParseReplacement()
{
var sb = new StringBuilder();
var tok = _pos;
var esc = false;
while (Next() is char c)
{
if (esc)
{
esc = false;
continue;
}
switch (c)
{
case ESCAPE:
// allow to escape only }
if (Peek() == VARIABLE_END)
{
esc = true;
sb.Append(_chars, tok, _pos - 1 - tok);
tok = _pos;
}
break;
case VARIABLE_END:
// goto is fine
goto Loop_exit;
case NEWLINE:
// no newlines allowed
return null;
}
}
Loop_exit:
sb.Append(_chars, tok, _pos - 1 - tok);
var replacement = sb.ToString();
return replacement;
}
private static bool IsNameChar(char c)
{
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
}
// (?) notice or log if variable is not found
private static string EvalVariable(Context context, string name)
{
if (!s_variables.TryGetValue(name, out var getter))
{
return string.Empty;
}
return getter(context);
}
private static string EvalVariable(Context context, Variable variable)
{
return EvalVariable(context, variable.name);
}
private static string EvalVariable(Context context, SlicedVariable variable)
{
if (!s_slicedVariables.TryGetValue(variable.name, out var getter))
{
return string.Empty;
}
return getter(context, variable.count);
}
private static string EvalVariable(Context context, RegexVariable variable)
{
var str = EvalVariable(context, variable.name);
if (string.IsNullOrEmpty(str))
return str;
return variable.regex.Replace(str, variable.replacement);
}
private int _pos = 0;
private char[] _chars = [];
private readonly List<object> _tokens = [];
private delegate string VariableGetter(Context context);
private static readonly IReadOnlyDictionary<string, VariableGetter> s_variables = new Dictionary<string, VariableGetter>() {
// legacy variables
{"branch_name", GetBranchName},
{"files_num", GetFilesCount},
{"files", GetFiles},
//
{"BRANCH", GetBranchName},
{"FILES_COUNT", GetFilesCount},
{"FILES", GetFiles},
};
private static string GetBranchName(Context context)
{
return context.branch.Name;
}
private static string GetFilesCount(Context context)
{
return context.changes.Count.ToString();
}
private static string GetFiles(Context context)
{
var paths = new List<string>();
foreach (var c in context.changes)
paths.Add(c.Path);
return string.Join(", ", paths);
}
private delegate string VariableSliceGetter(Context context, int count);
private static readonly IReadOnlyDictionary<string, VariableSliceGetter> s_slicedVariables = new Dictionary<string, VariableSliceGetter>() {
// legacy variables
{"files", GetFilesSliced},
//
{"FILES", GetFilesSliced},
};
private static string GetFilesSliced(Context context, int count)
{
var sb = new StringBuilder();
var paths = new List<string>();
var max = Math.Min(count, context.changes.Count);
for (int i = 0; i < max; i++)
paths.Add(context.changes[i].Path);
sb.AppendJoin(", ", paths);
if (max < context.changes.Count)
sb.AppendFormat(" and {0} other files", context.changes.Count - max);
return sb.ToString();
}
}
}

View file

@ -79,6 +79,7 @@
<StreamGeometry x:Key="Icons.Move">M299 811 299 725 384 725 384 811 299 811M469 811 469 725 555 725 555 811 469 811M640 811 640 725 725 725 725 811 640 811M299 640 299 555 384 555 384 640 299 640M469 640 469 555 555 555 555 640 469 640M640 640 640 555 725 555 725 640 640 640M299 469 299 384 384 384 384 469 299 469M469 469 469 384 555 384 555 469 469 469M640 469 640 384 725 384 725 469 640 469M299 299 299 213 384 213 384 299 299 299M469 299 469 213 555 213 555 299 469 299M640 299 640 213 725 213 725 299 640 299Z</StreamGeometry> <StreamGeometry x:Key="Icons.Move">M299 811 299 725 384 725 384 811 299 811M469 811 469 725 555 725 555 811 469 811M640 811 640 725 725 725 725 811 640 811M299 640 299 555 384 555 384 640 299 640M469 640 469 555 555 555 555 640 469 640M640 640 640 555 725 555 725 640 640 640M299 469 299 384 384 384 384 469 299 469M469 469 469 384 555 384 555 469 469 469M640 469 640 384 725 384 725 469 640 469M299 299 299 213 384 213 384 299 299 299M469 299 469 213 555 213 555 299 469 299M640 299 640 213 725 213 725 299 640 299Z</StreamGeometry>
<StreamGeometry x:Key="Icons.MoveToAnotherGroup">M64 363l0 204 265 0L329 460c0-11 6-18 14-20C349 437 355 437 362 441c93 60 226 149 226 149 33 22 34 60 0 82 0 0-133 89-226 149-14 9-32-3-32-18l-1-110L64 693l0 117c0 41 34 75 75 75l746 0c41 0 75-34 75-74L960 364c0-0 0-1 0-1L64 363zM64 214l0 75 650 0-33-80c-16-38-62-69-103-69l-440 0C97 139 64 173 64 214z</StreamGeometry> <StreamGeometry x:Key="Icons.MoveToAnotherGroup">M64 363l0 204 265 0L329 460c0-11 6-18 14-20C349 437 355 437 362 441c93 60 226 149 226 149 33 22 34 60 0 82 0 0-133 89-226 149-14 9-32-3-32-18l-1-110L64 693l0 117c0 41 34 75 75 75l746 0c41 0 75-34 75-74L960 364c0-0 0-1 0-1L64 363zM64 214l0 75 650 0-33-80c-16-38-62-69-103-69l-440 0C97 139 64 173 64 214z</StreamGeometry>
<StreamGeometry x:Key="Icons.OpenWith">M683 409v204L1024 308 683 0v191c-413 0-427 526-427 526c117-229 203-307 427-307zm85 492H102V327h153s38-63 114-122H51c-28 0-51 27-51 61v697c0 34 23 61 51 61h768c28 0 51-27 51-61V614l-102 100v187z</StreamGeometry> <StreamGeometry x:Key="Icons.OpenWith">M683 409v204L1024 308 683 0v191c-413 0-427 526-427 526c117-229 203-307 427-307zm85 492H102V327h153s38-63 114-122H51c-28 0-51 27-51 61v697c0 34 23 61 51 61h768c28 0 51-27 51-61V614l-102 100v187z</StreamGeometry>
<StreamGeometry x:Key="Icons.Order">M841 627A43 43 0 00811 555h-299v85h196l-183 183A43 43 0 00555 896h299v-85h-196l183-183zM299 170H213v512H85l171 171 171-171H299zM725 128h-85c-18 0-34 11-40 28l-117 313h91L606 384h154l32 85h91l-117-313A43 43 0 00725 128zm-88 171 32-85h26l32 85h-90z</StreamGeometry>
<StreamGeometry x:Key="Icons.Password">M640 96c-158 0-288 130-288 288 0 17 3 31 5 46L105 681 96 691V928h224v-96h96v-96h96v-95c38 18 82 31 128 31 158 0 288-130 288-288s-130-288-288-288zm0 64c123 0 224 101 224 224s-101 224-224 224a235 235 0 01-109-28l-8-4H448v96h-96v96H256v96H160v-146l253-254 12-11-3-17C419 417 416 400 416 384c0-123 101-224 224-224zm64 96a64 64 0 100 128 64 64 0 100-128z</StreamGeometry> <StreamGeometry x:Key="Icons.Password">M640 96c-158 0-288 130-288 288 0 17 3 31 5 46L105 681 96 691V928h224v-96h96v-96h96v-95c38 18 82 31 128 31 158 0 288-130 288-288s-130-288-288-288zm0 64c123 0 224 101 224 224s-101 224-224 224a235 235 0 01-109-28l-8-4H448v96h-96v96H256v96H160v-146l253-254 12-11-3-17C419 417 416 400 416 384c0-123 101-224 224-224zm64 96a64 64 0 100 128 64 64 0 100-128z</StreamGeometry>
<StreamGeometry x:Key="Icons.Paste">M544 85c49 0 90 37 95 85h75a96 96 0 0196 89L811 267a32 32 0 01-28 32L779 299a32 32 0 01-32-28L747 267a32 32 0 00-28-32L715 235h-91a96 96 0 01-80 42H395c-33 0-62-17-80-42L224 235a32 32 0 00-32 28L192 267v576c0 16 12 30 28 32l4 0h128a32 32 0 0132 28l0 4a32 32 0 01-32 32h-128a96 96 0 01-96-89L128 843V267a96 96 0 0189-96L224 171h75a96 96 0 0195-85h150zm256 256a96 96 0 0196 89l0 7v405a96 96 0 01-89 96L800 939h-277a96 96 0 01-96-89L427 843v-405a96 96 0 0189-96L523 341h277zm-256-192H395a32 32 0 000 64h150a32 32 0 100-64z</StreamGeometry> <StreamGeometry x:Key="Icons.Paste">M544 85c49 0 90 37 95 85h75a96 96 0 0196 89L811 267a32 32 0 01-28 32L779 299a32 32 0 01-32-28L747 267a32 32 0 00-28-32L715 235h-91a96 96 0 01-80 42H395c-33 0-62-17-80-42L224 235a32 32 0 00-32 28L192 267v576c0 16 12 30 28 32l4 0h128a32 32 0 0132 28l0 4a32 32 0 01-32 32h-128a96 96 0 01-96-89L128 843V267a96 96 0 0189-96L224 171h75a96 96 0 0195-85h150zm256 256a96 96 0 0196 89l0 7v405a96 96 0 01-89 96L800 939h-277a96 96 0 01-96-89L427 843v-405a96 96 0 0189-96L523 341h277zm-256-192H395a32 32 0 000 64h150a32 32 0 100-64z</StreamGeometry>
<StreamGeometry x:Key="Icons.Plus">m186 532 287 0 0 287c0 11 9 20 20 20s20-9 20-20l0-287 287 0c11 0 20-9 20-20s-9-20-20-20l-287 0 0-287c0-11-9-20-20-20s-20 9-20 20l0 287-287 0c-11 0-20 9-20 20s9 20 20 20z</StreamGeometry> <StreamGeometry x:Key="Icons.Plus">m186 532 287 0 0 287c0 11 9 20 20 20s20-9 20-20l0-287 287 0c11 0 20-9 20-20s-9-20-20-20l-287 0 0-287c0-11-9-20-20-20s-20 9-20 20l0 287-287 0c-11 0-20 9-20 20s9 20 20 20z</StreamGeometry>

View file

@ -543,6 +543,9 @@
<x:String x:Key="Text.Repository.FilterCommits.Default" xml:space="preserve">Unset</x:String> <x:String x:Key="Text.Repository.FilterCommits.Default" xml:space="preserve">Unset</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Exclude" xml:space="preserve">Hide in commit graph</x:String> <x:String x:Key="Text.Repository.FilterCommits.Exclude" xml:space="preserve">Hide in commit graph</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Include" xml:space="preserve">Filter in commit graph</x:String> <x:String x:Key="Text.Repository.FilterCommits.Include" xml:space="preserve">Filter in commit graph</x:String>
<x:String x:Key="Text.Repository.HistoriesOrder" xml:space="preserve">Switch Order Mode</x:String>
<x:String x:Key="Text.Repository.HistoriesOrder.ByDate" xml:space="preserve">Commit Date (--date-order)</x:String>
<x:String x:Key="Text.Repository.HistoriesOrder.Topo" xml:space="preserve">Topologically (--topo-order)</x:String>
<x:String x:Key="Text.Repository.LocalBranches" xml:space="preserve">LOCAL BRANCHES</x:String> <x:String x:Key="Text.Repository.LocalBranches" xml:space="preserve">LOCAL BRANCHES</x:String>
<x:String x:Key="Text.Repository.NavigateToCurrentHead" xml:space="preserve">Navigate to HEAD</x:String> <x:String x:Key="Text.Repository.NavigateToCurrentHead" xml:space="preserve">Navigate to HEAD</x:String>
<x:String x:Key="Text.Repository.FirstParentFilterToggle" xml:space="preserve">Enable '--first-parent' Option</x:String> <x:String x:Key="Text.Repository.FirstParentFilterToggle" xml:space="preserve">Enable '--first-parent' Option</x:String>

View file

@ -547,6 +547,9 @@
<x:String x:Key="Text.Repository.FilterCommits.Default" xml:space="preserve">不指定</x:String> <x:String x:Key="Text.Repository.FilterCommits.Default" xml:space="preserve">不指定</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Exclude" xml:space="preserve">在提交列表中隐藏</x:String> <x:String x:Key="Text.Repository.FilterCommits.Exclude" xml:space="preserve">在提交列表中隐藏</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Include" xml:space="preserve">使用其对提交列表过滤</x:String> <x:String x:Key="Text.Repository.FilterCommits.Include" xml:space="preserve">使用其对提交列表过滤</x:String>
<x:String x:Key="Text.Repository.HistoriesOrder" xml:space="preserve">切换排序模式</x:String>
<x:String x:Key="Text.Repository.HistoriesOrder.ByDate" xml:space="preserve">按提交时间 (--date-order)</x:String>
<x:String x:Key="Text.Repository.HistoriesOrder.Topo" xml:space="preserve">按拓扑排序 (--topo-order)</x:String>
<x:String x:Key="Text.Repository.LocalBranches" xml:space="preserve">本地分支</x:String> <x:String x:Key="Text.Repository.LocalBranches" xml:space="preserve">本地分支</x:String>
<x:String x:Key="Text.Repository.NavigateToCurrentHead" xml:space="preserve">定位HEAD</x:String> <x:String x:Key="Text.Repository.NavigateToCurrentHead" xml:space="preserve">定位HEAD</x:String>
<x:String x:Key="Text.Repository.FirstParentFilterToggle" xml:space="preserve">启用 --first-parent 过滤选项</x:String> <x:String x:Key="Text.Repository.FirstParentFilterToggle" xml:space="preserve">启用 --first-parent 过滤选项</x:String>

View file

@ -546,6 +546,9 @@
<x:String x:Key="Text.Repository.FilterCommits.Default" xml:space="preserve">不指定</x:String> <x:String x:Key="Text.Repository.FilterCommits.Default" xml:space="preserve">不指定</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Exclude" xml:space="preserve">在提交清單中隱藏</x:String> <x:String x:Key="Text.Repository.FilterCommits.Exclude" xml:space="preserve">在提交清單中隱藏</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Include" xml:space="preserve">使用其來篩選提交清單</x:String> <x:String x:Key="Text.Repository.FilterCommits.Include" xml:space="preserve">使用其來篩選提交清單</x:String>
<x:String x:Key="Text.Repository.HistoriesOrder" xml:space="preserve">切換排序方式</x:String>
<x:String x:Key="Text.Repository.HistoriesOrder.ByDate" xml:space="preserve">按提交时间排序 (--date-order)</x:String>
<x:String x:Key="Text.Repository.HistoriesOrder.Topo" xml:space="preserve">按拓扑排序 (--topo-order)</x:String>
<x:String x:Key="Text.Repository.LocalBranches" xml:space="preserve">本機分支</x:String> <x:String x:Key="Text.Repository.LocalBranches" xml:space="preserve">本機分支</x:String>
<x:String x:Key="Text.Repository.NavigateToCurrentHead" xml:space="preserve">回到 HEAD</x:String> <x:String x:Key="Text.Repository.NavigateToCurrentHead" xml:space="preserve">回到 HEAD</x:String>
<x:String x:Key="Text.Repository.FirstParentFilterToggle" xml:space="preserve">啟用 [--first-parent] 選項</x:String> <x:String x:Key="Text.Repository.FirstParentFilterToggle" xml:space="preserve">啟用 [--first-parent] 選項</x:String>

View file

@ -51,6 +51,12 @@ namespace SourceGit.ViewModels
private set => SetProperty(ref _unifiedLines, value); private set => SetProperty(ref _unifiedLines, value);
} }
public string ChangeBlockIndicator
{
get => _changeBlockIndicator;
private set => SetProperty(ref _changeBlockIndicator, value);
}
public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null) public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null)
{ {
_repo = repo; _repo = repo;
@ -73,6 +79,54 @@ namespace SourceGit.ViewModels
LoadDiffContent(); LoadDiffContent();
} }
public void PrevChange()
{
if (_content is Models.TextDiff textDiff)
{
if (textDiff.CurrentChangeBlockIdx > 0)
{
textDiff.CurrentChangeBlockIdx--;
}
else if (textDiff.ChangeBlocks.Count > 0)
{
// Force property value change and (re-)jump to first change block
textDiff.CurrentChangeBlockIdx = -1;
textDiff.CurrentChangeBlockIdx = 0;
}
}
RefreshChangeBlockIndicator();
}
public void NextChange()
{
if (_content is Models.TextDiff textDiff)
{
if (textDiff.CurrentChangeBlockIdx < textDiff.ChangeBlocks.Count - 1)
{
textDiff.CurrentChangeBlockIdx++;
}
else if (textDiff.ChangeBlocks.Count > 0)
{
// Force property value change and (re-)jump to last change block
textDiff.CurrentChangeBlockIdx = -1;
textDiff.CurrentChangeBlockIdx = textDiff.ChangeBlocks.Count - 1;
}
RefreshChangeBlockIndicator();
}
}
public void RefreshChangeBlockIndicator()
{
string curr = "-", tot = "-";
if (_content is Models.TextDiff textDiff)
{
if (textDiff.CurrentChangeBlockIdx >= 0)
curr = (textDiff.CurrentChangeBlockIdx + 1).ToString();
tot = (textDiff.ChangeBlocks.Count).ToString();
}
ChangeBlockIndicator = curr + "/" + tot;
}
public void ToggleFullTextDiff() public void ToggleFullTextDiff()
{ {
Preference.Instance.UseFullTextDiff = !Preference.Instance.UseFullTextDiff; Preference.Instance.UseFullTextDiff = !Preference.Instance.UseFullTextDiff;
@ -91,6 +145,12 @@ namespace SourceGit.ViewModels
LoadDiffContent(); LoadDiffContent();
} }
public void ToggleTwoSideDiff()
{
Preference.Instance.UseSideBySideDiff = !Preference.Instance.UseSideBySideDiff;
RefreshChangeBlockIndicator();
}
public void OpenExternalMergeTool() public void OpenExternalMergeTool()
{ {
var toolType = Preference.Instance.ExternalMergeToolType; var toolType = Preference.Instance.ExternalMergeToolType;
@ -217,6 +277,8 @@ namespace SourceGit.ViewModels
FileModeChange = latest.FileModeChange; FileModeChange = latest.FileModeChange;
Content = rs; Content = rs;
IsTextDiff = rs is Models.TextDiff; IsTextDiff = rs is Models.TextDiff;
RefreshChangeBlockIndicator();
}); });
}); });
} }
@ -281,6 +343,7 @@ namespace SourceGit.ViewModels
private string _title; private string _title;
private string _fileModeChange = string.Empty; private string _fileModeChange = string.Empty;
private int _unifiedLines = 4; private int _unifiedLines = 4;
private string _changeBlockIndicator = "-/-";
private bool _isTextDiff = false; private bool _isTextDiff = false;
private bool _ignoreWhitespace = false; private bool _ignoreWhitespace = false;
private object _content = null; private object _content = null;

View file

@ -64,7 +64,8 @@ namespace SourceGit.ViewModels
Task.Run(() => Task.Run(() =>
{ {
var commits = new Commands.QueryCommits(_repo.FullPath, $"-n 10000 {commit} -- \"{file}\"", false).Result(); var based = commit ?? string.Empty;
var commits = new Commands.QueryCommits(_repo.FullPath, false, $"-n 10000 {based} -- \"{file}\"", false).Result();
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>
{ {
IsLoading = false; IsLoading = false;

View file

@ -106,6 +106,16 @@ namespace SourceGit.ViewModels
} }
} }
public bool EnableTopoOrderInHistories
{
get => _enableTopoOrderInHistories;
set
{
if (SetProperty(ref _enableTopoOrderInHistories, value))
Task.Run(RefreshCommits);
}
}
public string Filter public string Filter
{ {
get => _filter; get => _filter;
@ -852,7 +862,7 @@ namespace SourceGit.ViewModels
else else
builder.Append(filters); builder.Append(filters);
var commits = new Commands.QueryCommits(_fullpath, builder.ToString()).Result(); var commits = new Commands.QueryCommits(_fullpath, _enableTopoOrderInHistories, builder.ToString()).Result();
var graph = Models.CommitGraph.Parse(commits, _enableFirstParentInHistories); var graph = Models.CommitGraph.Parse(commits, _enableFirstParentInHistories);
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>
@ -2228,6 +2238,7 @@ namespace SourceGit.ViewModels
private bool _onlySearchCommitsInCurrentBranch = false; private bool _onlySearchCommitsInCurrentBranch = false;
private bool _enableReflog = false; private bool _enableReflog = false;
private bool _enableFirstParentInHistories = false; private bool _enableFirstParentInHistories = false;
private bool _enableTopoOrderInHistories = false;
private string _searchCommitFilter = string.Empty; private string _searchCommitFilter = string.Empty;
private List<Models.Commit> _searchedCommits = new List<Models.Commit>(); private List<Models.Commit> _searchedCommits = new List<Models.Commit>();
private List<string> _revisionFiles = new List<string>(); private List<string> _revisionFiles = new List<string>();

View file

@ -54,7 +54,7 @@ namespace SourceGit.ViewModels
{ {
Task.Run(() => Task.Run(() =>
{ {
var result = new Commands.Statistics(repo).Result(); var result = new Commands.Statistics(repo, Preference.Instance.MaxHistoryCommits).Result();
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>
{ {
_data = result; _data = result;

View file

@ -45,10 +45,43 @@ namespace SourceGit.ViewModels
FillEmptyLines(); FillEmptyLines();
ProcessChangeBlocks();
if (previous != null && previous.File == File) if (previous != null && previous.File == File)
_syncScrollOffset = previous._syncScrollOffset; _syncScrollOffset = previous._syncScrollOffset;
} }
public List<Models.TextDiffChangeBlock> ChangeBlocks { get; set; } = [];
public void ProcessChangeBlocks()
{
ChangeBlocks.Clear();
int lineIdx = 0, blockStartIdx = 0;
bool isNewBlock = true;
foreach (var line in Old) // NOTE: Same block size in both Old and New lines.
{
lineIdx++;
if (line.Type == Models.TextDiffLineType.Added ||
line.Type == Models.TextDiffLineType.Deleted ||
line.Type == Models.TextDiffLineType.None) // Empty
{
if (isNewBlock)
{
isNewBlock = false;
blockStartIdx = lineIdx;
}
}
else
{
if (!isNewBlock)
{
ChangeBlocks.Add(new Models.TextDiffChangeBlock(blockStartIdx, lineIdx - 1));
isNewBlock = true;
}
}
}
}
public void ConvertsToCombinedRange(Models.TextDiff combined, ref int startLine, ref int endLine, bool isOldSide) public void ConvertsToCombinedRange(Models.TextDiff combined, ref int startLine, ref int endLine, bool isOldSide)
{ {
endLine = Math.Min(endLine, combined.Lines.Count - 1); endLine = Math.Min(endLine, combined.Lines.Count - 1);

View file

@ -42,6 +42,13 @@
<Path Width="12" Height="12" Stretch="Uniform" Margin="0,6,0,0" Data="{StaticResource Icons.Up}"/> <Path Width="12" Height="12" Stretch="Uniform" Margin="0,6,0,0" Data="{StaticResource Icons.Up}"/>
</Button> </Button>
<TextBlock Classes="primary"
Margin="0,0,0,0"
Text="{Binding ChangeBlockIndicator}"
FontSize="11"
TextTrimming="CharacterEllipsis"
IsVisible="{Binding IsTextDiff}"/>
<Button Classes="icon_button" <Button Classes="icon_button"
Width="28" Width="28"
Click="OnGotoNextChange" Click="OnGotoNextChange"
@ -124,7 +131,8 @@
<ToggleButton Classes="line_path" <ToggleButton Classes="line_path"
Width="28" Height="18" Width="28" Height="18"
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=TwoWay}" Command="{Binding ToggleTwoSideDiff}"
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=OneWay}"
IsVisible="{Binding IsTextDiff}" IsVisible="{Binding IsTextDiff}"
ToolTip.Tip="{DynamicResource Text.Diff.SideBySide}"> ToolTip.Tip="{DynamicResource Text.Diff.SideBySide}">
<Path Width="12" Height="12" Data="{StaticResource Icons.LayoutHorizontal}" Margin="0,2,0,0"/> <Path Width="12" Height="12" Data="{StaticResource Icons.LayoutHorizontal}" Margin="0,2,0,0"/>
@ -241,7 +249,8 @@
<DataTemplate DataType="m:TextDiff"> <DataTemplate DataType="m:TextDiff">
<v:TextDiffView <v:TextDiffView
UseSideBySideDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=OneWay}" UseSideBySideDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=OneWay}"
UseFullTextDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseFullTextDiff, Mode=OneWay}"/> UseFullTextDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseFullTextDiff, Mode=OneWay}"
CurrentChangeBlockIdx="{Binding CurrentChangeBlockIdx, Mode=OneWay}"/>
</DataTemplate> </DataTemplate>
<!-- Empty or only EOL changes --> <!-- Empty or only EOL changes -->

View file

@ -11,7 +11,16 @@ namespace SourceGit.Views
InitializeComponent(); InitializeComponent();
} }
public bool UseChangeBlocks { get; set; } = true;
private void OnGotoPrevChange(object _, RoutedEventArgs e) private void OnGotoPrevChange(object _, RoutedEventArgs e)
{
if (UseChangeBlocks)
{
if (DataContext is ViewModels.DiffContext diffCtx)
diffCtx.PrevChange();
}
else
{ {
var textDiff = this.FindDescendantOfType<ThemedTextDiffPresenter>(); var textDiff = this.FindDescendantOfType<ThemedTextDiffPresenter>();
if (textDiff == null) if (textDiff == null)
@ -23,8 +32,16 @@ namespace SourceGit.Views
e.Handled = true; e.Handled = true;
} }
}
private void OnGotoNextChange(object _, RoutedEventArgs e) private void OnGotoNextChange(object _, RoutedEventArgs e)
{
if (UseChangeBlocks)
{
if (DataContext is ViewModels.DiffContext diffCtx)
diffCtx.NextChange();
}
else
{ {
var textDiff = this.FindDescendantOfType<ThemedTextDiffPresenter>(); var textDiff = this.FindDescendantOfType<ThemedTextDiffPresenter>();
if (textDiff == null) if (textDiff == null)
@ -38,3 +55,4 @@ namespace SourceGit.Views
} }
} }
} }
}

View file

@ -80,7 +80,7 @@
<Grid RowDefinitions="Auto,*"> <Grid RowDefinitions="Auto,*">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto,Auto"> <Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto,Auto">
<v:Avatar Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/> <v:Avatar Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/>
<TextBlock Grid.Column="1" Classes="primary" Text="{Binding Author.Name}" Margin="8,0,0,0" ClipToBounds="True"/> <TextBlock Grid.Column="1" Classes="primary" Text="{Binding Author.Name}" Margin="8,0,0,0" TextTrimming="CharacterEllipsis"/>
<TextBlock Grid.Column="2" <TextBlock Grid.Column="2"
Classes="primary" Classes="primary"
Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}"

View file

@ -109,7 +109,7 @@
<ItemsControl ItemsSource="{Binding Notifications}"> <ItemsControl ItemsSource="{Binding Notifications}">
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate DataType="m:Notification"> <DataTemplate DataType="m:Notification">
<Border Margin="6" HorizontalAlignment="Stretch" VerticalAlignment="Top" Effect="drop-shadow(0 0 12 #A0000000)"> <Border Margin="6" HorizontalAlignment="Stretch" VerticalAlignment="Top" Effect="drop-shadow(0 0 8 #8F000000)">
<Border Padding="8" CornerRadius="6" Background="{DynamicResource Brush.Popup}"> <Border Padding="8" CornerRadius="6" Background="{DynamicResource Brush.Popup}">
<Grid RowDefinitions="26,Auto"> <Grid RowDefinitions="26,Auto">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Margin="8,0"> <Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Margin="8,0">

View file

@ -67,7 +67,7 @@
</ListBox.ItemsPanel> </ListBox.ItemsPanel>
<ListBoxItem> <ListBoxItem>
<Grid Classes="view_mode" ColumnDefinitions="32,*,Auto,Auto,Auto"> <Grid Classes="view_mode" ColumnDefinitions="32,*,Auto,Auto,Auto,Auto">
<Path Grid.Column="0" Width="12" Height="12" Data="{StaticResource Icons.Histories}"/> <Path Grid.Column="0" Width="12" Height="12" Data="{StaticResource Icons.Histories}"/>
<TextBlock Grid.Column="1" Classes="primary" Text="{DynamicResource Text.Histories}"/> <TextBlock Grid.Column="1" Classes="primary" Text="{DynamicResource Text.Histories}"/>
<ToggleButton Grid.Column="2" <ToggleButton Grid.Column="2"
@ -91,6 +91,13 @@
ToolTip.Tip="{DynamicResource Text.Repository.FirstParentFilterToggle}"> ToolTip.Tip="{DynamicResource Text.Repository.FirstParentFilterToggle}">
<Path Width="12" Height="12" Data="{StaticResource Icons.FirstParentFilter}"/> <Path Width="12" Height="12" Data="{StaticResource Icons.FirstParentFilter}"/>
</ToggleButton> </ToggleButton>
<Button Grid.Column="5"
Classes="icon_button"
Width="28" Height="26"
Click="OnSwitchHistoriesOrderClicked"
ToolTip.Tip="{DynamicResource Text.Repository.HistoriesOrder}">
<Path Width="12" Height="12" Margin="0,2,0,0" Data="{StaticResource Icons.Order}"/>
</Button>
</Grid> </Grid>
</ListBoxItem> </ListBoxItem>

View file

@ -395,5 +395,38 @@ namespace SourceGit.Views
} }
e.Handled = true; e.Handled = true;
} }
private void OnSwitchHistoriesOrderClicked(object sender, RoutedEventArgs e)
{
if (sender is Button button && DataContext is ViewModels.Repository repo)
{
var checkIcon = App.CreateMenuIcon("Icons.Check");
var dateOrder = new MenuItem();
dateOrder.Header = App.Text("Repository.HistoriesOrder.ByDate");
dateOrder.Icon = repo.EnableTopoOrderInHistories ? null : checkIcon;
dateOrder.Click += (_, ev) =>
{
repo.EnableTopoOrderInHistories = false;
ev.Handled = true;
};
var topoOrder = new MenuItem();
topoOrder.Header = App.Text("Repository.HistoriesOrder.Topo");
topoOrder.Icon = repo.EnableTopoOrderInHistories ? checkIcon : null;
topoOrder.Click += (_, ev) =>
{
repo.EnableTopoOrderInHistories = true;
ev.Handled = true;
};
var menu = new ContextMenu();
menu.Items.Add(dateOrder);
menu.Items.Add(topoOrder);
menu.Open(button);
}
e.Handled = true;
}
} }
} }

View file

@ -37,16 +37,19 @@
Margin="0,0,8,0" Margin="0,0,8,0"
Text="{DynamicResource Text.Reset.Mode}"/> Text="{DynamicResource Text.Reset.Mode}"/>
<ComboBox Grid.Row="2" Grid.Column="1" <ComboBox Grid.Row="2" Grid.Column="1"
x:Name="ResetMode"
Height="28" Padding="8,0" Height="28" Padding="8,0"
VerticalAlignment="Center" HorizontalAlignment="Stretch" VerticalAlignment="Center" HorizontalAlignment="Stretch"
ItemsSource="{Binding Source={x:Static m:ResetMode.Supported}}" ItemsSource="{Binding Source={x:Static m:ResetMode.Supported}}"
SelectedItem="{Binding SelectedMode, Mode=TwoWay}"> SelectedItem="{Binding SelectedMode, Mode=TwoWay}"
KeyDown="OnResetModeKeyDown">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate DataType="m:ResetMode"> <DataTemplate DataType="m:ResetMode">
<Grid ColumnDefinitions="16,60,*"> <Grid ColumnDefinitions="16,60,*">
<Ellipse Grid.Column="0" Width="12" Height="12" Fill="{Binding Color}"/> <Ellipse Grid.Column="0" Width="12" Height="12" Fill="{Binding Color}"/>
<TextBlock Grid.Column="1" Text="{Binding Name}" Margin="4,0,0,0"/> <TextBlock Grid.Column="1" Text="{Binding Name}" Margin="2,0,0,0"/>
<TextBlock Grid.Column="2" Text="{Binding Desc}" FontSize="11" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Right"/> <TextBlock Grid.Column="2" Text="{Binding Desc}" Margin="2,0,16,0" FontSize="11" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Right"/>
<TextBlock Grid.Column="3" Text="{Binding Key}" FontSize="11" FontWeight="Bold" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Right"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ComboBox.ItemTemplate> </ComboBox.ItemTemplate>

View file

@ -1,4 +1,6 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
namespace SourceGit.Views namespace SourceGit.Views
{ {
@ -8,5 +10,29 @@ namespace SourceGit.Views
{ {
InitializeComponent(); InitializeComponent();
} }
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
ResetMode.Focus();
}
private void OnResetModeKeyDown(object sender, KeyEventArgs e)
{
if (sender is ComboBox comboBox)
{
var key = e.Key.ToString();
for (int i = 0; i < Models.ResetMode.Supported.Length; i++)
{
if (key.Equals(Models.ResetMode.Supported[i].Key, System.StringComparison.OrdinalIgnoreCase))
{
comboBox.SelectedIndex = i;
e.Handled = true;
return;
}
}
}
}
} }
} }

View file

@ -30,6 +30,7 @@
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}" UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}" WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}" ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
CurrentChangeBlockIdx="{Binding #ThisControl.CurrentChangeBlockIdx}"
EnableChunkSelection="{Binding #ThisControl.EnableChunkSelection}" EnableChunkSelection="{Binding #ThisControl.EnableChunkSelection}"
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/> SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/>
@ -61,6 +62,7 @@
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}" UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
WordWrap="False" WordWrap="False"
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}" ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
CurrentChangeBlockIdx="{Binding #ThisControl.CurrentChangeBlockIdx}"
EnableChunkSelection="{Binding #ThisControl.EnableChunkSelection}" EnableChunkSelection="{Binding #ThisControl.EnableChunkSelection}"
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/> SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/>
@ -82,6 +84,7 @@
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}" UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
WordWrap="False" WordWrap="False"
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}" ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
CurrentChangeBlockIdx="{Binding #ThisControl.CurrentChangeBlockIdx}"
EnableChunkSelection="{Binding #ThisControl.EnableChunkSelection}" EnableChunkSelection="{Binding #ThisControl.EnableChunkSelection}"
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/> SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/>
@ -97,9 +100,29 @@
</ContentControl> </ContentControl>
<StackPanel x:Name="Popup" IsVisible="False" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right" Effect="drop-shadow(0 0 8 #80000000)"> <StackPanel x:Name="Popup" IsVisible="False" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right" Effect="drop-shadow(0 0 8 #80000000)">
<Button Classes="flat" Content="{DynamicResource Text.Hunk.Stage}" Click="OnStageChunk" IsVisible="{Binding #ThisControl.IsUnstagedChange}"/> <Button Classes="flat" Click="OnStageChunk" HotKey="{OnPlatform Ctrl+S, macOS=⌘+S}" IsVisible="{Binding #ThisControl.IsUnstagedChange}">
<Button Classes="flat" Content="{DynamicResource Text.Hunk.Unstage}" Click="OnUnstageChunk" IsVisible="{Binding #ThisControl.IsUnstagedChange, Converter={x:Static BoolConverters.Not}}"/> <TextBlock>
<Button Classes="flat" Content="{DynamicResource Text.Hunk.Discard}" Margin="8,0,0,0" Click="OnDiscardChunk" IsVisible="{Binding #ThisControl.IsUnstagedChange}"/> <Run Text="{DynamicResource Text.Hunk.Stage}"/>
<Run Text=" "/>
<Run Foreground="{DynamicResource Brush.FG2}" FontWeight="Normal" Text="{OnPlatform Ctrl+S, macOS=⌘+S}"/>
</TextBlock>
</Button>
<Button Classes="flat" Click="OnUnstageChunk" HotKey="{OnPlatform Ctrl+U, macOS=⌘+U}" IsVisible="{Binding #ThisControl.IsUnstagedChange, Converter={x:Static BoolConverters.Not}}">
<TextBlock>
<Run Text="{DynamicResource Text.Hunk.Unstage}"/>
<Run Text=" "/>
<Run Foreground="{DynamicResource Brush.FG2}" FontWeight="Normal" Text="{OnPlatform Ctrl+U, macOS=⌘+U}"/>
</TextBlock>
</Button>
<Button Classes="flat" Margin="8,0,0,0" HotKey="{OnPlatform Ctrl+D, macOS=⌘+D}" Click="OnDiscardChunk" IsVisible="{Binding #ThisControl.IsUnstagedChange}">
<TextBlock>
<Run Text="{DynamicResource Text.Hunk.Discard}"/>
<Run Text=" "/>
<Run Foreground="{DynamicResource Brush.FG2}" FontWeight="Normal" Text="{OnPlatform Ctrl+D, macOS=⌘+D}"/>
</TextBlock>
</Button>
</StackPanel> </StackPanel>
</Grid> </Grid>
</UserControl> </UserControl>

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq;
using System.Text; using System.Text;
using Avalonia; using Avalonia;
@ -254,6 +255,10 @@ namespace SourceGit.Views
if (_presenter.Document == null || !textView.VisualLinesValid) if (_presenter.Document == null || !textView.VisualLinesValid)
return; return;
var changeBlock = _presenter.GetCurrentChangeBlock();
Brush changeBlockBG = new SolidColorBrush(Colors.Gray, 0.25);
Pen changeBlockFG = new Pen(Brushes.Gray, 1);
var lines = _presenter.GetLines(); var lines = _presenter.GetLines();
var width = textView.Bounds.Width; var width = textView.Bounds.Width;
foreach (var line in textView.VisualLines) foreach (var line in textView.VisualLines)
@ -266,12 +271,14 @@ namespace SourceGit.Views
break; break;
var info = lines[index - 1]; var info = lines[index - 1];
var bg = GetBrushByLineType(info.Type);
if (bg == null)
continue;
var startY = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.LineTop) - textView.VerticalOffset; var startY = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.LineTop) - textView.VerticalOffset;
var endY = line.GetTextLineVisualYPosition(line.TextLines[^1], VisualYPosition.LineBottom) - textView.VerticalOffset; var endY = line.GetTextLineVisualYPosition(line.TextLines[^1], VisualYPosition.LineBottom) - textView.VerticalOffset;
var bg = GetBrushByLineType(info.Type);
if (bg != null)
{
if (bg != null)
drawingContext.DrawRectangle(bg, null, new Rect(0, startY, width, endY - startY)); drawingContext.DrawRectangle(bg, null, new Rect(0, startY, width, endY - startY));
if (info.Highlights.Count > 0) if (info.Highlights.Count > 0)
@ -279,7 +286,7 @@ namespace SourceGit.Views
var highlightBG = info.Type == Models.TextDiffLineType.Added ? _presenter.AddedHighlightBrush : _presenter.DeletedHighlightBrush; var highlightBG = info.Type == Models.TextDiffLineType.Added ? _presenter.AddedHighlightBrush : _presenter.DeletedHighlightBrush;
var processingIdxStart = 0; var processingIdxStart = 0;
var processingIdxEnd = 0; var processingIdxEnd = 0;
var nextHightlight = 0; var nextHighlight = 0;
foreach (var tl in line.TextLines) foreach (var tl in line.TextLines)
{ {
@ -288,9 +295,9 @@ namespace SourceGit.Views
var y = line.GetTextLineVisualYPosition(tl, VisualYPosition.LineTop) - textView.VerticalOffset; var y = line.GetTextLineVisualYPosition(tl, VisualYPosition.LineTop) - textView.VerticalOffset;
var h = line.GetTextLineVisualYPosition(tl, VisualYPosition.LineBottom) - textView.VerticalOffset - y; var h = line.GetTextLineVisualYPosition(tl, VisualYPosition.LineBottom) - textView.VerticalOffset - y;
while (nextHightlight < info.Highlights.Count) while (nextHighlight < info.Highlights.Count)
{ {
var highlight = info.Highlights[nextHightlight]; var highlight = info.Highlights[nextHighlight];
if (highlight.Start >= processingIdxEnd) if (highlight.Start >= processingIdxEnd)
break; break;
@ -305,13 +312,23 @@ namespace SourceGit.Views
if (highlight.End >= processingIdxEnd) if (highlight.End >= processingIdxEnd)
break; break;
nextHightlight++; nextHighlight++;
} }
processingIdxStart = processingIdxEnd; processingIdxStart = processingIdxEnd;
} }
} }
} }
if (changeBlock != null && changeBlock.IsInRange(index))
{
drawingContext.DrawRectangle(changeBlockBG, null, new Rect(0, startY, width, endY - startY));
if (index == changeBlock.StartLine)
drawingContext.DrawLine(changeBlockFG, new Point(0, startY), new Point(width, startY));
if (index == changeBlock.EndLine)
drawingContext.DrawLine(changeBlockFG, new Point(0, endY), new Point(width, endY));
}
}
} }
private IBrush GetBrushByLineType(Models.TextDiffLineType type) private IBrush GetBrushByLineType(Models.TextDiffLineType type)
@ -486,6 +503,15 @@ namespace SourceGit.Views
set => SetValue(DisplayRangeProperty, value); set => SetValue(DisplayRangeProperty, value);
} }
public static readonly StyledProperty<int> CurrentChangeBlockIdxProperty =
AvaloniaProperty.Register<ThemedTextDiffPresenter, int>(nameof(CurrentChangeBlockIdx));
public int CurrentChangeBlockIdx
{
get => GetValue(CurrentChangeBlockIdxProperty);
set => SetValue(CurrentChangeBlockIdxProperty, value);
}
protected override Type StyleKeyOverride => typeof(TextEditor); protected override Type StyleKeyOverride => typeof(TextEditor);
public ThemedTextDiffPresenter(TextArea area, TextDocument doc) : base(area, doc) public ThemedTextDiffPresenter(TextArea area, TextDocument doc) : base(area, doc)
@ -590,6 +616,27 @@ namespace SourceGit.Views
} }
} }
public Models.TextDiffChangeBlock GetCurrentChangeBlock()
{
return GetChangeBlock(CurrentChangeBlockIdx);
}
public virtual Models.TextDiffChangeBlock GetChangeBlock(int changeBlockIdx)
{
return null;
}
public void JumpToChangeBlock(int changeBlockIdx)
{
var changeBlock = GetChangeBlock(changeBlockIdx);
if (changeBlock != null)
{
TextArea.Caret.Line = changeBlock.StartLine;
//TextArea.Caret.BringCaretToView(); // NOTE: Brings caret line (barely) into view.
ScrollToLine(changeBlock.StartLine); // NOTE: Brings specified line into center of view.
}
}
public override void Render(DrawingContext context) public override void Render(DrawingContext context)
{ {
base.Render(context); base.Render(context);
@ -1017,6 +1064,16 @@ namespace SourceGit.Views
} }
} }
public override Models.TextDiffChangeBlock GetChangeBlock(int changeBlockIdx)
{
if (DataContext is Models.TextDiff diff)
{
if (changeBlockIdx >= 0 && changeBlockIdx < diff.ChangeBlocks.Count)
return diff.ChangeBlocks[changeBlockIdx];
}
return null;
}
protected override void OnLoaded(RoutedEventArgs e) protected override void OnLoaded(RoutedEventArgs e)
{ {
base.OnLoaded(e); base.OnLoaded(e);
@ -1088,8 +1145,10 @@ namespace SourceGit.Views
public void ForceSyncScrollOffset() public void ForceSyncScrollOffset()
{ {
if (_scrollViewer == null)
return;
if (DataContext is ViewModels.TwoSideTextDiff diff) if (DataContext is ViewModels.TwoSideTextDiff diff)
diff.SyncScrollOffset = _scrollViewer.Offset; diff.SyncScrollOffset = _scrollViewer?.Offset ?? Vector.Zero;
} }
public override List<Models.TextDiffLine> GetLines() public override List<Models.TextDiffLine> GetLines()
@ -1233,6 +1292,16 @@ namespace SourceGit.Views
} }
} }
public override Models.TextDiffChangeBlock GetChangeBlock(int changeBlockIdx)
{
if (DataContext is ViewModels.TwoSideTextDiff diff)
{
if (changeBlockIdx >= 0 && changeBlockIdx < diff.ChangeBlocks.Count)
return diff.ChangeBlocks[changeBlockIdx];
}
return null;
}
protected override void OnLoaded(RoutedEventArgs e) protected override void OnLoaded(RoutedEventArgs e)
{ {
base.OnLoaded(e); base.OnLoaded(e);
@ -1302,7 +1371,7 @@ namespace SourceGit.Views
private void OnTextViewScrollChanged(object sender, ScrollChangedEventArgs e) private void OnTextViewScrollChanged(object sender, ScrollChangedEventArgs e)
{ {
if (TextArea.IsFocused && DataContext is ViewModels.TwoSideTextDiff diff) if (TextArea.IsFocused && DataContext is ViewModels.TwoSideTextDiff diff)
diff.SyncScrollOffset = _scrollViewer.Offset; diff.SyncScrollOffset = _scrollViewer?.Offset ?? Vector.Zero;
} }
private void OnTextAreaPointerWheelChanged(object sender, PointerWheelEventArgs e) private void OnTextAreaPointerWheelChanged(object sender, PointerWheelEventArgs e)
@ -1426,7 +1495,7 @@ namespace SourceGit.Views
{ {
var brush = type == Models.TextDiffLineType.Added ? AddedLineBrush : DeletedLineBrush; var brush = type == Models.TextDiffLineType.Added ? AddedLineBrush : DeletedLineBrush;
var y = start / (total * 1.0) * Bounds.Height; var y = start / (total * 1.0) * Bounds.Height;
var h = count / (total * 1.0) * Bounds.Height; var h = Math.Max(0.5, count / (total * 1.0) * Bounds.Height);
context.DrawRectangle(brush, null, new Rect(x, y, width, h)); context.DrawRectangle(brush, null, new Rect(x, y, width, h));
} }
} }
@ -1479,6 +1548,15 @@ namespace SourceGit.Views
set => SetValue(EnableChunkSelectionProperty, value); set => SetValue(EnableChunkSelectionProperty, value);
} }
public static readonly StyledProperty<int> CurrentChangeBlockIdxProperty =
AvaloniaProperty.Register<TextDiffView, int>(nameof(CurrentChangeBlockIdx));
public int CurrentChangeBlockIdx
{
get => GetValue(CurrentChangeBlockIdxProperty);
set => SetValue(CurrentChangeBlockIdxProperty, value);
}
static TextDiffView() static TextDiffView()
{ {
UseSideBySideDiffProperty.Changed.AddClassHandler<TextDiffView>((v, _) => UseSideBySideDiffProperty.Changed.AddClassHandler<TextDiffView>((v, _) =>
@ -1505,6 +1583,19 @@ namespace SourceGit.Views
v.Popup.Margin = new Thickness(0, top, right, 0); v.Popup.Margin = new Thickness(0, top, right, 0);
v.Popup.IsVisible = true; v.Popup.IsVisible = true;
}); });
CurrentChangeBlockIdxProperty.Changed.AddClassHandler<TextDiffView>((v, e) =>
{
if ((int)e.NewValue >= 0 && v.Editor.Presenter != null)
{
foreach (var p in v.Editor.Presenter.GetVisualDescendants().OfType<ThemedTextDiffPresenter>())
{
p.JumpToChangeBlock((int)e.NewValue);
if (p is SingleSideTextDiffPresenter ssp)
ssp.ForceSyncScrollOffset();
}
}
});
} }
public TextDiffView() public TextDiffView()
@ -1552,6 +1643,8 @@ namespace SourceGit.Views
IsUnstagedChange = diff.Option.IsUnstaged; IsUnstagedChange = diff.Option.IsUnstaged;
EnableChunkSelection = diff.Option.WorkingCopyChange != null; EnableChunkSelection = diff.Option.WorkingCopyChange != null;
diff.CurrentChangeBlockIdx = -1; // Unset current change block.
} }
private void OnStageChunk(object _1, RoutedEventArgs _2) private void OnStageChunk(object _1, RoutedEventArgs _2)