enhance: paste text on subject

* for single line text, all text will be pasted in subject text box
* if paste in the middle of subject content, multi-line text will be transformed into single line text by `ReplaceLineEndings(" ")`
* if paste in the end of subject content, multi-line text will be split into two parts.
    - first line will be pasted in the subject box
    - remains will be pasted in the start of description box
This commit is contained in:
leo 2024-07-01 21:02:01 +08:00
parent 4998f14547
commit 254eac11a1
No known key found for this signature in database

View file

@ -20,6 +20,11 @@ namespace SourceGit.Views
protected override Type StyleKeyOverride => typeof(TextBox);
public void Paste(string text)
{
OnTextInput(new TextInputEventArgs() { Text = text });
}
protected override void OnKeyDown(KeyEventArgs e)
{
var dump = new KeyEventArgs()
@ -112,7 +117,7 @@ namespace SourceGit.Views
}
}
private void OnSubjectTextBoxPreviewKeyDown(object sender, KeyEventArgs e)
private async void OnSubjectTextBoxPreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter || (e.Key == Key.Right && SubjectEditor.CaretIndex == Subject.Length))
{
@ -120,6 +125,36 @@ namespace SourceGit.Views
DescriptionEditor.CaretIndex = 0;
e.Handled = true;
}
else if (e.Key == Key.V && ((OperatingSystem.IsMacOS() && e.KeyModifiers == KeyModifiers.Meta) || (!OperatingSystem.IsMacOS() && e.KeyModifiers == KeyModifiers.Control)))
{
var text = await App.GetClipboardTextAsync();
text = text.Trim();
if (!string.IsNullOrEmpty(text))
{
if (SubjectEditor.CaretIndex == Subject.Length)
{
var idx = text.IndexOf('\n');
if (idx == -1)
{
SubjectEditor.Paste(text);
}
else
{
SubjectEditor.Paste(text.Substring(0, idx));
DescriptionEditor.Focus();
DescriptionEditor.CaretIndex = 0;
DescriptionEditor.Paste(text.Substring(idx + 1) + "\n");
}
}
else
{
SubjectEditor.Paste(text.ReplaceLineEndings(" "));
}
}
e.Handled = true;
}
}
private void OnDescriptionTextBoxPreviewKeyDown(object sender, KeyEventArgs e)