enter in textarea handled

This commit is contained in:
Ozbolt Menegatti 2020-03-19 21:28:43 +01:00
parent 417ac55fda
commit 6438cf52d1
2 changed files with 10 additions and 1 deletions

View File

@ -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

View File

@ -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