From 8722f3338d91cca01557e0ae278744023142cd90 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Thu, 31 Oct 2024 18:40:45 +0100 Subject: [PATCH] Add new shortcut "Move first word to previous subtitle" - thx Rychelle :) --- src/libse/Settings/Settings.cs | 7 ++++ src/libse/Settings/Shortcuts.cs | 1 + src/ui/Forms/Main.cs | 60 +++++++++++++++++++++++++++++++ src/ui/Forms/Options/Settings.cs | 1 + src/ui/Logic/Language.cs | 1 + src/ui/Logic/LanguageStructure.cs | 1 + src/ui/Logic/MainShortcuts.cs | 2 ++ 7 files changed, 73 insertions(+) diff --git a/src/libse/Settings/Settings.cs b/src/libse/Settings/Settings.cs index d43ccf660..401900ebb 100644 --- a/src/libse/Settings/Settings.cs +++ b/src/libse/Settings/Settings.cs @@ -7914,6 +7914,12 @@ namespace Nikse.SubtitleEdit.Core.Settings shortcuts.MainTextBoxMoveFromCursorToNextAndGoToNext = subNode.InnerText; } + subNode = node.SelectSingleNode("MainTextBoxMoveFirstWordToPrev"); + if (subNode != null) + { + shortcuts.MainTextBoxMoveFirstWordToPrev = subNode.InnerText; + } + subNode = node.SelectSingleNode("MainTextBoxSelectionToLower"); if (subNode != null) { @@ -10166,6 +10172,7 @@ namespace Nikse.SubtitleEdit.Core.Settings textWriter.WriteElementString("MainTextBoxMoveLastWordDownCurrent", shortcuts.MainTextBoxMoveLastWordDownCurrent); textWriter.WriteElementString("MainTextBoxMoveFirstWordUpCurrent", shortcuts.MainTextBoxMoveFirstWordUpCurrent); textWriter.WriteElementString("MainTextBoxMoveFromCursorToNext", shortcuts.MainTextBoxMoveFromCursorToNextAndGoToNext); + textWriter.WriteElementString("MainTextBoxMoveFirstWordToPrev", shortcuts.MainTextBoxMoveFirstWordToPrev); textWriter.WriteElementString("MainTextBoxSelectionToLower", shortcuts.MainTextBoxSelectionToLower); textWriter.WriteElementString("MainTextBoxSelectionToUpper", shortcuts.MainTextBoxSelectionToUpper); textWriter.WriteElementString("MainTextBoxSelectionToggleCasing", shortcuts.MainTextBoxSelectionToggleCasing); diff --git a/src/libse/Settings/Shortcuts.cs b/src/libse/Settings/Shortcuts.cs index b3b543717..d06a40206 100644 --- a/src/libse/Settings/Shortcuts.cs +++ b/src/libse/Settings/Shortcuts.cs @@ -291,6 +291,7 @@ namespace Nikse.SubtitleEdit.Core.Settings public string MainTextBoxMoveLastWordDownCurrent { get; set; } public string MainTextBoxMoveFirstWordUpCurrent { get; set; } public string MainTextBoxMoveFromCursorToNextAndGoToNext { get; set; } + public string MainTextBoxMoveFirstWordToPrev { get; set; } public string MainTextBoxSelectionToLower { get; set; } public string MainTextBoxSelectionToUpper { get; set; } public string MainTextBoxSelectionToggleCasing { get; set; } diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index d95ee1e6b..d628207e5 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -11893,6 +11893,53 @@ namespace Nikse.SubtitleEdit.Forms } } + private void MoveFirstWordToPrev(SETextBox tb) + { + int firstIndex = FirstSelectedIndex; + if (firstIndex <= 0) + { + return; + } + + var prev = _subtitle.GetParagraphOrDefault(firstIndex - 1); + var current = _subtitle.GetParagraphOrDefault(firstIndex); + + if (tb == textBoxListViewTextOriginal) + { + prev = Utilities.GetOriginalParagraph(firstIndex - 1, prev, _subtitleOriginal.Paragraphs); + current = Utilities.GetOriginalParagraph(firstIndex, current, _subtitleOriginal.Paragraphs); + } + + if (prev != null && current != null) + { + var moveUpDown = new MoveWordUpDown(prev.Text, current.Text); + moveUpDown.MoveWordUp(); + if (moveUpDown.S1 != prev.Text && moveUpDown.S2 != current.Text) + { + MakeHistoryForUndo(_language.BeforeLineUpdatedInListView); + prev.Text = moveUpDown.S1; + current.Text = moveUpDown.S2; + if (tb == textBoxListViewTextOriginal) + { + SubtitleListview1.SetOriginalText(firstIndex - 1, prev.Text); + SubtitleListview1.SetOriginalText(firstIndex, current.Text); + } + else + { + SubtitleListview1.SetText(firstIndex - 1, prev.Text); + SubtitleListview1.SetText(firstIndex, current.Text); + } + + var selectionStart = textBoxListViewText.SelectionStart; + tb.Text = current.Text; + if (selectionStart >= 0) + { + tb.SelectionStart = selectionStart; + } + } + } + } + private void MoveLastWordDown(SETextBox tb) { int firstIndex = FirstSelectedIndex; @@ -18715,6 +18762,19 @@ namespace Nikse.SubtitleEdit.Forms e.SuppressKeyPress = true; } + else if (e.KeyData == _shortcuts.MainTextBoxMoveFirstWordToPrev) + { + if (textBoxListViewTextOriginal.Focused) + { + MoveFirstWordToPrev(textBoxListViewTextOriginal); + } + else + { + MoveFirstWordToPrev(textBoxListViewText); + } + + e.SuppressKeyPress = true; + } else if (_shortcuts.MainAutoCalcCurrentDuration == e.KeyData) { RecalcCurrentDuration(); diff --git a/src/ui/Forms/Options/Settings.cs b/src/ui/Forms/Options/Settings.cs index 161a16419..b111dc34a 100644 --- a/src/ui/Forms/Options/Settings.cs +++ b/src/ui/Forms/Options/Settings.cs @@ -1824,6 +1824,7 @@ namespace Nikse.SubtitleEdit.Forms.Options AddNode(textBoxNode, language.MainTextBoxMoveLastWordDownCurrent, nameof(Configuration.Settings.Shortcuts.MainTextBoxMoveLastWordDownCurrent)); AddNode(textBoxNode, language.MainTextBoxMoveFirstWordUpCurrent, nameof(Configuration.Settings.Shortcuts.MainTextBoxMoveFirstWordUpCurrent)); AddNode(textBoxNode, language.MainTextBoxMoveFromCursorToNext, nameof(Configuration.Settings.Shortcuts.MainTextBoxMoveFromCursorToNextAndGoToNext)); + AddNode(textBoxNode, language.MainTextBoxMoveFirstWordToPrev, nameof(Configuration.Settings.Shortcuts.MainTextBoxMoveFirstWordToPrev)); AddNode(textBoxNode, language.MainTextBoxSelectionToLower, nameof(Configuration.Settings.Shortcuts.MainTextBoxSelectionToLower)); AddNode(textBoxNode, language.MainTextBoxSelectionToUpper, nameof(Configuration.Settings.Shortcuts.MainTextBoxSelectionToUpper)); AddNode(textBoxNode, language.MainTextBoxSelectionToRuby, nameof(Configuration.Settings.Shortcuts.MainTextBoxSelectionToRuby), true); diff --git a/src/ui/Logic/Language.cs b/src/ui/Logic/Language.cs index 5c20937f8..016c463b7 100644 --- a/src/ui/Logic/Language.cs +++ b/src/ui/Logic/Language.cs @@ -3162,6 +3162,7 @@ can edit in same subtitle file (collaboration)", MainTextBoxMoveLastWordDownCurrent = "Move last word from first line down (current subtitle)", MainTextBoxMoveFirstWordUpCurrent = "Move first word from next line up (current subtitle)", MainTextBoxMoveFromCursorToNext = "Move text after cursor position to next subtitle and go to next", + MainTextBoxMoveFirstWordToPrev = "Move first word to previous subtitle", MainTextBoxSelectionToLower = "Selection to lowercase", MainTextBoxSelectionToUpper = "Selection to uppercase", MainTextBoxSelectionToggleCasing = "Toggle casing of selection (propercase/uppercase/lowercase)", diff --git a/src/ui/Logic/LanguageStructure.cs b/src/ui/Logic/LanguageStructure.cs index f3982b0cd..9efd37e3d 100644 --- a/src/ui/Logic/LanguageStructure.cs +++ b/src/ui/Logic/LanguageStructure.cs @@ -2977,6 +2977,7 @@ public string MainTextBoxMoveFirstWordFromNextUp { get; set; } public string MainTextBoxMoveFirstWordUpCurrent { get; set; } public string MainTextBoxMoveFromCursorToNext { get; set; } + public string MainTextBoxMoveFirstWordToPrev { get; set; } public string MainTextBoxMoveLastWordDownCurrent { get; set; } public string MainTextBoxSelectionToLower { get; set; } public string MainTextBoxSelectionToUpper { get; set; } diff --git a/src/ui/Logic/MainShortcuts.cs b/src/ui/Logic/MainShortcuts.cs index 1363c9901..2f604fbcf 100644 --- a/src/ui/Logic/MainShortcuts.cs +++ b/src/ui/Logic/MainShortcuts.cs @@ -133,6 +133,7 @@ namespace Nikse.SubtitleEdit.Logic public Keys MainTextBoxMoveFirstWordFromNextUp { get; set; } public Keys MainTextBoxMoveLastWordDownCurrent { get; set; } public Keys MainTextBoxMoveFromCursorToNextAndGoToNext { get; set; } + public Keys MainTextBoxMoveFirstWordToPrev { get; set; } public Keys MainTextBoxMoveFirstWordUpCurrent { get; set; } public Keys MainTextBoxSelectionToLower { get; set; } public Keys MainTextBoxSelectionToUpper { get; set; } @@ -458,6 +459,7 @@ namespace Nikse.SubtitleEdit.Logic MainTextBoxMoveFirstWordFromNextUp = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxMoveFirstWordFromNextUp); MainTextBoxMoveLastWordDownCurrent = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxMoveLastWordDownCurrent); MainTextBoxMoveFromCursorToNextAndGoToNext = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxMoveFromCursorToNextAndGoToNext); + MainTextBoxMoveFirstWordToPrev = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxMoveFirstWordToPrev); MainTextBoxMoveFirstWordUpCurrent = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxMoveFirstWordUpCurrent); MainTextBoxSelectionToLower = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxSelectionToLower); MainTextBoxSelectionToUpper = UiUtil.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxSelectionToUpper);