Skip to content

Commit

Permalink
Fixed bug in updating phonemize result
Browse files Browse the repository at this point in the history
  • Loading branch information
EX3exp committed Oct 2, 2024
1 parent a8dbed7 commit bf715c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Mirivoice/Views/SingleLineEditorView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
x:Class="Mirivoice.SingleLineEditorView">

<Border>
<TextBox AcceptsReturn="True" LostFocus="LineLostFocus" GotFocus="LineGotFocus" TextChanged="LineTextChanged" TextWrapping="Wrap" Text="{Binding mTextBoxEditor.CurrentScript, Mode=TwoWay}" IsUndoEnabled="False" Watermark="{DynamicResource singlelinebox.placeholder}" FontSize="15" CornerRadius="0"></TextBox>
<TextBox AcceptsReturn="True" LostFocus="LineLostFocus" GotFocus="LineGotFocus" TextChanging="LineTextChanging" TextWrapping="Wrap" Text="{Binding mTextBoxEditor.CurrentScript, Mode=TwoWay}" IsUndoEnabled="False" Watermark="{DynamicResource singlelinebox.placeholder}" FontSize="15" CornerRadius="0"></TextBox>
</Border>
</UserControl>
21 changes: 16 additions & 5 deletions Mirivoice/Views/SingleLineEditorView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public SingleLineEditorView(LineBoxView l, bool FirstUpdate = true)
this.FirstUpdate = FirstUpdate;
}

bool ShouldPhonemizeWhenOutFocused = false;

private async void LineTextChanged(object sender, TextChangedEventArgs e)
private async void LineTextChanging(object sender, TextChangingEventArgs e)
{

l.DeActivatePhonemizer = false;
Expand All @@ -38,32 +39,42 @@ private async void LineTextChanged(object sender, TextChangedEventArgs e)
}
if (l.lastPhonemizedText != l.viewModel.LineText)
{
l.ShouldPhonemize = true;
ShouldPhonemizeWhenOutFocused = true;
}
if (l.ShouldPhonemize && !l.DeActivatePhonemizer)
{
await Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(viewModel.mTextBoxEditor.CurrentScript, l));
ShouldPhonemizeWhenOutFocused = true;
}
l.viewModel.LineText = viewModel.mTextBoxEditor.CurrentScript;

}

private void LineLostFocus(object sender, RoutedEventArgs e)
{
l.viewModel.LineText = viewModel.mTextBoxEditor.CurrentScript;
//Log.Debug("SingleLineTBox Lost Focus");
if (l.lastPhonemizedText != l.viewModel.LineText)
{
l.DeActivatePhonemizer = false;
ShouldPhonemizeWhenOutFocused = true;
}

if (FirstUpdate)
{
FirstUpdate = false;
Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(viewModel.mTextBoxEditor.CurrentScript, l));
return;
}

if (ShouldPhonemizeWhenOutFocused)
{
l.ShouldPhonemize = true;
ShouldPhonemizeWhenOutFocused = false;
}

if (! l.DeActivatePhonemizer || l.MResultsCollection.Count == 0 && !string.IsNullOrEmpty(l.viewModel.LineText))
{
l.ShouldPhonemize = true;

return;
}


Expand Down

0 comments on commit bf715c5

Please sign in to comment.