Skip to content

Commit

Permalink
Fixed auto word selection in native winforms RTB
Browse files Browse the repository at this point in the history
  • Loading branch information
openbullet committed Aug 4, 2024
1 parent 041f7de commit 439cf10
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
13 changes: 11 additions & 2 deletions OpenBullet2.Native/Views/Dialogs/BotLogDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public BotLogDialog(IBotLogger logger)

logRTB.Font = new System.Drawing.Font("Consolas", 10);
logRTB.BackColor = System.Drawing.Color.FromArgb(22, 22, 22);
logRTB.HandleCreated += (_, _) => FixAutoWordSelection(logRTB);

if (logger is null)
{
Expand All @@ -45,9 +46,17 @@ public BotLogDialog(IBotLogger logger)
}
catch
{

// ignored
}
}

private void FixAutoWordSelection(System.Windows.Forms.RichTextBox rtb)
{
// Stupid ass workaround because WinForms RichTextBox is broken
// https://stackoverflow.com/questions/3678620/c-sharp-richtextbox-selection-problem
rtb.AutoWordSelection = true;
rtb.AutoWordSelection = false;
}

#region Search
private void Search(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -139,7 +148,7 @@ private void NextMatch(object sender, RoutedEventArgs e)
}
#endregion
}

public class BotLogDialogViewModel : ViewModelBase
{
private string searchString = string.Empty;
Expand Down
14 changes: 12 additions & 2 deletions OpenBullet2.Native/Views/Pages/Shared/Debugger.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,27 @@ public Debugger()

logRTB.Font = new System.Drawing.Font("Consolas", 10);
logRTB.BackColor = System.Drawing.Color.FromArgb(22, 22, 22);

logRTB.HandleCreated += (_, _) => FixAutoWordSelection(logRTB);

variablesRTB.Font = new System.Drawing.Font("Consolas", 10);
variablesRTB.BackColor = System.Drawing.Color.FromArgb(22, 22, 22);
variablesRTB.HandleCreated += (_, _) => FixAutoWordSelection(variablesRTB);
}

private void FixAutoWordSelection(System.Windows.Forms.RichTextBox rtb)
{
// Stupid ass workaround because WinForms RichTextBox is broken
// https://stackoverflow.com/questions/3678620/c-sharp-richtextbox-selection-problem
rtb.AutoWordSelection = true;
rtb.AutoWordSelection = false;
}

private void ShowLog(object sender, RoutedEventArgs e) => tabControl.SelectedIndex = 0;
private void ShowVariables(object sender, RoutedEventArgs e) => tabControl.SelectedIndex = 1;
private void ShowHTML(object sender, RoutedEventArgs e) => tabControl.SelectedIndex = 2;

private async void Start(object sender, RoutedEventArgs e)
{
{
if (!vm.PersistLog)
{
logRTB.Clear();
Expand Down

0 comments on commit 439cf10

Please sign in to comment.