From d2a005c53249843c66e85f03645dded4ffb829af Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 30 Sep 2024 11:34:09 +0800 Subject: [PATCH] feature: add a button in diff view to ignore all whitespace changes (--ignore-all-space) --- src/Commands/Diff.cs | 8 ++++++-- src/Resources/Icons.axaml | 3 ++- src/Resources/Locales/de_DE.axaml | 4 ++-- src/Resources/Locales/en_US.axaml | 5 +++-- src/Resources/Locales/pt_BR.axaml | 4 ++-- src/Resources/Locales/ru_RU.axaml | 4 ++-- src/Resources/Locales/zh_CN.axaml | 5 +++-- src/Resources/Locales/zh_TW.axaml | 5 +++-- src/ViewModels/DiffContext.cs | 14 +++++++++++++- src/Views/DiffView.axaml | 9 ++++++++- 10 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/Commands/Diff.cs b/src/Commands/Diff.cs index 0f2ee626..e3185781 100644 --- a/src/Commands/Diff.cs +++ b/src/Commands/Diff.cs @@ -12,7 +12,7 @@ namespace SourceGit.Commands private const string PREFIX_LFS_DEL = "-version https://git-lfs.github.com/spec/"; private const string PREFIX_LFS_MODIFY = " version https://git-lfs.github.com/spec/"; - public Diff(string repo, Models.DiffOption opt, int unified) + public Diff(string repo, Models.DiffOption opt, int unified, bool ignoreWhitespace) { _result.TextDiff = new Models.TextDiff() { @@ -22,7 +22,11 @@ namespace SourceGit.Commands WorkingDirectory = repo; Context = repo; - Args = $"diff --ignore-cr-at-eol --unified={unified} {opt}"; + + if (ignoreWhitespace) + Args = $"diff --ignore-cr-at-eol --ignore-all-space --unified={unified} {opt}"; + else + Args = $"diff --ignore-cr-at-eol --unified={unified} {opt}"; } public Models.DiffResult Result() diff --git a/src/Resources/Icons.axaml b/src/Resources/Icons.axaml index 8650e068..fab32275 100644 --- a/src/Resources/Icons.axaml +++ b/src/Resources/Icons.axaml @@ -50,6 +50,7 @@ M884 159l-18-18a43 43 0 00-38-12l-235 43a166 166 0 00-101 60L400 349a128 128 0 00-148 47l-120 171a21 21 0 005 29l17 12a128 128 0 00178-32l27-38 124 124-38 27a128 128 0 00-32 178l12 17a21 21 0 0029 5l171-120a128 128 0 0047-148l117-92A166 166 0 00853 431l43-235a43 43 0 00-12-38zm-177 249a64 64 0 110-90 64 64 0 010 90zm-373 312a21 21 0 010 30l-139 139a21 21 0 01-30 0l-30-30a21 21 0 010-30l139-139a21 21 0 0130 0z M590 74 859 342V876c0 38-31 68-68 68H233c-38 0-68-31-68-68V142c0-38 31-68 68-68h357zm-12 28H233a40 40 0 00-40 38L193 142v734a40 40 0 0038 40L233 916h558a40 40 0 0040-38L831 876V354L578 102zM855 371h-215c-46 0-83-36-84-82l0-2V74h28v213c0 30 24 54 54 55l2 0h215v28zM57 489m28 0 853 0q28 0 28 28l0 284q0 28-28 28l-853 0q-28 0-28-28l0-284q0-28 28-28ZM157 717c15 0 29-6 37-13v-51h-41v22h17v18c-2 2-6 3-10 3-21 0-30-13-30-34 0-21 12-34 28-34 9 0 15 4 20 9l14-17C184 610 172 603 156 603c-29 0-54 21-54 57 0 37 24 56 54 56zM245 711v-108h-34v108h34zm69 0v-86H341V603H262v22h28V711h24zM393 711v-108h-34v108h34zm66 6c15 0 29-6 37-13v-51h-41v22h17v18c-2 2-6 3-10 3-21 0-30-13-30-34 0-21 12-34 28-34 9 0 15 4 20 9l14-17C485 610 474 603 458 603c-29 0-54 21-54 57 0 37 24 56 54 56zm88-6v-36c0-13-2-28-3-40h1l10 24 25 52H603v-108h-23v36c0 13 2 28 3 40h-1l-10-24L548 603H523v108h23zM677 717c30 0 51-22 51-57 0-36-21-56-51-56-30 0-51 20-51 56 0 36 21 57 51 57zm3-23c-16 0-26-12-26-32 0-19 10-31 26-31 16 0 26 11 26 31S696 694 680 694zm93 17v-38h13l21 38H836l-25-43c12-5 19-15 19-31 0-26-20-34-44-34H745v108h27zm16-51H774v-34h15c16 0 25 4 25 16s-9 18-25 18zM922 711v-22h-43v-23h35v-22h-35V625h41V603H853v108h68z M30 271l241 0 0-241-241 0 0 241zM392 271l241 0 0-241-241 0 0 241zM753 30l0 241 241 0 0-241-241 0zM30 632l241 0 0-241-241 0 0 241zM392 632l241 0 0-241-241 0 0 241zM753 632l241 0 0-241-241 0 0 241zM30 994l241 0 0-241-241 0 0 241zM392 994l241 0 0-241-241 0 0 241zM753 994l241 0 0-241-241 0 0 241z + M416 64H768v64h-64v704h64v64H448v-64h64V512H416a224 224 0 1 1 0-448zM576 832h64V128H576v704zM416 128H512v320H416a160 160 0 0 1 0-320z M24 512A488 488 0 01512 24A488 488 0 011000 512A488 488 0 01512 1000A488 488 0 0124 512zm447-325v327L243 619l51 111 300-138V187H471z M832 64h128v278l-128-146V64zm64 448L512 73 128 512H0L448 0h128l448 512h-128zm0 83V1024H640V704c0-35-29-64-64-64h-128a64 64 0 00-64 64v320H128V595l384-424 384 424z M512 0C229 0 0 229 0 512c0 283 229 512 512 512s512-229 512-512c0-283-229-512-512-512zm0 958C266 958 66 758 66 512S266 66 512 66 958 266 958 512 758 958 512 958zM192 416h96a32 32 0 0032-32v-32a32 32 0 00-32-32H192a32 32 0 00-32 32v32a32 32 0 0032 32zM384 416h96a32 32 0 0032-32v-32a32 32 0 00-32-32h-96a32 32 0 00-32 32v32a32 32 0 0032 32zM576 416h96a32 32 0 0032-32v-32a32 32 0 00-32-32h-96a32 32 0 00-32 32v32a32 32 0 0032 32zM832 320h-64a32 32 0 00-32 32v128h-160a32 32 0 00-32 32v32a32 32 0 0032 32h256a32 32 0 0032-32v-192a32 32 0 00-32-32zM320 544v-32a32 32 0 00-32-32H192a32 32 0 00-32 32v32a32 32 0 0032 32h96a32 32 0 0032-32zM384 576h96a32 32 0 0032-32v-32a32 32 0 00-32-32h-96a32 32 0 00-32 32v32a32 32 0 0032 32zM800 640H256a32 32 0 00-32 32v32a32 32 0 0032 32h544a32 32 0 0032-32v-32a32 32 0 00-32-32z @@ -118,7 +119,7 @@ M832 464H332V240c0-31 25-56 56-56h248c31 0 56 25 56 56v68c0 4 4 8 8 8h56c4 0 8-4 8-8v-68c0-71-57-128-128-128H388c-71 0-128 57-128 128v224h-68c-18 0-32 14-32 32v384c0 18 14 32 32 32h640c18 0 32-14 32-32V496c0-18-14-32-32-32zM540 701v53c0 4-4 8-8 8h-40c-4 0-8-4-8-8v-53c-12-9-20-23-20-39 0-27 22-48 48-48s48 22 48 48c0 16-8 30-20 39z M170 831l343-342L855 831l105-105-448-448L64 726 170 831z M812 864h-29V654c0-21-11-40-28-52l-133-88 134-89c18-12 28-31 28-52V164h28c18 0 32-14 32-32s-14-32-32-32H212c-18 0-32 14-32 32s14 32 32 32h30v210c0 21 11 40 28 52l133 88-134 89c-18 12-28 31-28 52V864H212c-18 0-32 14-32 32s14 32 32 32h600c18 0 32-14 32-32s-14-32-32-32zM441 566c18-12 28-31 28-52s-11-40-28-52L306 373V164h414v209l-136 90c-18 12-28 31-28 52 0 21 11 40 28 52l135 89V695c-9-7-20-13-32-19-30-15-93-41-176-41-63 0-125 14-175 38-12 6-22 12-31 18v-36l136-90z - M416 64H768v64h-64v704h64v64H448v-64h64V512H416a224 224 0 1 1 0-448zM576 832h64V128H576v704zM416 128H512v320H416a160 160 0 0 1 0-320z + M0 512M1024 512M512 0M512 1024M762 412v100h-500v-100h-150v200h800v-200h-150z M519 459 222 162a37 37 0 10-52 52l297 297L169 809a37 37 0 1052 52l297-297 297 297a37 37 0 1052-52l-297-297 297-297a37 37 0 10-52-52L519 459z M1024 565V459H0V565H1024ZM512 0M512 1024 M153 154h768v768h-768v-768zm64 64v640h640v-640h-640z diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index eac15bca..95c3f07f 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -210,17 +210,17 @@ Nächste Änderung KEINE ÄNDERUNG ODER NUR ZEILEN-ENDE ÄNDERUNGEN Vorherige Änderung + Zeige versteckte Symbole Nebeneinander SUBMODUL NEU + Seiten wechseln Syntax Hervorhebung Zeilenumbruch Öffne in Merge Tool Weniger Zeilen anzeigen Mehr Zeilen anzeigen WÄHLE EINE DATEI AUS UM ÄNDERUNGEN ANZUZEIGEN - Zeige versteckte Symbole - Seiten wechseln Öffne in Merge Tool Änderungen verwerfen Alle Änderungen in der Arbeitskopie. diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index ca320f4d..434b3b1a 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -203,21 +203,22 @@ OLD Copy File Mode Changed + Ignore Whitespace Change LFS OBJECT CHANGE Next Difference NO CHANGES OR ONLY EOL CHANGES Previous Difference + Show hidden symbols Side-By-Side Diff SUBMODULE NEW + Swap Syntax Highlighting Line Word Wrap Open in Merge Tool Decrease Number of Visible Lines Increase Number of Visible Lines SELECT FILE TO VIEW CHANGES - Show hidden symbols - Swap Open in Merge Tool Discard Changes All local changes in working copy. diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml index 90341b44..b0505014 100644 --- a/src/Resources/Locales/pt_BR.axaml +++ b/src/Resources/Locales/pt_BR.axaml @@ -199,17 +199,17 @@ Próxima Diferença SEM MUDANÇAS OU APENAS MUDANÇAS DE EOL Diferença Anterior + Mostrar símbolos ocultos Diferença Lado a Lado SUBMÓDULO NOVO + Trocar Realce de Sintaxe Quebra de Linha Abrir na Ferramenta de Mesclagem Diminuir Número de Linhas Visíveis Aumentar Número de Linhas Visíveis SELECIONE O ARQUIVO PARA VISUALIZAR AS MUDANÇAS - Mostrar símbolos ocultos - Trocar Abrir na Ferramenta de Mesclagem Descartar Alterações Todas as alterações locais na cópia de trabalho. diff --git a/src/Resources/Locales/ru_RU.axaml b/src/Resources/Locales/ru_RU.axaml index edfc8b08..948905eb 100644 --- a/src/Resources/Locales/ru_RU.axaml +++ b/src/Resources/Locales/ru_RU.axaml @@ -206,6 +206,7 @@ СТАРЫЙ Копировать Режим файла изменён + Показать скрытые символы ИЗМЕНЕНИЕ ОБЪЕКТА ХБФ Следующее различие НИКАКИХ ИЗМЕНЕНИЙ ИЛИ МЕНЯЕТСЯ ТОЛЬКО EOL @@ -213,14 +214,13 @@ Различие бок о бок ПОДМОДУЛЬ НОВЫЙ + Обмен Подсветка синтаксиса Перенос слов в строке Открыть в инструменте слияния Уменьшить количество видимых линий Увеличить количество видимых линий ВЫБРАТЬ ФАЙЛ ДЛЯ ПРОСМОТРА ИЗМЕНЕНИЙ - Показать скрытые символы - Обмен Открыть в инструменте слияния Отклонить изменения Все локальные изменения в рабочей копии. diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 5b753a08..f26d3e3c 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -206,21 +206,22 @@ 原始大小 复制 文件权限已变化 + 忽略空白符号变化 LFS对象变更 下一个差异 没有变更或仅有换行符差异 上一个差异 + 显示隐藏符号 分列对比 子模块 新增 + 交换比对双方 语法高亮 自动换行 使用外部合并工具查看 减少可见的行数 增加可见的行数 请选择需要对比的文件 - 显示隐藏符号 - 交换比对双方 使用外部比对工具查看 放弃更改确认 所有本地址未提交的修改。 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 733b3f39..ffc46895 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -206,21 +206,22 @@ 原始大小 複製 檔案權限已變更 + 忽略空白符號變化 LFS 物件變更 下一個差異 沒有變更或僅有換行字元差異 上一個差異 + 顯示隱藏符號 並排對比 子模組 新增 + 交換比對雙方 語法上色 自動換行 使用外部合併工具檢視 減少可見的行數 增加可見的行數 請選擇需要對比的檔案 - 顯示隱藏符號 - 交換比對雙方 使用外部比對工具檢視 捨棄變更 所有本機未提交的變更。 diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index 08499d89..1a48c8e0 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -17,6 +17,16 @@ namespace SourceGit.ViewModels get => _title; } + public bool IgnoreWhitespace + { + get => _ignoreWhitespace; + set + { + if (SetProperty(ref _ignoreWhitespace, value)) + LoadDiffContent(); + } + } + public string FileModeChange { get => _fileModeChange; @@ -57,6 +67,7 @@ namespace SourceGit.ViewModels _isTextDiff = previous._isTextDiff; _content = previous._content; _unifiedLines = previous._unifiedLines; + _ignoreWhitespace = previous._ignoreWhitespace; } if (string.IsNullOrEmpty(_option.OrgPath) || _option.OrgPath == "/dev/null") @@ -98,7 +109,7 @@ namespace SourceGit.ViewModels Task.Run(() => { - var latest = new Commands.Diff(_repo, _option, _unifiedLines).Result(); + var latest = new Commands.Diff(_repo, _option, _unifiedLines, _ignoreWhitespace).Result(); var rs = null as object; if (latest.TextDiff != null) @@ -237,6 +248,7 @@ namespace SourceGit.ViewModels private int _unifiedLines = 4; private bool _isLoading = true; private bool _isTextDiff = false; + private bool _ignoreWhitespace = false; private object _content = null; } } diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index 07ed7a77..8ccc25bb 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -77,12 +77,19 @@ + + + + - +