From 983607e70881824e5e5a885980c2f1210c66c11e Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 23 Sep 2024 14:44:23 +0800 Subject: [PATCH 0001/1497] fix: minimize window button not work on Windows 10 (#501) --- src/Native/Windows.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index b02112cc..6ca0bbb0 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -201,9 +201,9 @@ namespace SourceGit.Native private void FixWindowFrameOnWin10(Window w) { - if (w.WindowState != WindowState.Normal) + if (w.WindowState == WindowState.Maximized || w.WindowState == WindowState.FullScreen) w.SystemDecorations = SystemDecorations.Full; - else + else if (w.WindowState == WindowState.Normal) w.SystemDecorations = SystemDecorations.BorderOnly; } From af57c56cd7591393a1246932af1cdcb29476d2d9 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 23 Sep 2024 21:45:44 +0800 Subject: [PATCH 0002/1497] feature: enhanced statistics panel (#493) * replace the `YEAR` tab with `OVERVIEW` tab, which will analyze most recent 20K commits * use `LiveChartsCore.SkiaSharpView.Avalonia` instead of a custom chart view --- src/Commands/Statistics.cs | 32 +++-- src/Models/Statistics.cs | 179 +++++++++++++++---------- src/Resources/Locales/de_DE.axaml | 1 - src/Resources/Locales/en_US.axaml | 2 +- src/Resources/Locales/fr_FR.axaml | 1 - src/Resources/Locales/pt_BR.axaml | 1 - src/Resources/Locales/ru_RU.axaml | 1 - src/Resources/Locales/zh_CN.axaml | 2 +- src/Resources/Locales/zh_TW.axaml | 2 +- src/SourceGit.csproj | 3 +- src/ViewModels/Statistics.cs | 2 +- src/Views/Statistics.axaml | 18 ++- src/Views/Statistics.axaml.cs | 213 ------------------------------ 13 files changed, 147 insertions(+), 310 deletions(-) diff --git a/src/Commands/Statistics.cs b/src/Commands/Statistics.cs index 6b2296ca..8d426d09 100644 --- a/src/Commands/Statistics.cs +++ b/src/Commands/Statistics.cs @@ -6,21 +6,35 @@ namespace SourceGit.Commands { public Statistics(string repo) { - _statistics = new Models.Statistics(); - WorkingDirectory = repo; Context = repo; - Args = $"log --date-order --branches --remotes --since=\"{_statistics.Since()}\" --pretty=format:\"%ct$%an\""; + Args = $"log --date-order --branches --remotes -20000 --pretty=format:\"%ct$%an\""; } public Models.Statistics Result() { - Exec(); - _statistics.Complete(); - return _statistics; + var statistics = new Models.Statistics(); + var rs = ReadToEnd(); + if (!rs.IsSuccess) + return statistics; + + var start = 0; + var end = rs.StdOut.IndexOf('\n', start); + while (end > 0) + { + ParseLine(statistics, rs.StdOut.Substring(start, end - start)); + start = end + 1; + end = rs.StdOut.IndexOf('\n', start); + } + + if (start < rs.StdOut.Length) + ParseLine(statistics, rs.StdOut.Substring(start)); + + statistics.Complete(); + return statistics; } - protected override void OnReadline(string line) + private void ParseLine(Models.Statistics statistics, string line) { var dateEndIdx = line.IndexOf('$', StringComparison.Ordinal); if (dateEndIdx == -1) @@ -28,9 +42,7 @@ namespace SourceGit.Commands var dateStr = line.Substring(0, dateEndIdx); if (double.TryParse(dateStr, out var date)) - _statistics.AddCommit(line.Substring(dateEndIdx + 1), date); + statistics.AddCommit(line.Substring(dateEndIdx + 1), date); } - - private readonly Models.Statistics _statistics = null; } } diff --git a/src/Models/Statistics.cs b/src/Models/Statistics.cs index 21f1e65d..c3a3b3cf 100644 --- a/src/Models/Statistics.cs +++ b/src/Models/Statistics.cs @@ -1,122 +1,165 @@ using System; using System.Collections.Generic; +using LiveChartsCore; +using LiveChartsCore.Defaults; +using LiveChartsCore.SkiaSharpView; +using LiveChartsCore.SkiaSharpView.Painting; + +using SkiaSharp; + namespace SourceGit.Models { - public class StatisticsSample(string name) + public enum StaticsticsMode + { + All, + ThisMonth, + ThisWeek, + } + + public class StaticsticsAuthor(string name, int count) { public string Name { get; set; } = name; - public int Count { get; set; } = 0; + public int Count { get; set; } = count; + } + + public class StaticsticsSample(DateTime time, int count) + { + public DateTime Time { get; set; } = time; + public int Count { get; set; } = count; } public class StatisticsReport { + public static readonly string[] WEEKDAYS = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]; + public int Total { get; set; } = 0; - public List Samples { get; set; } = new List(); - public List ByAuthor { get; set; } = new List(); + public List Authors { get; set; } = new List(); + public List Series { get; set; } = new List(); + public List XAxes { get; set; } = new List(); + public List YAxes { get; set; } = new List(); - public void AddCommit(int index, string author) + public StatisticsReport(StaticsticsMode mode, DateTime start) { - Total++; - Samples[index].Count++; + _mode = mode; - if (_mapUsers.TryGetValue(author, out var value)) + YAxes = [new Axis() { + TextSize = 10, + MinLimit = 0, + SeparatorsPaint = new SolidColorPaint(SKColors.LightSlateGray) { StrokeThickness = .6f } + }]; + + if (mode == StaticsticsMode.ThisWeek) { - value.Count++; + for (int i = 0; i < 7; i++) + _mapSamples.Add(start.AddDays(i), 0); + + XAxes.Add(new DateTimeAxis(TimeSpan.FromDays(1), v => WEEKDAYS[(int)v.DayOfWeek]) { TextSize = 10 }); + } + else if (mode == StaticsticsMode.ThisMonth) + { + var now = DateTime.Now; + var maxDays = DateTime.DaysInMonth(now.Year, now.Month); + for (int i = 0; i < maxDays; i++) + _mapSamples.Add(start.AddDays(i), 0); + + XAxes.Add(new DateTimeAxis(TimeSpan.FromDays(1), v => $"{v:MM/dd}") { TextSize = 10 }); } else { - var sample = new StatisticsSample(author); - sample.Count++; - - _mapUsers.Add(author, sample); - ByAuthor.Add(sample); + XAxes.Add(new DateTimeAxis(TimeSpan.FromDays(365), v => $"{v:yyyy/MM}") { TextSize = 10 }); } } + public void AddCommit(DateTime time, string author) + { + Total++; + + var normalized = DateTime.MinValue; + if (_mode == StaticsticsMode.ThisWeek || _mode == StaticsticsMode.ThisMonth) + normalized = time.Date; + else + normalized = new DateTime(time.Year, time.Month, 1).ToLocalTime(); + + if (_mapSamples.TryGetValue(normalized, out var vs)) + _mapSamples[normalized] = vs + 1; + else + _mapSamples.Add(normalized, 1); + + if (_mapUsers.TryGetValue(author, out var vu)) + _mapUsers[author] = vu + 1; + else + _mapUsers.Add(author, 1); + } + public void Complete() { - ByAuthor.Sort((l, r) => r.Count - l.Count); + var samples = new List(); + foreach (var kv in _mapSamples) + samples.Add(new DateTimePoint(kv.Key, kv.Value)); + + Series.Add( + new LineSeries() + { + Values = samples, + Stroke = new SolidColorPaint(SKColors.Green) { StrokeThickness = 1 }, + GeometrySize = 8, + GeometryStroke = new SolidColorPaint(SKColors.Green) { StrokeThickness = 2 } + } + ); + + foreach (var kv in _mapUsers) + Authors.Add(new StaticsticsAuthor(kv.Key, kv.Value)); + + Authors.Sort((l, r) => r.Count - l.Count); + _mapUsers.Clear(); + _mapSamples.Clear(); } - private readonly Dictionary _mapUsers = new Dictionary(); + private StaticsticsMode _mode = StaticsticsMode.All; + private Dictionary _mapUsers = new Dictionary(); + private Dictionary _mapSamples = new Dictionary(); } public class Statistics { - public StatisticsReport Year { get; set; } = new StatisticsReport(); - public StatisticsReport Month { get; set; } = new StatisticsReport(); - public StatisticsReport Week { get; set; } = new StatisticsReport(); + public StatisticsReport All { get; set; } + public StatisticsReport Month { get; set; } + public StatisticsReport Week { get; set; } public Statistics() { - _today = DateTime.Today; - _thisWeekStart = _today.AddSeconds(-(int)_today.DayOfWeek * 3600 * 24 - _today.Hour * 3600 - _today.Minute * 60 - _today.Second); - _thisWeekEnd = _thisWeekStart.AddDays(7); + _today = DateTime.Now.ToLocalTime().Date; + _thisWeekStart = _today.AddSeconds(-(int)_today.DayOfWeek * 3600 * 24); + _thisMonthStart = _today.AddDays(1 - _today.Day); - for (int i = 0; i < 12; i++) - Year.Samples.Add(new StatisticsSample("")); - - var monthDays = DateTime.DaysInMonth(_today.Year, _today.Month); - for (int i = 0; i < monthDays; i++) - Month.Samples.Add(new StatisticsSample($"{i + 1}")); - - string[] weekDayNames = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]; - for (int i = 0; i < weekDayNames.Length; i++) - Week.Samples.Add(new StatisticsSample(weekDayNames[i])); - } - - public string Since() - { - return _today.AddMonths(-11).ToString("yyyy-MM-01 00:00:00"); + All = new StatisticsReport(StaticsticsMode.All, DateTime.MinValue); + Month = new StatisticsReport(StaticsticsMode.ThisMonth, _thisMonthStart); + Week = new StatisticsReport(StaticsticsMode.ThisWeek, _thisWeekStart); } public void AddCommit(string author, double timestamp) { var time = DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime(); - if (time.CompareTo(_thisWeekStart) >= 0 && time.CompareTo(_thisWeekEnd) < 0) - Week.AddCommit((int)time.DayOfWeek, author); + if (time >= _thisWeekStart) + Week.AddCommit(time, author); - if (time.Month == _today.Month) - Month.AddCommit(time.Day - 1, author); + if (time >= _thisMonthStart) + Month.AddCommit(time, author); - Year.AddCommit(time.Month - 1, author); + All.AddCommit(time, author); } public void Complete() { - Year.Complete(); + All.Complete(); Month.Complete(); Week.Complete(); - - // Year is start from 11 months ago from now. - var thisYear = _today.Year; - var start = _today.AddMonths(-11); - if (start.Month == 1) - { - for (int i = 0; i < 12; i++) - Year.Samples[i].Name = $"{thisYear}/{i + 1:00}"; - } - else - { - var lastYearIdx = start.Month - 1; - var lastYearMonths = Year.Samples.GetRange(lastYearIdx, 12 - lastYearIdx); - for (int i = 0; i < lastYearMonths.Count; i++) - lastYearMonths[i].Name = $"{thisYear - 1}/{lastYearIdx + i + 1:00}"; - - var thisYearMonths = Year.Samples.GetRange(0, lastYearIdx); - for (int i = 0; i < thisYearMonths.Count; i++) - thisYearMonths[i].Name = $"{thisYear}/{i + 1:00}"; - - Year.Samples.Clear(); - Year.Samples.AddRange(lastYearMonths); - Year.Samples.AddRange(thisYearMonths); - } } private readonly DateTime _today; + private readonly DateTime _thisMonthStart; private readonly DateTime _thisWeekStart; - private readonly DateTime _thisWeekEnd; } } diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index 8ec97547..90445ec9 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -567,7 +567,6 @@ COMMITTER MONAT WOCHE - JAHR COMMITS: AUTOREN: SUBMODULE diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index e9717845..cebbe194 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -571,9 +571,9 @@ COMMITTER MONTH WEEK - YEAR COMMITS: AUTHORS: + OVERVIEW SUBMODULES Add Submodule Copy Relative Path diff --git a/src/Resources/Locales/fr_FR.axaml b/src/Resources/Locales/fr_FR.axaml index 40df6d99..0db805ca 100644 --- a/src/Resources/Locales/fr_FR.axaml +++ b/src/Resources/Locales/fr_FR.axaml @@ -552,7 +552,6 @@ COMMITTER MONTH WEEK - YEAR COMMITS: AUTHORS: SUBMODULES diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml index 96cdda3e..6ff8e06c 100644 --- a/src/Resources/Locales/pt_BR.axaml +++ b/src/Resources/Locales/pt_BR.axaml @@ -545,7 +545,6 @@ COMMITTER MÊS SEMANA - ANO COMMITS: AUTORES: SUBMÓDULOS diff --git a/src/Resources/Locales/ru_RU.axaml b/src/Resources/Locales/ru_RU.axaml index 56b01b0b..4b3f6402 100644 --- a/src/Resources/Locales/ru_RU.axaml +++ b/src/Resources/Locales/ru_RU.axaml @@ -571,7 +571,6 @@ ФИКСАТОРЫ МЕСЯЦ НЕДЕЛЯ - ГОД ФИКСАЦИИ: АВТОРЫ: ПОДМОДУЛИ diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 6d3474b6..9989c30d 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -569,9 +569,9 @@ 提交者 本月 本周 - 最近一年 提交次数: 贡献者人数: + 总览 子模块 添加子模块 复制路径 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 7d31e33e..7ed253dc 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -574,9 +574,9 @@ 提交者 本月 本週 - 最近一年 提交次數: 貢獻者人數: + 總覽 子模組 新增子模組 複製路徑 diff --git a/src/SourceGit.csproj b/src/SourceGit.csproj index 53bc0176..036dcb57 100644 --- a/src/SourceGit.csproj +++ b/src/SourceGit.csproj @@ -45,7 +45,8 @@ - + + diff --git a/src/ViewModels/Statistics.cs b/src/ViewModels/Statistics.cs index 587b1b71..ce28cfea 100644 --- a/src/ViewModels/Statistics.cs +++ b/src/ViewModels/Statistics.cs @@ -50,7 +50,7 @@ namespace SourceGit.ViewModels switch (_selectedIndex) { case 0: - SelectedReport = _data.Year; + SelectedReport = _data.All; break; case 1: SelectedReport = _data.Month; diff --git a/src/Views/Statistics.axaml b/src/Views/Statistics.axaml index 4efb1e9d..a3364830 100644 --- a/src/Views/Statistics.axaml +++ b/src/Views/Statistics.axaml @@ -5,6 +5,7 @@ xmlns:m="using:SourceGit.Models" xmlns:vm="using:SourceGit.ViewModels" xmlns:v="using:SourceGit.Views" + xmlns:lvc="using:LiveChartsCore.SkiaSharpView.Avalonia" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="SourceGit.Views.Statistics" x:DataType="vm:Statistics" @@ -62,6 +63,7 @@ - diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index 786c8484..a897a5ba 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -19,31 +19,22 @@ - - - - + - + - - - - + - - + + @@ -138,6 +129,12 @@ Watermark="{DynamicResource Text.Repository.Filter}" Text="{Binding Filter, Mode=TwoWay}" VerticalContentAlignment="Center"> + + + + - + - + + IsVisible="{Binding SearchCommitFilterType, Converter={x:Static c:IntConverters.IsGreaterThanZero}}"> + + Date: Fri, 27 Sep 2024 17:14:29 +0800 Subject: [PATCH 0042/1497] code_style: remove unnecessary margins --- src/Views/Repository.axaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index a897a5ba..e629f869 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -21,14 +21,12 @@ From 2346082228e0ce4fafd9de862624bf47fdbd3b4c Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 27 Sep 2024 18:23:55 +0800 Subject: [PATCH 0043/1497] ux: style of tab switch in file histories view --- src/Resources/Styles.axaml | 7 ++- src/ViewModels/FileHistories.cs | 14 +++--- src/Views/FileHistories.axaml | 80 +++++---------------------------- src/Views/Repository.axaml | 2 + 4 files changed, 27 insertions(+), 76 deletions(-) diff --git a/src/Resources/Styles.axaml b/src/Resources/Styles.axaml index 13ccf0a5..06fa1651 100644 --- a/src/Resources/Styles.axaml +++ b/src/Resources/Styles.axaml @@ -963,7 +963,6 @@ + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index e629f869..3ed53102 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -21,12 +21,14 @@ From 9a8f4e20fbb66dbf14ed0f850649b7eafba04bc2 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 27 Sep 2024 22:21:56 +0800 Subject: [PATCH 0044/1497] =?UTF-8?q?feature:=20add=20hotkey=20`Alt+Enter/?= =?UTF-8?q?=E2=8C=A5+Enter`=20to=20auto=20stage=20all=20local=20changes=20?= =?UTF-8?q?and=20then=20commit=20(#521)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Commands/Command.cs | 6 ++---- src/Resources/Locales/en_US.axaml | 3 +++ src/Resources/Locales/zh_CN.axaml | 3 +++ src/Resources/Locales/zh_TW.axaml | 3 +++ src/ViewModels/WorkingCopy.cs | 22 +++++++++++---------- src/Views/Hotkeys.axaml | 13 ++++++++----- src/Views/WorkingCopy.axaml | 32 ++++++++++++++++++++++++++++--- src/Views/WorkingCopy.axaml.cs | 1 - 8 files changed, 60 insertions(+), 23 deletions(-) diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index 83a29ddf..4d5efaa4 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -126,10 +126,8 @@ namespace SourceGit.Commands } return false; } - else - { - return true; - } + + return true; } public ReadToEndResult ReadToEnd() diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 1d6563b9..275ddf5a 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -327,6 +327,7 @@ REPOSITORY Commit staged changes Commit and push staged changes + Stage all changes and commit Discard selected changes Dashboard mode (Default) Force to reload this repository @@ -622,6 +623,8 @@ COMMIT & PUSH Template/Histories CTRL + Enter + Use 'Alt+Enter' to stage all changes and commit + Use '⌥+Enter' to stage all changes and commit CONFLICTS DETECTED FILE CONFLICTS ARE RESOLVED INCLUDE UNTRACKED FILES diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 7915cc53..2d5cc4b8 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -330,6 +330,7 @@ 仓库页面快捷键 提交暂存区更改 提交暂存区更改并推送 + 自动暂存全部变更并提交 丢弃选中的更改 切换左边栏为分支/标签等显示模式(默认) 重新加载仓库状态 @@ -620,6 +621,8 @@ 提交并推送 历史输入/模板 CTRL + Enter + 使用 Alt+Enter 自动暂存所有变更并提交 + 使用 ⌥+Enter 自动暂存所有变更并提交 检测到冲突 文件冲突已解决 显示未跟踪文件 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index cb8fc19d..1c07df18 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -330,6 +330,7 @@ 存放庫頁面快速鍵 提交暫存區變更 提交暫存區變更並推送 + 自動暫存全部變更並提交 捨棄選取的變更 切換左邊欄為分支/標籤等顯示模式 (預設) 強制重新載入存放庫 @@ -625,6 +626,8 @@ 提交並推送 歷史輸入/範本 CTRL + Enter + 使用 Alt+Enter 自動暫存全部變更並提交 + 使用 ⌥+Enter 自動暫存全部變更並提交 檢測到衝突 檔案衝突已解決 顯示未追蹤檔案 diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 2dad3fc2..74ff3e0e 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -240,11 +240,6 @@ namespace SourceGit.ViewModels _cached = changes; _count = _cached.Count; - var unstaged = new List(); - var staged = new List(); - var selectedUnstaged = new List(); - var selectedStaged = new List(); - var lastSelectedUnstaged = new HashSet(); var lastSelectedStaged = new HashSet(); if (_selectedUnstaged != null && _selectedUnstaged.Count > 0) @@ -258,6 +253,8 @@ namespace SourceGit.ViewModels lastSelectedStaged.Add(c.Path); } + var unstaged = new List(); + var selectedUnstaged = new List(); var hasConflict = false; foreach (var c in changes) { @@ -271,7 +268,8 @@ namespace SourceGit.ViewModels } } - staged = GetStagedChanges(); + var staged = GetStagedChanges(); + var selectedStaged = new List(); foreach (var c in staged) { if (lastSelectedStaged.Contains(c.Path)) @@ -418,12 +416,17 @@ namespace SourceGit.ViewModels public void Commit() { - DoCommit(false); + DoCommit(AutoStageBeforeCommit, false); + } + + public void CommitWithAutoStage() + { + DoCommit(true, false); } public void CommitWithPush() { - DoCommit(true); + DoCommit(AutoStageBeforeCommit, true); } public ContextMenu CreateContextMenuForUnstagedChanges() @@ -1276,7 +1279,7 @@ namespace SourceGit.ViewModels _repo.SetWatcherEnabled(true); } - private void DoCommit(bool autoPush) + private void DoCommit(bool autoStage, bool autoPush) { if (!PopupHost.CanCreatePopup()) { @@ -1290,7 +1293,6 @@ namespace SourceGit.ViewModels return; } - var autoStage = AutoStageBeforeCommit; if (!_useAmend) { if (autoStage) diff --git a/src/Views/Hotkeys.axaml b/src/Views/Hotkeys.axaml index cd7f9c4a..45fc1c08 100644 --- a/src/Views/Hotkeys.axaml +++ b/src/Views/Hotkeys.axaml @@ -78,7 +78,7 @@ FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Increase}}" Margin="0,8"/> - + @@ -102,12 +102,15 @@ + + + - - + + - - + + - + + + + - + - + From e945367b281dc3b66582416901afbe3c757d4016 Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 29 Sep 2024 12:11:09 +0800 Subject: [PATCH 0055/1497] enhance: avoid re-calcuting highlight chunk when move mouse from stage/unstage buttons to text area --- src/Views/TextDiffView.axaml.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index 02564428..4de04eaf 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -513,7 +513,17 @@ namespace SourceGit.Views private void OnTextViewPointerEntered(object sender, PointerEventArgs e) { if (EnableChunkSelection && sender is TextView view) + { + var chunk = SelectedChunk; + if (chunk != null) + { + var rect = new Rect(0, chunk.Y, Bounds.Width, chunk.Height); + if (rect.Contains(e.GetPosition(this))) + return; + } + UpdateSelectedChunk(e.GetPosition(view).Y + view.VerticalOffset); + } } private void OnTextViewPointerMoved(object sender, PointerEventArgs e) From d5671ea8df65c44cd1d90d5a261a500a66f08d4c Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 29 Sep 2024 13:48:48 +0800 Subject: [PATCH 0056/1497] enhance: only re-calculate highlight chunk when it is needed --- src/Views/TextDiffView.axaml.cs | 60 +++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index 4de04eaf..6ae637fc 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -437,8 +437,8 @@ namespace SourceGit.Views base.OnLoaded(e); TextArea.TextView.ContextRequested += OnTextViewContextRequested; - TextArea.TextView.PointerEntered += OnTextViewPointerEntered; - TextArea.TextView.PointerMoved += OnTextViewPointerMoved; + TextArea.TextView.PointerEntered += OnTextViewPointerChanged; + TextArea.TextView.PointerMoved += OnTextViewPointerChanged; TextArea.TextView.PointerWheelChanged += OnTextViewPointerWheelChanged; UpdateTextMate(); @@ -449,8 +449,8 @@ namespace SourceGit.Views base.OnUnloaded(e); TextArea.TextView.ContextRequested -= OnTextViewContextRequested; - TextArea.TextView.PointerEntered -= OnTextViewPointerEntered; - TextArea.TextView.PointerMoved -= OnTextViewPointerMoved; + TextArea.TextView.PointerEntered -= OnTextViewPointerChanged; + TextArea.TextView.PointerMoved -= OnTextViewPointerChanged; TextArea.TextView.PointerWheelChanged -= OnTextViewPointerWheelChanged; if (_textMate != null) @@ -510,35 +510,43 @@ namespace SourceGit.Views e.Handled = true; } - private void OnTextViewPointerEntered(object sender, PointerEventArgs e) + private void OnTextViewPointerChanged(object sender, PointerEventArgs e) { if (EnableChunkSelection && sender is TextView view) { - var chunk = SelectedChunk; - if (chunk != null) + var selection = TextArea.Selection; + if (selection == null || selection.IsEmpty) { - var rect = new Rect(0, chunk.Y, Bounds.Width, chunk.Height); - if (rect.Contains(e.GetPosition(this))) - return; + if (_lastSelectStart != _lastSelectEnd) + { + _lastSelectStart = TextLocation.Empty; + _lastSelectEnd = TextLocation.Empty; + } + + var chunk = SelectedChunk; + if (chunk != null) + { + var rect = new Rect(0, chunk.Y, Bounds.Width, chunk.Height); + if (rect.Contains(e.GetPosition(this))) + return; + } + + UpdateSelectedChunk(e.GetPosition(view).Y + view.VerticalOffset); + return; } - UpdateSelectedChunk(e.GetPosition(view).Y + view.VerticalOffset); - } - } - - private void OnTextViewPointerMoved(object sender, PointerEventArgs e) - { - if (EnableChunkSelection && sender is TextView view) - { - var chunk = SelectedChunk; - if (chunk != null) + var start = selection.StartPosition.Location; + var end = selection.EndPosition.Location; + if (_lastSelectStart != start || _lastSelectEnd != end) { - var rect = new Rect(0, chunk.Y, Bounds.Width, chunk.Height); - if (rect.Contains(e.GetPosition(this))) - return; + _lastSelectStart = start; + _lastSelectEnd = end; + UpdateSelectedChunk(e.GetPosition(view).Y + view.VerticalOffset); + return; } - UpdateSelectedChunk(e.GetPosition(view).Y + view.VerticalOffset); + if (SelectedChunk == null) + UpdateSelectedChunk(e.GetPosition(view).Y + view.VerticalOffset); } } @@ -657,7 +665,9 @@ namespace SourceGit.Views } private TextMate.Installation _textMate = null; - protected LineStyleTransformer _lineStyleTransformer = null; + private TextLocation _lastSelectStart = TextLocation.Empty; + private TextLocation _lastSelectEnd = TextLocation.Empty; + private LineStyleTransformer _lineStyleTransformer = null; } public class CombinedTextDiffPresenter : ThemedTextDiffPresenter From 3af30f54b6f4fb5e76c9d0990126ee130c857206 Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 29 Sep 2024 14:16:42 +0800 Subject: [PATCH 0057/1497] enhance: avoid flicker at the first time clicking on text diff view --- src/Views/TextDiffView.axaml.cs | 53 +++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index 6ae637fc..dd3471bf 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -694,18 +694,6 @@ namespace SourceGit.Views return 0; } - protected override void OnApplyTemplate(TemplateAppliedEventArgs e) - { - base.OnApplyTemplate(e); - - var scroller = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer"); - if (scroller != null) - { - scroller.Bind(ScrollViewer.OffsetProperty, new Binding("SyncScrollOffset", BindingMode.TwoWay)); - scroller.GotFocus += (_, _) => TrySetChunk(null); - } - } - public override void UpdateSelectedChunk(double y) { var diff = DataContext as Models.TextDiff; @@ -822,6 +810,27 @@ namespace SourceGit.Views } } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + + var scroller = this.FindDescendantOfType(); + if (scroller != null) + { + scroller.Bind(ScrollViewer.OffsetProperty, new Binding("SyncScrollOffset", BindingMode.TwoWay)); + scroller.GotFocus += OnTextViewScrollGotFocus; + } + } + + protected override void OnUnloaded(RoutedEventArgs e) + { + var scroller = this.FindDescendantOfType(); + if (scroller != null) + scroller.GotFocus -= OnTextViewScrollGotFocus; + + base.OnUnloaded(e); + } + protected override void OnDataContextChanged(EventArgs e) { base.OnDataContextChanged(e); @@ -853,6 +862,16 @@ namespace SourceGit.Views GC.Collect(); } + + private void OnTextViewScrollGotFocus(object sender, GotFocusEventArgs e) + { + if (EnableChunkSelection && sender is ScrollViewer viewer) + { + var area = viewer.FindDescendantOfType