From defdf8e6ae9af1a2e017a74f9a61a38953bae7fc Mon Sep 17 00:00:00 2001 From: fiaxh Date: Thu, 29 Jul 2021 15:13:03 +0200 Subject: Don't keep own reference to GspellTextView/Buffer fixes #1058 --- main/src/ui/chat_input/spell_checker.vala | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'main/src/ui/chat_input') diff --git a/main/src/ui/chat_input/spell_checker.vala b/main/src/ui/chat_input/spell_checker.vala index 8359b1b4..bdd9d51a 100644 --- a/main/src/ui/chat_input/spell_checker.vala +++ b/main/src/ui/chat_input/spell_checker.vala @@ -1,6 +1,5 @@ using Gdk; using Gee; -using Gspell; using Dino.Entities; @@ -9,12 +8,14 @@ namespace Dino.Ui { public class SpellChecker { private Conversation? conversation; - private TextView text_view; - private TextBuffer text_buffer; + private Gtk.TextView text_input; public SpellChecker(Gtk.TextView text_input) { - this.text_view = TextView.get_from_gtk_text_view(text_input); - this.text_buffer = TextBuffer.get_from_gtk_text_buffer(text_view.view.buffer); + this.text_input = text_input; + + // We can't keep a reference to GspellTextView/Buffer around, otherwise they'd get freed twice + Gspell.TextView text_view = Gspell.TextView.get_from_gtk_text_view(text_input); + Gspell.TextBuffer text_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(text_view.view.buffer); text_view.basic_setup(); text_buffer.spell_checker.notify["language"].connect(lang_changed); @@ -32,11 +33,14 @@ public class SpellChecker { public void initialize_for_conversation(Conversation conversation) { this.conversation = conversation; + Gspell.TextView text_view = Gspell.TextView.get_from_gtk_text_view(text_input); + Gspell.TextBuffer text_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(text_view.view.buffer); + if (!Dino.Application.get_default().settings.check_spelling) { text_buffer.set_spell_checker(null); return; } - if (text_buffer.spell_checker == null) text_buffer.spell_checker = new Checker(null); + if (text_buffer.spell_checker == null) text_buffer.spell_checker = new Gspell.Checker(null); // Set the conversation language (from cache or db) text_buffer.spell_checker.notify["language"].disconnect(lang_changed); @@ -48,7 +52,7 @@ public class SpellChecker { .single().row(); if (row_option.is_present()) { string lang_code = row_option.inner[db.conversation_settings.value]; - Language? lang = Language.lookup(lang_code); + Gspell.Language? lang = Gspell.Language.lookup(lang_code); text_buffer.spell_checker.language = lang; } else { text_buffer.spell_checker.language = null; @@ -60,8 +64,11 @@ public class SpellChecker { private void lang_changed() { var db = Dino.Application.get_default().db; - Checker spell_checker = text_buffer.spell_checker; + Gspell.TextView text_view = Gspell.TextView.get_from_gtk_text_view(text_input); + Gspell.TextBuffer text_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(text_view.view.buffer); + Gspell.Checker spell_checker = text_buffer.spell_checker; if (spell_checker.language.get_code() == null) return; + db.conversation_settings.upsert() .value(db.conversation_settings.conversation_id, conversation.id, true) .value(db.conversation_settings.key, "lang", true) -- cgit v1.2.3-70-g09d2