mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Re-add auto wrap
This commit is contained in:
parent
fc9bca851c
commit
5d84058517
@ -9228,17 +9228,15 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
textBoxListViewText.TextChanged -= TextBoxListViewTextTextChanged;
|
textBoxListViewText.TextChanged -= TextBoxListViewTextTextChanged;
|
||||||
if (_doAutoBreakOnTextChanged)
|
if (_doAutoBreakOnTextChanged)
|
||||||
{
|
{
|
||||||
//TODO: fix wrap
|
UiUtil.CheckAutoWrap(textBoxListViewText, new KeyEventArgs(Keys.None), Utilities.GetNumberOfLines(textBoxListViewText.Text));
|
||||||
//UiUtil.CheckAutoWrap(textBoxListViewText, new KeyEventArgs(Keys.None), Utilities.GetNumberOfLines(textBoxListViewText.Text));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update _subtitle + listview
|
// update _subtitle + listview
|
||||||
string text = textBoxListViewText.Text.TrimEnd();
|
string text = textBoxListViewText.Text.TrimEnd();
|
||||||
if (ContainsNonStandardNewLines(text))
|
if (ContainsNonStandardNewLines(text))
|
||||||
{
|
{
|
||||||
//var lines = text.SplitToLines();
|
var lines = text.SplitToLines();
|
||||||
//text = string.Join(Environment.NewLine, lines);
|
text = string.Join(Environment.NewLine, lines);
|
||||||
//textBoxListViewText.Text = text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx < 0 || idx >= _subtitle.Paragraphs.Count)
|
if (idx < 0 || idx >= _subtitle.Paragraphs.Count)
|
||||||
@ -9320,8 +9318,7 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
}
|
}
|
||||||
|
|
||||||
int numberOfNewLines = Utilities.GetNumberOfLines(textBoxListViewTextAlternate.Text);
|
int numberOfNewLines = Utilities.GetNumberOfLines(textBoxListViewTextAlternate.Text);
|
||||||
//TODO:Fix autowrap
|
UiUtil.CheckAutoWrap(textBoxListViewTextAlternate, new KeyEventArgs(Keys.None), numberOfNewLines);
|
||||||
//UiUtil.CheckAutoWrap(textBoxListViewTextAlternate, new KeyEventArgs(Keys.None), numberOfNewLines);
|
|
||||||
|
|
||||||
// update _subtitle + listview
|
// update _subtitle + listview
|
||||||
string text = textBoxListViewTextAlternate.Text.TrimEnd();
|
string text = textBoxListViewTextAlternate.Text.TrimEnd();
|
||||||
@ -9329,7 +9326,6 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
{
|
{
|
||||||
var lines = text.SplitToLines();
|
var lines = text.SplitToLines();
|
||||||
text = string.Join(Environment.NewLine, lines);
|
text = string.Join(Environment.NewLine, lines);
|
||||||
textBoxListViewTextAlternate.Text = text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
original.Text = text;
|
original.Text = text;
|
||||||
|
@ -315,6 +315,52 @@ namespace Nikse.SubtitleEdit.Logic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CheckAutoWrap(RichTextBox textBox, KeyEventArgs e, int numberOfNewLines)
|
||||||
|
{
|
||||||
|
// Do not auto-break lines more than 1 line.
|
||||||
|
if (numberOfNewLines != 1 || !Configuration.Settings.General.AutoWrapLineWhileTyping)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int length = HtmlUtil.RemoveHtmlTags(textBox.Text, true).Length;
|
||||||
|
if (e.Modifiers == Keys.None && e.KeyCode != Keys.Enter && length > Configuration.Settings.General.SubtitleLineMaximumLength)
|
||||||
|
{
|
||||||
|
string newText;
|
||||||
|
if (length > Configuration.Settings.General.SubtitleLineMaximumLength + 30)
|
||||||
|
{
|
||||||
|
newText = Utilities.AutoBreakLine(textBox.Text);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int lastSpace = textBox.Text.LastIndexOf(' ');
|
||||||
|
if (lastSpace > 0)
|
||||||
|
{
|
||||||
|
newText = textBox.Text.Remove(lastSpace, 1).Insert(lastSpace, Environment.NewLine);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newText = textBox.Text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int autoBreakIndex = newText.IndexOf(Environment.NewLine, StringComparison.Ordinal);
|
||||||
|
if (autoBreakIndex > 0)
|
||||||
|
{
|
||||||
|
int selectionStart = textBox.SelectionStart;
|
||||||
|
textBox.Text = newText;
|
||||||
|
if (selectionStart > autoBreakIndex)
|
||||||
|
{
|
||||||
|
selectionStart += Environment.NewLine.Length - 1;
|
||||||
|
}
|
||||||
|
if (selectionStart >= 0)
|
||||||
|
{
|
||||||
|
textBox.SelectionStart = selectionStart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly Dictionary<string, Keys> AllKeys = new Dictionary<string, Keys>();
|
private static readonly Dictionary<string, Keys> AllKeys = new Dictionary<string, Keys>();
|
||||||
private static Keys _helpKeys;
|
private static Keys _helpKeys;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user