Skip to content

Commit

Permalink
Fixed bug that phonemized result not updated properly
Browse files Browse the repository at this point in the history
  • Loading branch information
EX3exp committed Oct 6, 2024
1 parent dd619d3 commit 6374c88
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
22 changes: 18 additions & 4 deletions Mirivoice/Views/LineBoxView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ public bool ShouldPhonemize

if (value)
{
PhonemizeLine();
DeActivatePhonemizer = true;
Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(async () =>
{
await PhonemizeLine();
_shouldPhonemize = false;
DeActivatePhonemizer = true;
});
}
}
}
Expand Down Expand Up @@ -131,7 +135,7 @@ private async Task PhonemizeLine(bool ApplyToCurrentEdit = true)
}
else
{
await Task.Run(() => viewModel.phonemizer.PhonemizeAsync(textChanged, this, ApplyToCurrentEdit));
await Task.Run(() => viewModel.phonemizer.PhonemizeAsync(textChanged, this));
lastPhonemizedText = textChanged;
}

Expand All @@ -157,7 +161,7 @@ private async Task PhonemizeLine(bool ApplyToCurrentEdit = true)

public bool ShouldPhonemizeWhenSelected = false;

SingleLineEditorView singleLineEditorView;
public SingleLineEditorView singleLineEditorView;
public ObservableCollection<MResult> MResultsCollection { get; set; } = new ObservableCollection<MResult>();


Expand Down Expand Up @@ -549,6 +553,16 @@ private void OnDragStart(object sender, RoutedEventArgs e)
}

}
if (singleLineEditorView is not null && lastPhonemizedText is not null && singleLineEditorView.viewModel.mTextBoxEditor.CurrentScript is not null)
{
if (!lastPhonemizedText.Equals(singleLineEditorView.viewModel.mTextBoxEditor.CurrentScript))
{
DeActivatePhonemizer = false;
ShouldPhonemize = true;
}
}


if (v.CurrentLineBox != this)
{

Expand Down
33 changes: 21 additions & 12 deletions Mirivoice/Views/SingleLineEditorView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@ public SingleLineEditorView(LineBoxView lineBoxView, bool FirstUpdate = true)

bool ShouldPhonemizeWhenOutFocused = false;

private async void LineTextChanging(object sender, TextChangingEventArgs e)
private void LineTextChanging(object sender, TextChangingEventArgs e)
{
l.DeActivatePhonemizer = false;
if (FirstUpdate)
{
FirstUpdate = false;
Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(viewModel.mTextBoxEditor.CurrentScript, l));
l.DeActivatePhonemizer = false;
l.ShouldPhonemize = true;
return;
}
if (l.lastPhonemizedText != l.viewModel.LineText)

if (l.singleLineEditorView is not null && l.lastPhonemizedText is not null && l.singleLineEditorView.viewModel.mTextBoxEditor.CurrentScript is not null)
{
ShouldPhonemizeWhenOutFocused = true;
if (!l.lastPhonemizedText.Equals(l.singleLineEditorView.viewModel.mTextBoxEditor.CurrentScript))
{
ShouldPhonemizeWhenOutFocused = true;
}
}
if (l.ShouldPhonemize && !l.DeActivatePhonemizer)
{
Expand All @@ -54,26 +59,30 @@ private void LineLostFocus(object sender, RoutedEventArgs e)
l.viewModel.LineText = viewModel.mTextBoxEditor.CurrentScript;
//Log.Information("SingleLineTBox Lost Focus");
//Log.Debug($"lastPhonemizedText={l.lastPhonemizedText} // LineText={l.viewModel.LineText}");
if (l.lastPhonemizedText != l.viewModel.LineText)
if (l.singleLineEditorView is not null && l.lastPhonemizedText is not null && l.singleLineEditorView.viewModel.mTextBoxEditor.CurrentScript is not null)
{
//Log.Debug("lastPhonemizedText != l.viewModel.LineText");
l.DeActivatePhonemizer = false;
ShouldPhonemizeWhenOutFocused = true;

if (!l.lastPhonemizedText.Equals(l.singleLineEditorView.viewModel.mTextBoxEditor.CurrentScript))
{
l.DeActivatePhonemizer = false;
l.ShouldPhonemize = true;
}
}


if (ShouldPhonemizeWhenOutFocused)
{
//Log.Debug("ShouldPhonemizeWhenOutFocused");
l.DeActivatePhonemizer = false;
l.ShouldPhonemize = true;
Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(viewModel.mTextBoxEditor.CurrentScript, l));

ShouldPhonemizeWhenOutFocused = false;
}

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

Expand All @@ -99,7 +108,7 @@ private void InitializeComponent(LineBoxView l)
DataContext = viewModel = new SingleLineEditorViewModel(l.viewModel.LineText);
}

public async void SetLine(string text)
public void SetLine(string text)
{
if (text == null)
{
Expand Down

0 comments on commit 6374c88

Please sign in to comment.