Add new shortcut for split + auto-br - thx oep42 :)

Work on #6673
This commit is contained in:
niksedk 2023-03-07 21:51:24 +01:00
parent 0cdd435037
commit 560f8feef9
8 changed files with 43 additions and 4 deletions

View File

@ -1369,6 +1369,7 @@ To use an API key, go to "Options -> Settings -> Tools" to enter your Goog
<Paste>Paste</Paste>
<Delete>Delete</Delete>
<SplitLineAtCursorPosition>Split line at cursor position</SplitLineAtCursorPosition>
<SplitLineAtCursorPositionAndAutoBr>Split line at cursor position and auto-break</SplitLineAtCursorPositionAndAutoBr>
<SplitLineAtCursorAndWaveformPosition>Split line at cursor/video position</SplitLineAtCursorAndWaveformPosition>
<AutoDurationCurrentLine>Auto duration (current line)</AutoDurationCurrentLine>
<SelectAll>Select all</SelectAll>

View File

@ -2438,6 +2438,7 @@ $HorzAlign = Center
public string MainListViewSortByStyle { get; set; }
public string MainListViewRemoveTimeCodes { get; set; }
public string MainTextBoxSplitAtCursor { get; set; }
public string MainTextBoxSplitAtCursorAndAutoBr { get; set; }
public string MainTextBoxSplitAtCursorAndVideoPos { get; set; }
public string MainTextBoxSplitSelectedLineBilingual { get; set; }
public string MainTextBoxMoveLastWordDown { get; set; }
@ -9304,6 +9305,12 @@ $HorzAlign = Center
shortcuts.MainTextBoxSplitAtCursor = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainTextBoxSplitAtCursorAndAutoBr");
if (subNode != null)
{
shortcuts.MainTextBoxSplitAtCursorAndAutoBr = subNode.InnerText;
}
subNode = node.SelectSingleNode("MainTextBoxSplitAtCursorAndVideoPos");
if (subNode != null)
{
@ -11260,6 +11267,7 @@ $HorzAlign = Center
textWriter.WriteElementString("MainEditReverseStartAndEndingForRTL", shortcuts.MainEditReverseStartAndEndingForRTL);
textWriter.WriteElementString("MainVideoToggleControls", shortcuts.MainVideoToggleControls);
textWriter.WriteElementString("MainTextBoxSplitAtCursor", shortcuts.MainTextBoxSplitAtCursor);
textWriter.WriteElementString("MainTextBoxSplitAtCursorAndAutoBr", shortcuts.MainTextBoxSplitAtCursorAndAutoBr);
textWriter.WriteElementString("MainTextBoxSplitAtCursorAndVideoPos", shortcuts.MainTextBoxSplitAtCursorAndVideoPos);
textWriter.WriteElementString("MainTextBoxSplitSelectedLineBilingual", shortcuts.MainTextBoxSplitSelectedLineBilingual);
textWriter.WriteElementString("MainTextBoxMoveLastWordDown", shortcuts.MainTextBoxMoveLastWordDown);

View File

@ -10651,7 +10651,12 @@ namespace Nikse.SubtitleEdit.Forms
}
else if (_shortcuts.MainTextBoxSplitAtCursor == e.KeyData)
{
ToolStripMenuItemSplitTextAtCursorClick(null, null);
SplitTextAtCursor(false);
e.SuppressKeyPress = true;
}
else if (_shortcuts.MainTextBoxSplitAtCursorAndAutoBr == e.KeyData)
{
SplitTextAtCursor(true);
e.SuppressKeyPress = true;
}
else if (_shortcuts.MainTextBoxSplitAtCursorAndVideoPos == e.KeyData)
@ -11108,7 +11113,7 @@ namespace Nikse.SubtitleEdit.Forms
SplitSelectedParagraph(null, null);
}
private void SplitSelectedParagraph(double? splitSeconds, int? textIndex)
private void SplitSelectedParagraph(double? splitSeconds, int? textIndex, bool autoBreak = false)
{
int maxSingleLineLength = Configuration.Settings.General.SubtitleLineMaximumLength;
var language = LanguageAutoDetect.AutoDetectGoogleLanguage(_subtitle);
@ -11337,6 +11342,12 @@ namespace Nikse.SubtitleEdit.Forms
FixSplitBoxTag(currentParagraph, newParagraph);
SetSplitTime(splitSeconds, currentParagraph, newParagraph, oldText);
if (autoBreak)
{
currentParagraph.Text = Utilities.AutoBreakLine(currentParagraph.Text);
newParagraph.Text = Utilities.AutoBreakLine(newParagraph.Text);
}
if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleOriginal != null && _subtitleOriginal.Paragraphs.Count > 0)
{
var originalCurrent = Utilities.GetOriginalParagraph(firstSelectedIndex, currentParagraph, _subtitleOriginal.Paragraphs);
@ -11522,7 +11533,13 @@ namespace Nikse.SubtitleEdit.Forms
_subtitleOriginal.Renumber();
FixSplitItalicTagAndAssa(originalCurrent, originalNew);
FixSplitFontTag(originalCurrent, originalNew);
FixSplitBoxTag(currentParagraph, newParagraph);
FixSplitBoxTag(originalCurrent, originalNew);
if (autoBreak)
{
originalCurrent.Text = Utilities.AutoBreakLine(originalCurrent.Text);
originalNew.Text = Utilities.AutoBreakLine(originalNew.Text);
}
}
}
@ -28638,6 +28655,11 @@ namespace Nikse.SubtitleEdit.Forms
}
private void ToolStripMenuItemSplitTextAtCursorClick(object sender, EventArgs e)
{
SplitTextAtCursor(false);
}
private void SplitTextAtCursor(bool autoBreak)
{
var tb = GetFocusedTextBox();
@ -28647,7 +28669,7 @@ namespace Nikse.SubtitleEdit.Forms
pos = tb.SelectionStart;
}
SplitSelectedParagraph(null, pos);
SplitSelectedParagraph(null, pos, autoBreak);
tb.Focus();
tb.SelectionStart = tb.Text.Length;
}

View File

@ -1516,6 +1516,7 @@ namespace Nikse.SubtitleEdit.Forms.Options
var textBoxNode = new ShortcutNode(language.TextBox);
AddNode(textBoxNode, LanguageSettings.Current.Main.Menu.ContextMenu.SplitLineAtCursorPosition, nameof(Configuration.Settings.Shortcuts.MainTextBoxSplitAtCursor));
AddNode(textBoxNode, LanguageSettings.Current.Main.Menu.ContextMenu.SplitLineAtCursorPositionAndAutoBr, nameof(Configuration.Settings.Shortcuts.MainTextBoxSplitAtCursorAndAutoBr));
AddNode(textBoxNode, LanguageSettings.Current.Main.Menu.ContextMenu.SplitLineAtCursorAndWaveformPosition, nameof(Configuration.Settings.Shortcuts.MainTextBoxSplitAtCursorAndVideoPos));
AddNode(textBoxNode, language.SplitSelectedLineBilingual, nameof(Configuration.Settings.Shortcuts.MainTextBoxSplitSelectedLineBilingual));
AddNode(textBoxNode, language.MainTextBoxMoveLastWordDown, nameof(Configuration.Settings.Shortcuts.MainTextBoxMoveLastWordDown));

View File

@ -1930,6 +1930,7 @@ namespace Nikse.SubtitleEdit.Logic
Paste = "Paste",
Delete = "Delete",
SplitLineAtCursorPosition = "Split line at cursor position",
SplitLineAtCursorPositionAndAutoBr = "Split line at cursor position and auto-break",
SplitLineAtCursorAndWaveformPosition = "Split line at cursor/video position",
AutoDurationCurrentLine = "Auto duration (current line)",
SelectAll = "Select all",

View File

@ -4480,6 +4480,9 @@ namespace Nikse.SubtitleEdit.Logic
case "Main/Menu/ContextMenu/SplitLineAtCursorPosition":
language.Main.Menu.ContextMenu.SplitLineAtCursorPosition = reader.Value;
break;
case "Main/Menu/ContextMenu/SplitLineAtCursorPositionAndAutoBr":
language.Main.Menu.ContextMenu.SplitLineAtCursorPositionAndAutoBr = reader.Value;
break;
case "Main/Menu/ContextMenu/SplitLineAtCursorAndWaveformPosition":
language.Main.Menu.ContextMenu.SplitLineAtCursorAndWaveformPosition = reader.Value;
break;

View File

@ -1775,6 +1775,7 @@ namespace Nikse.SubtitleEdit.Logic
public string Paste { get; set; }
public string Delete { get; set; }
public string SplitLineAtCursorPosition { get; set; }
public string SplitLineAtCursorPositionAndAutoBr { get; set; }
public string SplitLineAtCursorAndWaveformPosition { get; set; }
public string AutoDurationCurrentLine { get; set; }
public string SelectAll { get; set; }

View File

@ -103,6 +103,7 @@ namespace Nikse.SubtitleEdit.Logic
public Keys MainGeneralToggleMode { get; set; }
public Keys MainGeneralTogglePreviewOnVideo { get; set; }
public Keys MainTextBoxSplitAtCursor { get; set; }
public Keys MainTextBoxSplitAtCursorAndAutoBr { get; set; }
public Keys MainTextBoxSplitAtCursorAndVideoPos { get; set; }
public Keys MainTextBoxSplitSelectedLineBilingual { get; set; }
public Keys MainTextBoxMoveLastWordDown { get; set; }
@ -373,6 +374,7 @@ namespace Nikse.SubtitleEdit.Logic
MainListViewCopyText = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainListViewCopyText);
MainListViewCopyPlainText = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainListViewCopyPlainText);
MainTextBoxSplitAtCursor = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxSplitAtCursor);
MainTextBoxSplitAtCursorAndAutoBr = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxSplitAtCursorAndAutoBr);
MainTextBoxSplitAtCursorAndVideoPos = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxSplitAtCursorAndVideoPos);
MainTextBoxSplitSelectedLineBilingual = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxSplitSelectedLineBilingual);
MainTextBoxMoveLastWordDown = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxMoveLastWordDown);