Skip to content

Commit f8debc0

Browse files
committed
feature: configurable description guide length for commit messages
Add a `Description Guide Length` preference next to the existing subject guide length. The commit message editor now: - shows a `DESCRIPTION n/limit` counter (longest body line) with the same warning color and icon used for the subject - draws the vertical column guide at the configured length instead of a hardcoded 80 columns Since the working copy commit box, the reword editor in interactive rebase, the commit template editor and the standalone editor mode all share `CommitMessageToolBox`, the guide applies everywhere a message is written. The default stays at 80 so existing users see no change. Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
1 parent 18d8d7f commit f8debc0

7 files changed

Lines changed: 131 additions & 11 deletions

File tree

‎src/Resources/Locales/en_US.axaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
<x:String x:Key="Text.CommitDetail.Info.SHA" xml:space="preserve">SHA</x:String>
205205
<x:String x:Key="Text.CommitDetail.Info.Signer" xml:space="preserve">Signer:</x:String>
206206
<x:String x:Key="Text.CommitDetail.Info.WebLinks" xml:space="preserve">Open in Browser</x:String>
207+
<x:String x:Key="Text.CommitMessageTextBox.DescriptionCount" xml:space="preserve">DESCRIPTION</x:String>
207208
<x:String x:Key="Text.CommitMessageTextBox.Placeholder" xml:space="preserve">Enter commit message. Please use an empty-line to separate subject and description!</x:String>
208209
<x:String x:Key="Text.CommitMessageTextBox.SubjectCount" xml:space="preserve">SUBJECT</x:String>
209210
<x:String x:Key="Text.Compare" xml:space="preserve">Compare</x:String>
@@ -696,6 +697,7 @@
696697
<x:String x:Key="Text.Preferences.General" xml:space="preserve">GENERAL</x:String>
697698
<x:String x:Key="Text.Preferences.General.Check4UpdatesOnStartup" xml:space="preserve">Check for updates on startup</x:String>
698699
<x:String x:Key="Text.Preferences.General.DateFormat" xml:space="preserve">Date Format</x:String>
700+
<x:String x:Key="Text.Preferences.General.DescriptionGuideLength" xml:space="preserve">Description Guide Length</x:String>
699701
<x:String x:Key="Text.Preferences.General.EnableCompactFolders" xml:space="preserve">Enable compact folders in changes tree</x:String>
700702
<x:String x:Key="Text.Preferences.General.Locale" xml:space="preserve">Language</x:String>
701703
<x:String x:Key="Text.Preferences.General.MaxHistoryCommits" xml:space="preserve">History Commits</x:String>

‎src/Resources/Locales/zh_CN.axaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@
208208
<x:String x:Key="Text.CommitDetail.Info.SHA" xml:space="preserve">提交指纹</x:String>
209209
<x:String x:Key="Text.CommitDetail.Info.Signer" xml:space="preserve">签名者 :</x:String>
210210
<x:String x:Key="Text.CommitDetail.Info.WebLinks" xml:space="preserve">浏览器中查看</x:String>
211+
<x:String x:Key="Text.CommitMessageTextBox.DescriptionCount" xml:space="preserve">描述</x:String>
211212
<x:String x:Key="Text.CommitMessageTextBox.Placeholder" xml:space="preserve">请输入提交的信息。注意:主题与具体描述中间需要空白行分隔!</x:String>
212213
<x:String x:Key="Text.CommitMessageTextBox.SubjectCount" xml:space="preserve">主题</x:String>
213214
<x:String x:Key="Text.Compare" xml:space="preserve">比较</x:String>
@@ -700,6 +701,7 @@
700701
<x:String x:Key="Text.Preferences.General" xml:space="preserve">通用配置</x:String>
701702
<x:String x:Key="Text.Preferences.General.Check4UpdatesOnStartup" xml:space="preserve">启动时检测软件更新</x:String>
702703
<x:String x:Key="Text.Preferences.General.DateFormat" xml:space="preserve">日期时间格式</x:String>
704+
<x:String x:Key="Text.Preferences.General.DescriptionGuideLength" xml:space="preserve">DESCRIPTION字数检测</x:String>
703705
<x:String x:Key="Text.Preferences.General.EnableCompactFolders" xml:space="preserve">在变更列表树中启用紧凑文件夹模式</x:String>
704706
<x:String x:Key="Text.Preferences.General.Locale" xml:space="preserve">显示语言</x:String>
705707
<x:String x:Key="Text.Preferences.General.MaxHistoryCommits" xml:space="preserve">最大历史提交数</x:String>

‎src/Resources/Locales/zh_TW.axaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
<x:String x:Key="Text.CommitDetail.Info.SHA" xml:space="preserve">提交編號</x:String>
199199
<x:String x:Key="Text.CommitDetail.Info.Signer" xml:space="preserve">簽署人:</x:String>
200200
<x:String x:Key="Text.CommitDetail.Info.WebLinks" xml:space="preserve">在瀏覽器中檢視</x:String>
201+
<x:String x:Key="Text.CommitMessageTextBox.DescriptionCount" xml:space="preserve">描述</x:String>
201202
<x:String x:Key="Text.CommitMessageTextBox.Placeholder" xml:space="preserve">請輸入提交訊息,標題與詳細描述之間請使用單行空白區隔。</x:String>
202203
<x:String x:Key="Text.CommitMessageTextBox.SubjectCount" xml:space="preserve">標題</x:String>
203204
<x:String x:Key="Text.Compare" xml:space="preserve">比較</x:String>
@@ -690,6 +691,7 @@
690691
<x:String x:Key="Text.Preferences.General" xml:space="preserve">一般設定</x:String>
691692
<x:String x:Key="Text.Preferences.General.Check4UpdatesOnStartup" xml:space="preserve">啟動時檢查軟體更新</x:String>
692693
<x:String x:Key="Text.Preferences.General.DateFormat" xml:space="preserve">日期時間格式</x:String>
694+
<x:String x:Key="Text.Preferences.General.DescriptionGuideLength" xml:space="preserve">提交描述字數偵測</x:String>
693695
<x:String x:Key="Text.Preferences.General.EnableCompactFolders" xml:space="preserve">在樹狀變更目錄中啟用密集資料夾模式</x:String>
694696
<x:String x:Key="Text.Preferences.General.Locale" xml:space="preserve">顯示語言</x:String>
695697
<x:String x:Key="Text.Preferences.General.MaxHistoryCommits" xml:space="preserve">最大歷史提交數</x:String>

‎src/ViewModels/Preferences.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ public int SubjectGuideLength
141141
set => SetProperty(ref _subjectGuideLength, value);
142142
}
143143

144+
public int DescriptionGuideLength
145+
{
146+
get => _descriptionGuideLength;
147+
set => SetProperty(ref _descriptionGuideLength, value);
148+
}
149+
144150
public int DateTimeFormat
145151
{
146152
get => Models.DateTimeFormat.ActiveIndex;
@@ -820,6 +826,7 @@ private bool RemoveInvalidRepositoriesRecursive(List<RepositoryNode> collection)
820826

821827
private int _maxHistoryCommits = 20000;
822828
private int _subjectGuideLength = 50;
829+
private int _descriptionGuideLength = 80;
823830
private bool _useFixedTabWidth = true;
824831
private bool _useAutoHideScrollBars = true;
825832
private bool _useGitHubStyleAvatar = true;

‎src/Views/CommitMessageToolBox.axaml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Text="{Binding #ThisControl.CommitMessage, Mode=TwoWay}"
2222
Watermark="{DynamicResource Text.CommitMessageTextBox.Placeholder}"
2323
SubjectGuideLength="{Binding Source={x:Static vm:Preferences.Instance}, Path=SubjectGuideLength, Mode=OneWay}"
24+
DescriptionGuideLength="{Binding Source={x:Static vm:Preferences.Instance}, Path=DescriptionGuideLength, Mode=OneWay}"
2425
GuideLineBrush="{DynamicResource Brush.Border2}"
2526
FontFamily="{DynamicResource Fonts.Monospace}">
2627
<v:CommitMessageTextBox.Styles>
@@ -138,6 +139,23 @@
138139
Text="{Binding #Editor.SubjectGuideLength, Mode=OneWay}"
139140
VerticalAlignment="Center"/>
140141
<Path Width="10" Height="10" Margin="4,0,0,0" Data="{StaticResource Icons.Error}" Fill="DarkGoldenrod" IsVisible="{Binding #Editor.WarnSubjectLength, Mode=OneWay}"/>
142+
<TextBlock Classes="info_label"
143+
Margin="12,0,0,0"
144+
FontSize="13"
145+
HorizontalAlignment="Left"
146+
Text="{DynamicResource Text.CommitMessageTextBox.DescriptionCount}"/>
147+
<TextBlock Margin="8,0,0,0"
148+
FontSize="11"
149+
Text="{Binding #Editor.DescriptionLength}"
150+
Foreground="{Binding #Editor.WarnDescriptionLength, Converter={x:Static c:BoolConverters.IsWarningToBrush}, Mode=OneWay}"
151+
VerticalAlignment="Center"/>
152+
<TextBlock FontSize="11"
153+
Text="/"
154+
VerticalAlignment="Center"/>
155+
<TextBlock FontSize="11"
156+
Text="{Binding #Editor.DescriptionGuideLength, Mode=OneWay}"
157+
VerticalAlignment="Center"/>
158+
<Path Width="10" Height="10" Margin="4,0,0,0" Data="{StaticResource Icons.Error}" Fill="DarkGoldenrod" IsVisible="{Binding #Editor.WarnDescriptionLength, Mode=OneWay}"/>
141159
</StackPanel>
142160
</Grid>
143161
</Border>

‎src/Views/CommitMessageToolBox.axaml.cs‎

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,40 @@ public bool WarnSubjectLength
8181
set => SetAndRaise(WarnSubjectLengthProperty, ref _warnSubjectLen, value);
8282
}
8383

84+
public static readonly DirectProperty<CommitMessageTextBox, int> DescriptionLengthProperty =
85+
AvaloniaProperty.RegisterDirect<CommitMessageTextBox, int>(
86+
nameof(DescriptionLength),
87+
static o => o.DescriptionLength);
88+
89+
public int DescriptionLength
90+
{
91+
get => _descriptionLen;
92+
set => SetAndRaise(DescriptionLengthProperty, ref _descriptionLen, value);
93+
}
94+
95+
public static readonly DirectProperty<CommitMessageTextBox, int> DescriptionGuideLengthProperty =
96+
AvaloniaProperty.RegisterDirect<CommitMessageTextBox, int>(
97+
nameof(DescriptionGuideLength),
98+
static o => o.DescriptionGuideLength,
99+
static (o, v) => o.DescriptionGuideLength = v);
100+
101+
public int DescriptionGuideLength
102+
{
103+
get => _descriptionGuideLen;
104+
set => SetAndRaise(DescriptionGuideLengthProperty, ref _descriptionGuideLen, value);
105+
}
106+
107+
public static readonly DirectProperty<CommitMessageTextBox, bool> WarnDescriptionLengthProperty =
108+
AvaloniaProperty.RegisterDirect<CommitMessageTextBox, bool>(
109+
nameof(WarnDescriptionLength),
110+
static o => o.WarnDescriptionLength);
111+
112+
public bool WarnDescriptionLength
113+
{
114+
get => _warnDescriptionLen;
115+
set => SetAndRaise(WarnDescriptionLengthProperty, ref _warnDescriptionLen, value);
116+
}
117+
84118
public static readonly DirectProperty<CommitMessageTextBox, List<CommitMessageTextBoxSuggestion>> SuggestionsProperty =
85119
AvaloniaProperty.RegisterDirect<CommitMessageTextBox, List<CommitMessageTextBoxSuggestion>>(
86120
nameof(Suggestions),
@@ -173,7 +207,7 @@ public override void Render(DrawingContext context)
173207
new Typeface(font),
174208
ViewModels.Preferences.Instance.DefaultFontSize,
175209
Brushes.White);
176-
var columnGuideX = columnTest.WidthIncludingTrailingWhitespace * 80 + 5.5;
210+
var columnGuideX = columnTest.WidthIncludingTrailingWhitespace * _descriptionGuideLen + 5.5;
177211
context.DrawLine(pen, new Point(columnGuideX, Math.Max(0, y)), new Point(columnGuideX, Bounds.Height));
178212
}
179213

@@ -209,10 +243,12 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
209243
{
210244
_subjectEndCharIdx = -1;
211245
SubjectLength = 0;
246+
DescriptionLength = 0;
212247
return;
213248
}
214249

215250
var subjectLen = 0;
251+
var descriptionLen = 0;
216252
var lastNonLineBreakCharIdx = 0;
217253
var lastLineStart = 0;
218254
for (var i = 0; i < text.Length; i++)
@@ -226,7 +262,10 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
226262
if (string.IsNullOrWhiteSpace(line))
227263
{
228264
if (subjectLen > 0)
265+
{
266+
descriptionLen = GetMaxLineLength(text, lastLineStart);
229267
break;
268+
}
230269

231270
continue;
232271
}
@@ -253,12 +292,18 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
253292
}
254293

255294
SubjectLength = subjectLen;
295+
DescriptionLength = descriptionLen;
256296
_subjectEndCharIdx = lastNonLineBreakCharIdx;
257297
}
258298
else if (change.Property == SubjectLengthProperty || change.Property == SubjectGuideLengthProperty)
259299
{
260300
WarnSubjectLength = _subjectLen > _subjectGuideLen;
261301
}
302+
else if (change.Property == DescriptionLengthProperty || change.Property == DescriptionGuideLengthProperty)
303+
{
304+
WarnDescriptionLength = _descriptionLen > _descriptionGuideLen;
305+
InvalidateVisual();
306+
}
262307
else if (change.Property == SubjectEndYProperty)
263308
{
264309
InvalidateVisual();
@@ -377,6 +422,28 @@ protected override void OnKeyDown(KeyEventArgs e)
377422
base.OnKeyDown(e);
378423
}
379424

425+
private static int GetMaxLineLength(string text, int start)
426+
{
427+
var maxLen = 0;
428+
var lineStart = start;
429+
for (var i = start; i <= text.Length; i++)
430+
{
431+
if (i == text.Length || text[i] == '\n')
432+
{
433+
var lineLen = i - lineStart;
434+
while (lineLen > 0 && char.IsWhiteSpace(text[lineStart + lineLen - 1]))
435+
lineLen--;
436+
437+
if (lineLen > maxLen)
438+
maxLen = lineLen;
439+
440+
lineStart = i + 1;
441+
}
442+
}
443+
444+
return maxLen;
445+
}
446+
380447
private void OnLayoutUpdated(object sender, EventArgs e)
381448
{
382449
if (_textPresenter == null || !IsEffectivelyVisible)
@@ -447,6 +514,9 @@ private void OnLayoutUpdated(object sender, EventArgs e)
447514
private int _subjectEndCharIdx = -1;
448515
private double _subjectEndY = 0;
449516
private bool _warnSubjectLen = false;
517+
private int _descriptionLen = 0;
518+
private int _descriptionGuideLen = 80;
519+
private bool _warnDescriptionLen = false;
450520
private int _suggestionMatchStartIdx = -1;
451521
private List<CommitMessageTextBoxSuggestion> _suggestions = null;
452522
private int _selectedSuggestionIdx = 0;

‎src/Views/Preferences.axaml‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<TabItem.Header>
4848
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preferences.General}"/>
4949
</TabItem.Header>
50-
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
50+
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
5151
<TextBlock Grid.Row="0" Grid.Column="0"
5252
Text="{DynamicResource Text.Preferences.General.Locale}"
5353
HorizontalAlignment="Right"
@@ -123,10 +123,29 @@
123123
</Grid>
124124

125125
<TextBlock Grid.Row="4" Grid.Column="0"
126-
Text="{DynamicResource Text.Preferences.General.MaxHistoryCommits}"
126+
Text="{DynamicResource Text.Preferences.General.DescriptionGuideLength}"
127127
HorizontalAlignment="Right"
128128
Margin="0,0,16,0"/>
129129
<Grid Grid.Row="4" Grid.Column="1" ColumnDefinitions="*,64">
130+
<Slider Grid.Column="0"
131+
Minimum="50" Maximum="200"
132+
TickPlacement="BottomRight" TickFrequency="10"
133+
IsSnapToTickEnabled="False"
134+
VerticalAlignment="Center"
135+
Foreground="{DynamicResource Brush.Border1}"
136+
Value="{Binding DescriptionGuideLength, Mode=TwoWay}"/>
137+
138+
<TextBlock Grid.Column="1"
139+
HorizontalAlignment="Right" VerticalAlignment="Center"
140+
Foreground="{DynamicResource Brush.FG1}"
141+
Text="{Binding DescriptionGuideLength, Mode=OneWay}"/>
142+
</Grid>
143+
144+
<TextBlock Grid.Row="5" Grid.Column="0"
145+
Text="{DynamicResource Text.Preferences.General.MaxHistoryCommits}"
146+
HorizontalAlignment="Right"
147+
Margin="0,0,16,0"/>
148+
<Grid Grid.Row="5" Grid.Column="1" ColumnDefinitions="*,64">
130149
<Slider Grid.Column="0"
131150
Minimum="5000" Maximum="100000"
132151
TickPlacement="BottomRight" TickFrequency="5000"
@@ -141,42 +160,42 @@
141160
Text="{Binding MaxHistoryCommits}"/>
142161
</Grid>
143162

144-
<CheckBox Grid.Row="5" Grid.Column="1"
163+
<CheckBox Grid.Row="6" Grid.Column="1"
145164
Height="32"
146165
Content="{DynamicResource Text.Preferences.General.ShowChangesPageByDefault}"
147166
IsChecked="{Binding ShowLocalChangesByDefault, Mode=TwoWay}"/>
148167

149-
<CheckBox Grid.Row="6" Grid.Column="1"
168+
<CheckBox Grid.Row="7" Grid.Column="1"
150169
Height="32"
151170
Content="{DynamicResource Text.Preferences.General.ShowChangesTabInCommitDetailByDefault}"
152171
IsChecked="{Binding ShowChangesInCommitDetailByDefault, Mode=TwoWay}"/>
153172

154-
<CheckBox Grid.Row="7" Grid.Column="1"
173+
<CheckBox Grid.Row="8" Grid.Column="1"
155174
Height="32"
156175
Content="{DynamicResource Text.Preferences.General.ShowTagsInGraph}"
157176
IsChecked="{Binding ShowTagsInGraph, Mode=TwoWay}"/>
158177

159-
<CheckBox Grid.Row="8" Grid.Column="1"
178+
<CheckBox Grid.Row="9" Grid.Column="1"
160179
Height="32"
161180
Content="{DynamicResource Text.Preferences.General.ShowRelativeTimeInGraph}"
162181
IsChecked="{Binding DisplayTimeAsPeriodInHistories, Mode=TwoWay}"/>
163182

164-
<CheckBox Grid.Row="9" Grid.Column="1"
183+
<CheckBox Grid.Row="10" Grid.Column="1"
165184
Height="32"
166185
Content="{DynamicResource Text.Preferences.General.UseCompactBranchNames}"
167186
IsChecked="{Binding UseCompactBranchNamesInGraph, Mode=TwoWay}"/>
168187

169-
<CheckBox Grid.Row="10" Grid.Column="1"
188+
<CheckBox Grid.Row="11" Grid.Column="1"
170189
Height="32"
171190
Content="{DynamicResource Text.Preferences.General.EnableCompactFolders}"
172191
IsChecked="{Binding EnableCompactFoldersInChangesTree, Mode=TwoWay}"/>
173192

174-
<CheckBox Grid.Row="11" Grid.Column="1"
193+
<CheckBox Grid.Row="12" Grid.Column="1"
175194
Height="32"
176195
Content="{DynamicResource Text.Preferences.General.UseGitHubStyleAvatar}"
177196
IsChecked="{Binding UseGitHubStyleAvatar, Mode=TwoWay}"/>
178197

179-
<CheckBox Grid.Row="12" Grid.Column="1"
198+
<CheckBox Grid.Row="13" Grid.Column="1"
180199
Height="32"
181200
Content="{DynamicResource Text.Preferences.General.Check4UpdatesOnStartup}"
182201
IsVisible="{x:Static s:App.IsCheckForUpdateCommandVisible}"

0 commit comments

Comments
 (0)