Daniel Brötzmann pushed to branch newcontrol at gajim / gajim


Commits:
68181443 by wurstsalat at 2022-07-08T18:48:34+02:00
MessageInputTextView: Add draft support

- - - - -


1 changed file:

- gajim/gtk/message_input.py


Changes:

=====================================
gajim/gtk/message_input.py
=====================================
@@ -20,6 +20,7 @@
 from __future__ import annotations
 
 from typing import Any
+from typing import Optional
 
 import sys
 
@@ -73,6 +74,9 @@ def __init__(self) -> None:
         self._undo_list: list[str] = []
         self.undo_pressed: bool = False
 
+        self._contact: Optional[ChatContactT] = None
+        self._drafts: dict[str, str] = {}
+
         self._chat_action_processor = ChatActionProcessor(self)
 
         self.get_buffer().create_tag('strong', weight=Pango.Weight.BOLD)
@@ -88,6 +92,18 @@ def __init__(self) -> None:
         self.connect('populate-popup', self._on_populate_popup)
 
     def switch_contact(self, contact: ChatContactT) -> None:
+        if self._contact is not None:
+            if self.has_text():
+                self._drafts[str(self._contact.jid)] = self.get_text()
+            else:
+                self._drafts.pop(str(self._contact.jid), None)
+
+        self.clear()
+        draft = self._drafts.get(str(contact.jid))
+        if draft is not None:
+            self.insert_text(draft)
+
+        self._contact = contact
         self._chat_action_processor.switch_contact(contact)
 
     def _on_destroy(self, _widget: Gtk.Widget) -> None:



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/68181443efd0314102e794da0fe841a723594238

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/68181443efd0314102e794da0fe841a723594238
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
Commits@gajim.org
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to