From 0739e62cf073974e21ed8c989a2d1229823f678b Mon Sep 17 00:00:00 2001 From: xmcp Date: Sun, 10 Mar 2019 16:22:19 +0800 Subject: [PATCH] add keyboard shortcut and clear flag --- src/Common.js | 15 +++++++++++++-- src/Title.js | 11 ++++++++--- src/UserAction.js | 24 ++++++++++++++++++++---- src/flows_api.js | 2 +- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/Common.js b/src/Common.js index fe03856..e9f5cc2 100644 --- a/src/Common.js +++ b/src/Common.js @@ -70,10 +70,12 @@ export class SafeTextarea extends Component { text: window.TEXTAREA_BACKUP[props.id]||'', }; this.on_change_bound=this.on_change.bind(this); + this.on_keydown_bound=this.on_keydown.bind(this); this.clear=this.clear.bind(this); this.area_ref=React.createRef(); - this.change_callback=props.on_change; + this.change_callback=props.on_change||(()=>{}); this.change_callback(this.state.text); + this.submit_callback=props.on_submit||(()=>{}); } componentWillUnmount() { @@ -87,6 +89,12 @@ export class SafeTextarea extends Component { }); this.change_callback(event.target.value); } + on_keydown(event) { + if(event.key==='Enter' && event.ctrlKey && !event.altKey) { + event.preventDefault(); + this.submit_callback(); + } + } clear() { this.setState({ @@ -102,10 +110,13 @@ export class SafeTextarea extends Component { get() { return this.state.text; } + focus() { + this.area_ref.current.focus(); + } render() { return ( -