mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
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:
parent
4998f14547
commit
254eac11a1
1 changed files with 36 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue