Merge pull request #4966 from OmrSi/break-at-first-space-patch

Work on Break at first space from position
This commit is contained in:
Nikolaj Olsson 2021-04-08 22:46:22 +02:00 committed by GitHub
commit 374c11f7df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9697,30 +9697,12 @@ namespace Nikse.SubtitleEdit.Forms
}
else if (e.KeyData == _shortcuts.MainTextBoxBreakAtCursorPosition)
{
var text = Utilities.ReSplit(textBoxListViewText.Text, textBoxListViewText.SelectionStart);
if (text != textBoxListViewText.Text)
{
MakeHistoryForUndo(string.Format(_language.BeforeReplace, LanguageSettings.Current.Settings.MainTextBoxAutoBreakFromPos));
textBoxListViewText.Text = text;
var lines = textBoxListViewText.Text.SplitToLines();
if (lines.Count > 0)
{
textBoxListViewText.SelectionStart = lines[0].Length;
}
}
AutoBreakAtFirstSpaceFromPos(textBoxListViewText);
e.SuppressKeyPress = true;
}
else if (e.KeyData == _shortcuts.MainTextBoxBreakAtCursorPositionAndGoToNext)
{
var text = Utilities.ReSplit(textBoxListViewText.Text, textBoxListViewText.SelectionStart);
if (text != textBoxListViewText.Text)
{
MakeHistoryForUndo(string.Format(_language.BeforeReplace, LanguageSettings.Current.Settings.MainTextBoxAutoBreakFromPosAndGoToNext));
textBoxListViewText.Text = text;
ButtonNextClick(null, null);
}
AutoBreakAtFirstSpaceFromPos(textBoxListViewText, true);
e.SuppressKeyPress = true;
}
else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.I)
@ -12102,6 +12084,29 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private void AutoBreakAtFirstSpaceFromPos(SETextBox textBox, bool goToNext = false)
{
var text = Utilities.ReSplit(textBox.Text, textBox.SelectionStart);
if (text != textBox.Text)
{
MakeHistoryForUndo(string.Format(_language.BeforeX, LanguageSettings.Current.Settings.MainTextBoxAutoBreakFromPos));
textBox.Text = text;
if (goToNext)
{
ButtonNextClick(null, null);
}
else
{
var lines = textBox.Text.SplitToLines();
if (lines.Count > 0)
{
textBox.SelectionStart = lines[0].Length;
}
}
}
}
private void SwitchView(Control view)
{
if (InSourceView)
@ -24895,19 +24900,12 @@ namespace Nikse.SubtitleEdit.Forms
}
else if (e.KeyData == _shortcuts.MainTextBoxBreakAtCursorPosition)
{
textBoxListViewTextOriginal.Text = Utilities.ReSplit(textBoxListViewTextOriginal.Text, textBoxListViewTextOriginal.SelectionStart);
var lines = textBoxListViewTextOriginal.Text.SplitToLines();
if (lines.Count > 0)
{
textBoxListViewTextOriginal.SelectionStart = lines[0].Length;
}
AutoBreakAtFirstSpaceFromPos(textBoxListViewTextOriginal);
e.SuppressKeyPress = true;
}
else if (e.KeyData == _shortcuts.MainTextBoxBreakAtCursorPositionAndGoToNext)
{
textBoxListViewText.Text = Utilities.ReSplit(textBoxListViewText.Text, textBoxListViewText.SelectionStart);
ButtonNextClick(null, null);
AutoBreakAtFirstSpaceFromPos(textBoxListViewTextOriginal, true);
e.SuppressKeyPress = true;
}
else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.I)