From 8f4c8e02c5ccf9ab7344864554aca22d84631d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Fri, 26 Jun 2015 11:02:38 +0200 Subject: [PATCH] TranslationTextCtrl: fix invalid iterators when adding \n 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. --- src/text_control.cpp | 10 ++++++++++ src/text_control.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/text_control.cpp b/src/text_control.cpp index 16726c0da4..c1861fbe26 100644 --- a/src/text_control.cpp +++ b/src/text_control.cpp @@ -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(); diff --git a/src/text_control.h b/src/text_control.h index 39e5c2397d..531ad4f885 100644 --- a/src/text_control.h +++ b/src/text_control.h @@ -132,7 +132,7 @@ class AnyTranslatableTextCtrl : public CustomizedTextCtrl void DoSetValue(const wxString& value, int flags) override; #endif -private: +protected: void HighlightText(); class Attributes;