Skip to content

Commit

Permalink
TranslationTextCtrl: fix invalid iterators when adding \n
Browse files Browse the repository at this point in the history
Don't do text modifications from GtkTextBuffer's "changed" signal,
because it is emitted at a time when GTK+ internal code holds some
iterator(s). Use CallAfter() to delay the operation a tiny bit and
execute it from the main loop.

Fixes #190.
  • Loading branch information
vslavik committed Jun 26, 2015
1 parent 2fdca12 commit 8f4c8e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/text_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,17 @@ void TranslationTextCtrl::OnText(wxCommandEvent& e)
long pos = GetInsertionPoint();
auto range = GetRange(std::max(0l, pos - 3), pos);
if (range.Last() == '\n' && range != "\\n\n")
{
#ifdef __WXGTK__
// GTK+ doesn't like modifying the content in the "changed" signal:
CallAfter([=]{
Replace(pos - 1, pos, "\\n\n");
HighlightText();
});
#else
Replace(pos - 1, pos, "\\n\n");
#endif
}
}

e.Skip();
Expand Down
2 changes: 1 addition & 1 deletion src/text_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class AnyTranslatableTextCtrl : public CustomizedTextCtrl
void DoSetValue(const wxString& value, int flags) override;
#endif

private:
protected:
void HighlightText();

class Attributes;
Expand Down

0 comments on commit 8f4c8e0

Please sign in to comment.