Skip to content

Commit 9fa4dcd

Browse files
committed
refactor: commit message editor
- Use a custom `CommitMessageTextBox` based on `TextBox` instead of `AvaloniaEdit.Editor` to solve the issue of IME support - Use `DirectProperty` instead of `StyledProperty` to improve performance (we do not need to style these values)
1 parent ff2aa0e commit 9fa4dcd

3 files changed

Lines changed: 441 additions & 288 deletions

File tree

src/Views/CommitMessageToolBox.axaml

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,69 @@
1313
BorderBrush="{DynamicResource Brush.Border2}"
1414
CornerRadius="4">
1515
<Grid RowDefinitions="*,1,24">
16-
<v:CommitMessageTextEditor Grid.Row="0"
17-
x:Name="Editor"
18-
CommitMessage="{Binding #ThisControl.CommitMessage, Mode=TwoWay}"
19-
Placeholder="{DynamicResource Text.CommitMessageTextBox.Placeholder}"
20-
SubjectLineBrush="{DynamicResource Brush.Border2}"
21-
SubjectGuideLength="{Binding Source={x:Static vm:Preferences.Instance}, Path=SubjectGuideLength, Mode=OneWay}"
22-
Foreground="{DynamicResource Brush.FG1}"
23-
FontFamily="{DynamicResource Fonts.Default}"
24-
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize, Mode=OneWay}"/>
16+
<Grid Grid.Row="0">
17+
<v:CommitMessageTextBox x:Name="Editor"
18+
Classes="no_border"
19+
CornerRadius="4,4,0,0"
20+
Background="Transparent"
21+
Text="{Binding #ThisControl.CommitMessage, Mode=TwoWay}"
22+
PlaceholderText="{DynamicResource Text.CommitMessageTextBox.Placeholder}"
23+
SubjectGuideLength="{Binding Source={x:Static vm:Preferences.Instance}, Path=SubjectGuideLength, Mode=OneWay}"
24+
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize, Mode=OneWay}"/>
25+
26+
<v:CommitMessageSubjectEndIndicator LineBrush="{DynamicResource Brush.Border2}"
27+
FontFamily="{DynamicResource Fonts.Default}"
28+
SubjectEndY="{Binding #Editor.SubjectEndY, Mode=OneWay}"/>
29+
30+
<Popup PlacementTarget="#Editor"
31+
Placement="AnchorAndGravity"
32+
PlacementAnchor="TopLeft"
33+
PlacementGravity="BottomRight"
34+
HorizontalOffset="-4" VerticalOffset="{Binding #Editor.SuggestionPopupY, Mode=OneWay}">
35+
<Popup.IsOpen>
36+
<MultiBinding Converter="{x:Static BoolConverters.And}">
37+
<Binding Path="#Editor.Suggestions" Converter="{x:Static c:ListConverters.IsNotNullOrEmpty}"/>
38+
<Binding Path="$parent[Window].IsActive"/>
39+
</MultiBinding>
40+
</Popup.IsOpen>
41+
42+
<Border Margin="8" VerticalAlignment="Top" Effect="drop-shadow(0 0 8 #80000000)">
43+
<Border Background="{DynamicResource Brush.Popup}" CornerRadius="4" Padding="4" BorderThickness="0.65" BorderBrush="{DynamicResource Brush.Border0}">
44+
<v:ListBoxEx x:Name="SuggestionBox"
45+
Background="Transparent"
46+
SelectionMode="Single"
47+
ItemsSource="{Binding #Editor.Suggestions, Mode=OneWay}"
48+
SelectedIndex="{Binding #Editor.SelectedSuggestionIndex, Mode=TwoWay}"
49+
MaxHeight="400"
50+
Focusable="False">
51+
<ListBox.Styles>
52+
<Style Selector="ListBoxItem">
53+
<Setter Property="Padding" Value="0"/>
54+
<Setter Property="MinWidth" Value="140"/>
55+
<Setter Property="MinHeight" Value="26"/>
56+
<Setter Property="CornerRadius" Value="4"/>
57+
<Setter Property="Focusable" Value="False"/>
58+
</Style>
59+
</ListBox.Styles>
60+
61+
<ListBox.ItemsPanel>
62+
<ItemsPanelTemplate>
63+
<StackPanel Orientation="Vertical" Spacing="2"/>
64+
</ItemsPanelTemplate>
65+
</ListBox.ItemsPanel>
66+
67+
<ListBox.ItemTemplate>
68+
<DataTemplate DataType="v:CommitMessageTextBoxSuggestion">
69+
<Border Padding="8,0" Height="26" Background="Transparent" Tapped="OnSuggestionTapped">
70+
<TextBlock Text="{Binding Text, Mode=OneWay}" VerticalAlignment="Center"/>
71+
</Border>
72+
</DataTemplate>
73+
</ListBox.ItemTemplate>
74+
</v:ListBoxEx>
75+
</Border>
76+
</Border>
77+
</Popup>
78+
</Grid>
2579

2680
<Rectangle Grid.Row="1"
2781
Height="1"
@@ -95,15 +149,15 @@
95149
<TextBlock Margin="8,0,0,0"
96150
FontSize="11"
97151
Text="{Binding #Editor.SubjectLength}"
98-
Foreground="{Binding #Editor.IsSubjectWarningIconVisible, Converter={x:Static c:BoolConverters.IsWarningToBrush}, Mode=OneWay}"
152+
Foreground="{Binding #Editor.WarnSubjectLength, Converter={x:Static c:BoolConverters.IsWarningToBrush}, Mode=OneWay}"
99153
VerticalAlignment="Center"/>
100154
<TextBlock FontSize="11"
101155
Text="/"
102156
VerticalAlignment="Center"/>
103157
<TextBlock FontSize="11"
104158
Text="{Binding #Editor.SubjectGuideLength, Mode=OneWay}"
105159
VerticalAlignment="Center"/>
106-
<Path Width="10" Height="10" Margin="4,0,0,0" Data="{StaticResource Icons.Error}" Fill="DarkGoldenrod" IsVisible="{Binding #Editor.IsSubjectWarningIconVisible, Mode=OneWay}"/>
160+
<Path Width="10" Height="10" Margin="4,0,0,0" Data="{StaticResource Icons.Error}" Fill="DarkGoldenrod" IsVisible="{Binding #Editor.WarnSubjectLength, Mode=OneWay}"/>
107161
</StackPanel>
108162
</Grid>
109163
</Border>

0 commit comments

Comments
 (0)