diff --git a/src/message/simple_messages.py b/src/message/simple_messages.py index 74eb66e..7f63b1f 100644 --- a/src/message/simple_messages.py +++ b/src/message/simple_messages.py @@ -31,6 +31,7 @@ class NoReset(Reset): class KeyboardPress(Message): def on_event(self, event): self.add_arg(event.key) + self.add_arg(event) def reset(self): key = self.get_arg(0, str) @@ -39,11 +40,19 @@ class KeyboardPress(Message): def data_change(self): return False + def _handle_textarea(self): + event = self.get_arg(1) + if event.target["type"] == "textarea": + event.preventDefault(); + def update_model(self, model): key = self.get_arg(0, str) # Enter when modal shown -> press ok button if model.modal_shown and key == "Enter": + # handle textarea as per user wishes + self._handle_textarea() + ok_button = document.getElementById("modal-ok") if ok_button is not None: # has to be called in separate thread diff --git a/src/view/view.py b/src/view/view.py index 2955493..b330660 100644 --- a/src/view/view.py +++ b/src/view/view.py @@ -16,7 +16,7 @@ class View: patch(container, self.vdom) # this does not work on parent div, so attaching to document here - document.addEventListener("keyup", msg(KeyboardPress)) + document.addEventListener("keydown", msg(KeyboardPress)) def view(self, model, data_change): self.model = model