feature: auto-open commit message editor

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-07-14 16:25:02 +08:00
parent 2d3e450afb
commit f487990bc0
3 changed files with 23 additions and 11 deletions

View File

@@ -17,23 +17,14 @@ namespace SourceGit.Views
{
_onSave = msg => File.WriteAllText(file, msg);
_shouldExitApp = true;
var content = File.ReadAllText(file).ReplaceLineEndings("\n").Trim();
var parts = content.Split('\n', 2);
Editor.SubjectEditor.Text = parts[0];
if (parts.Length > 1)
Editor.DescriptionEditor.Text = parts[1];
Editor.Text = File.ReadAllText(file).ReplaceLineEndings("\n").Trim();
}
public void AsBuiltin(string msg, Action<string> onSave)
{
_onSave = onSave;
_shouldExitApp = false;
var parts = msg.Split('\n', 2);
Editor.SubjectEditor.Text = parts[0];
if (parts.Length > 1)
Editor.DescriptionEditor.Text = parts[1];
Editor.Text = msg.Trim();
}
protected override void OnClosed(EventArgs e)

View File

@@ -58,6 +58,7 @@
ItemsSource="{Binding Items}"
SelectionMode="Single"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
SelectionChanged="OnRowsSelectionChanged"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto"
Grid.IsSharedSizeScope="True">

View File

@@ -1,4 +1,5 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
@@ -99,6 +100,23 @@ namespace SourceGit.Views
Close();
}
private void OnRowsSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!_firstSelectionChangedHandled &&
sender is InteractiveRebaseListBox list &&
list.SelectedItem is ViewModels.InteractiveRebaseItem item)
{
_firstSelectionChangedHandled = true;
if (item.Action == Models.InteractiveRebaseAction.Reword)
{
var dialog = new CommitMessageEditor();
dialog.AsBuiltin(item.FullMessage, msg => item.FullMessage = msg);
dialog.ShowDialog(this);
}
}
}
private void OnSetupRowHeaderDragDrop(object sender, RoutedEventArgs e)
{
if (sender is Border border)
@@ -242,5 +260,7 @@ namespace SourceGit.Views
flyout.Items.Add(menuItem);
}
private bool _firstSelectionChangedHandled = false;
}
}