Fix single letter shortcut conflict - thx Leon :)

Fix #5520
This commit is contained in:
niksedk 2021-11-24 08:38:59 +01:00
parent 6b0f04c271
commit 0475276d5d
3 changed files with 35 additions and 13 deletions

View File

@ -846,6 +846,28 @@ namespace Nikse.SubtitleEdit.Forms
private void FormFixKeyDown(object sender, KeyEventArgs e) private void FormFixKeyDown(object sender, KeyEventArgs e)
{ {
var fc = UiUtil.FindFocusedControl(this);
if (fc != null && (e.Modifiers == Keys.None || e.Modifiers == Keys.Shift))
{
var typeName = fc.GetType().Name;
// do not check for shortcuts if text is being entered and a textbox is focused
var textBoxTypes = new List<string> { "AdvancedTextBox", "SimpleTextBox", "SETextBox", "TextBox", "RichTextBox" };
if (textBoxTypes.Contains(typeName) &&
((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) || (e.KeyCode >= Keys.OemSemicolon && e.KeyCode <= Keys.OemBackslash) || e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9 || e.KeyValue >= 48 && e.KeyValue <= 57) &&
!Configuration.Settings.General.AllowLetterShortcutsInTextBox)
{
return;
}
// do not check for shortcuts if a number is being entered and a time box is focused
if (typeName == "UpDownEdit" &&
(e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9 || e.KeyValue >= 48 && e.KeyValue <= 57))
{
return;
}
}
if (e.KeyCode == Keys.Escape) if (e.KeyCode == Keys.Escape)
{ {
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;

View File

@ -15075,18 +15075,6 @@ namespace Nikse.SubtitleEdit.Forms
RefreshSelectedParagraph(); RefreshSelectedParagraph();
} }
public static Control FindFocusedControl(Control control)
{
var container = control as ContainerControl;
while (container != null)
{
control = container.ActiveControl;
container = control as ContainerControl;
}
return control;
}
internal void MainKeyDown(object sender, KeyEventArgs e) internal void MainKeyDown(object sender, KeyEventArgs e)
{ {
if (e.KeyCode == Keys.LWin) if (e.KeyCode == Keys.LWin)
@ -15126,7 +15114,7 @@ namespace Nikse.SubtitleEdit.Forms
return; return;
} }
var fc = FindFocusedControl(this); var fc = UiUtil.FindFocusedControl(this);
if (fc != null && (e.Modifiers == Keys.None || e.Modifiers == Keys.Shift)) if (fc != null && (e.Modifiers == Keys.None || e.Modifiers == Keys.Shift))
{ {
var typeName = fc.GetType().Name; var typeName = fc.GetType().Name;

View File

@ -1361,5 +1361,17 @@ namespace Nikse.SubtitleEdit.Logic
} }
public static string DecimalSeparator => CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; public static string DecimalSeparator => CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
public static Control FindFocusedControl(Control control)
{
var container = control as ContainerControl;
while (container != null)
{
control = container.ActiveControl;
container = control as ContainerControl;
}
return control;
}
} }
} }