diff options
author | fiaxh <git@lightrise.org> | 2021-07-29 15:13:03 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2021-07-29 17:28:35 +0200 |
commit | defdf8e6ae9af1a2e017a74f9a61a38953bae7fc (patch) | |
tree | 651dd545441d69a442243230b30c675d24e17e89 | |
parent | 2ea4fa0ce6a59c64838705a5eee32fdd097d4a51 (diff) | |
download | dino-defdf8e6ae9af1a2e017a74f9a61a38953bae7fc.tar.gz dino-defdf8e6ae9af1a2e017a74f9a61a38953bae7fc.zip |
Don't keep own reference to GspellTextView/Buffer
fixes #1058
-rw-r--r-- | main/src/ui/chat_input/spell_checker.vala | 23 |
1 files changed, 15 insertions, 8 deletions
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) |