diff options
author | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2025-01-21 22:18:53 +0000 |
---|---|---|
committer | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2025-01-21 22:18:53 +0000 |
commit | 903e32b804eb257ffeb87d76bde373bcb9ac882c (patch) | |
tree | fc79dbe87af1135fa6dbac63b52607ed6bb0c205 /src | |
parent | 8bd5b17906ac145fd35383bad413bca4aa342688 (diff) |
chat: Make enter key work for GtkSourceView
Diffstat (limited to 'src')
-rw-r--r-- | src/chat.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/chat.py b/src/chat.py index ab33ebe..d7f1ce8 100644 --- a/src/chat.py +++ b/src/chat.py @@ -68,7 +68,13 @@ class WeegtkChat(Adw.Bin): adj.connect("value-changed", self.scroll_changes) adj.connect("notify::upper", self.upper_notify) - self.text_entry.get_buffer().connect("insert-text", self.text_inserted) + sc_controller = Gtk.ShortcutController(propagation_phase=Gtk.PropagationPhase.CAPTURE) + action = Gtk.CallbackAction.new(self.entry_callback, self) + trigger = Gtk.ShortcutTrigger.parse_string("Return") + shortcut = Gtk.Shortcut(action=action, trigger=trigger) + sc_controller.add_shortcut(shortcut) + + self.add_controller(sc_controller) # Enable spell checking self.checker = Spelling.Checker.get_default() @@ -202,14 +208,9 @@ class WeegtkChat(Adw.Bin): entry_buffer.set_text("", 0) self.emit("buffer_input", self.data['full_name'], text) - def text_inserted(self, buffer, location, text, length): - if text == "\n": - print("Got newline!") - entry_buffer = self.text_entry.get_buffer() - text = entry_buffer.get_text(entry_buffer.get_start_iter(), entry_buffer.get_end_iter(), False) - print("Buffer is {}".format(text)) - print("Last char is {}".format(text[-1])) - self.entry_activate() + def entry_callback(self, *args): + self.entry_activate() + return True def open_file_dialog(self, dialog, result, caller): try: @@ -221,7 +222,7 @@ class WeegtkChat(Adw.Bin): conf = config.read() file_url = netfile.upload(file.get_path(), conf["upload"]["url"]) entry_buffer = self.text_entry.get_buffer() - entry_buffer.insert_text(self.text_entry.get_position(), file_url, -1) + entry_buffer.insert_at_cursor(file_url, -1) @Gtk.Template.Callback() def attach_file(self, *args): |