|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.IO; |
| 4 | +using System.Text; |
4 | 5 |
|
5 | 6 | using Avalonia.Controls; |
6 | 7 | using Avalonia.Input; |
@@ -117,15 +118,31 @@ private async void OnUnstagedKeyDown(object _, KeyEventArgs e) |
117 | 118 | Native.OS.OpenWithDefaultEditor(fullpath); |
118 | 119 | e.Handled = true; |
119 | 120 | } |
120 | | - else if (e.Key is Key.C && e.KeyModifiers.HasFlag(cmdKey) && vm.SelectedUnstaged is { Count: 1 }) |
| 121 | + else if (e.Key is Key.C && e.KeyModifiers.HasFlag(cmdKey)) |
121 | 122 | { |
122 | | - var change = vm.SelectedUnstaged[0]; |
123 | | - if (e.KeyModifiers.HasFlag(KeyModifiers.Shift)) |
124 | | - await this.CopyTextAsync(Native.OS.GetAbsPath(vm.Repository.FullPath, change.Path)); |
125 | | - else |
126 | | - await this.CopyTextAsync(change.Path); |
| 123 | + var builder = new StringBuilder(); |
| 124 | + var copyAbsPath = e.KeyModifiers.HasFlag(KeyModifiers.Shift); |
| 125 | + var container = UnstagedChangesView.FindDescendantOfType<ChangeCollectionContainer>(); |
| 126 | + if (container is { SelectedItems.Count: 1, SelectedItem: ViewModels.ChangeTreeNode { IsFolder: true } node }) |
| 127 | + { |
| 128 | + builder.Append(copyAbsPath ? Native.OS.GetAbsPath(vm.Repository.FullPath, node.FullPath) : node.FullPath); |
| 129 | + } |
| 130 | + else if (vm.SelectedUnstaged is { Count: 1 }) |
| 131 | + { |
| 132 | + var change = vm.SelectedUnstaged[0]; |
| 133 | + builder.Append(copyAbsPath ? Native.OS.GetAbsPath(vm.Repository.FullPath, change.Path) : change.Path); |
| 134 | + } |
| 135 | + else if (vm.SelectedUnstaged is { Count: > 0 }) |
| 136 | + { |
| 137 | + foreach (var c in vm.SelectedUnstaged) |
| 138 | + builder.AppendLine(copyAbsPath ? Native.OS.GetAbsPath(vm.Repository.FullPath, c.Path) : c.Path); |
| 139 | + } |
127 | 140 |
|
128 | | - e.Handled = true; |
| 141 | + if (builder.Length > 0) |
| 142 | + { |
| 143 | + await this.CopyTextAsync(builder.ToString()); |
| 144 | + e.Handled = true; |
| 145 | + } |
129 | 146 | } |
130 | 147 | else if (e.Key is Key.F && e.KeyModifiers == cmdKey) |
131 | 148 | { |
@@ -156,15 +173,31 @@ private async void OnStagedKeyDown(object _, KeyEventArgs e) |
156 | 173 | Native.OS.OpenWithDefaultEditor(fullpath); |
157 | 174 | e.Handled = true; |
158 | 175 | } |
159 | | - else if (e.Key is Key.C && e.KeyModifiers.HasFlag(cmdKey) && vm.SelectedStaged is { Count: 1 }) |
| 176 | + else if (e.Key is Key.C && e.KeyModifiers.HasFlag(cmdKey)) |
160 | 177 | { |
161 | | - var change = vm.SelectedStaged[0]; |
162 | | - if (e.KeyModifiers.HasFlag(KeyModifiers.Shift)) |
163 | | - await this.CopyTextAsync(Native.OS.GetAbsPath(vm.Repository.FullPath, change.Path)); |
164 | | - else |
165 | | - await this.CopyTextAsync(change.Path); |
| 178 | + var builder = new StringBuilder(); |
| 179 | + var copyAbsPath = e.KeyModifiers.HasFlag(KeyModifiers.Shift); |
| 180 | + var container = StagedChangesView.FindDescendantOfType<ChangeCollectionContainer>(); |
| 181 | + if (container is { SelectedItems.Count: 1, SelectedItem: ViewModels.ChangeTreeNode { IsFolder: true } node }) |
| 182 | + { |
| 183 | + builder.Append(copyAbsPath ? Native.OS.GetAbsPath(vm.Repository.FullPath, node.FullPath) : node.FullPath); |
| 184 | + } |
| 185 | + else if (vm.SelectedStaged is { Count: 1 }) |
| 186 | + { |
| 187 | + var change = vm.SelectedStaged[0]; |
| 188 | + builder.Append(copyAbsPath ? Native.OS.GetAbsPath(vm.Repository.FullPath, change.Path) : change.Path); |
| 189 | + } |
| 190 | + else if (vm.SelectedStaged is { Count: > 0 }) |
| 191 | + { |
| 192 | + foreach (var c in vm.SelectedStaged) |
| 193 | + builder.AppendLine(copyAbsPath ? Native.OS.GetAbsPath(vm.Repository.FullPath, c.Path) : c.Path); |
| 194 | + } |
166 | 195 |
|
167 | | - e.Handled = true; |
| 196 | + if (builder.Length > 0) |
| 197 | + { |
| 198 | + await this.CopyTextAsync(builder.ToString()); |
| 199 | + e.Handled = true; |
| 200 | + } |
168 | 201 | } |
169 | 202 | else if (e.Key is Key.F && e.KeyModifiers == cmdKey) |
170 | 203 | { |
|
0 commit comments