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

Commits:

1 changed file:

Changes:

  • gajim/gtk/message_input.py
    ... ... @@ -20,6 +20,7 @@
    20 20
     from __future__ import annotations
    
    21 21
     
    
    22 22
     from typing import Any
    
    23
    +from typing import Optional
    
    23 24
     
    
    24 25
     import sys
    
    25 26
     
    
    ... ... @@ -73,6 +74,9 @@ def __init__(self) -> None:
    73 74
             self._undo_list: list[str] = []
    
    74 75
             self.undo_pressed: bool = False
    
    75 76
     
    
    77
    +        self._contact: Optional[ChatContactT] = None
    
    78
    +        self._drafts: dict[str, str] = {}
    
    79
    +
    
    76 80
             self._chat_action_processor = ChatActionProcessor(self)
    
    77 81
     
    
    78 82
             self.get_buffer().create_tag('strong', weight=Pango.Weight.BOLD)
    
    ... ... @@ -88,6 +92,18 @@ def __init__(self) -> None:
    88 92
             self.connect('populate-popup', self._on_populate_popup)
    
    89 93
     
    
    90 94
         def switch_contact(self, contact: ChatContactT) -> None:
    
    95
    +        if self._contact is not None:
    
    96
    +            if self.has_text():
    
    97
    +                self._drafts[str(self._contact.jid)] = self.get_text()
    
    98
    +            else:
    
    99
    +                self._drafts.pop(str(self._contact.jid), None)
    
    100
    +
    
    101
    +        self.clear()
    
    102
    +        draft = self._drafts.get(str(contact.jid))
    
    103
    +        if draft is not None:
    
    104
    +            self.insert_text(draft)
    
    105
    +
    
    106
    +        self._contact = contact
    
    91 107
             self._chat_action_processor.switch_contact(contact)
    
    92 108
     
    
    93 109
         def _on_destroy(self, _widget: Gtk.Widget) -> None: