Skip to content

Commit

Permalink
fix: crash when merging paragraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislav.seps committed Oct 14, 2014
1 parent c17ee11 commit ae20f88
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions WpfApplication2/Control/SubtitlesVizualizer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ void l_MergeWithPreviousRequest(object sender, EventArgs e)
Element el = (Element)sender;
TranscriptionElement t = el.ValueElement;
TranscriptionElement p = el.ValueElement.Previous();
t.Parent.BeginUpdate();
var parent = t.Parent;
parent.BeginUpdate();
int len = p.Text.Length;
if (t is TranscriptionParagraph && p is TranscriptionParagraph)
{
Expand All @@ -237,13 +238,13 @@ void l_MergeWithPreviousRequest(object sender, EventArgs e)
pel.ValueElement = p;
}
}
t.Parent.Remove(t);
parent.Remove(t);

}
// SpeakerChanged();
t.Parent.EndUpdate();
// SpeakerChanged();
parent.EndUpdate();
ActiveTransctiption = p;
ScrollToItem(p);
// ScrollToItem(p);
var vis = GetVisualForTransctiption(p);
vis.editor.CaretOffset = len;
}
Expand Down Expand Up @@ -272,8 +273,9 @@ void l_MergeWithnextRequest(object sender, EventArgs e)
//SpeakerChanged();
t.Parent.EndUpdate();
ActiveTransctiption = t;
ScrollToItem(t);
//ScrollToItem(t);
ColorizeBackground(t);
_scrollViewer.UpdateLayout();
var vis = GetVisualForTransctiption(t);
vis.editor.CaretOffset = len;
}
Expand Down Expand Up @@ -469,7 +471,6 @@ private void ScrollToItem(TranscriptionElement elm)

listbox.SelectedItem = elm;
listbox.ScrollIntoView(listbox.Items[listbox.SelectedIndex]);
listbox.UpdateLayout();
if (elm == Transcription.Last())
{
_scrollViewer.ScrollToBottom();
Expand All @@ -478,12 +479,19 @@ private void ScrollToItem(TranscriptionElement elm)
{
var all = listbox.VisualFindChildren<Element>();
var visible = all.Where(itm => listbox.VisualIsVisibleChild(itm));
if (!visible.Any(itm => itm.ValueElement == elm))
{
var element = all.First(itm => itm.ValueElement == elm);
var position = element.TransformToAncestor(_scrollViewer).Transform(new Point(0, element.ActualHeight));
_scrollViewer.ScrollToVerticalOffset(position.Y);
}

Action scroll = new Action(() =>
{
all = listbox.VisualFindChildren<Element>();
visible = all.Where(itm => listbox.VisualIsVisibleChild(itm));
var element = all.First(itm => itm.ValueElement == elm);
var position = element.TransformToAncestor(_scrollViewer).Transform(new Point(0, element.ActualHeight));
_scrollViewer.ScrollToVerticalOffset(position.Y);
_scrollViewer.UpdateLayout();
});

if (visible.Any(itm => itm.ValueElement == elm))
_scrollViewer.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, scroll);
}
}

Expand Down

0 comments on commit ae20f88

Please sign in to comment.