@@ -3,13 +3,37 @@ import { Button, Text } from "../components";
33import { useTranslation } from "../hooks" ;
44import { memo , useState } from "react" ;
55
6+ const GLFW_KEY_ENTER = 257 ;
7+
68const TestPage = memo ( ( ) => {
79 const { t } = useTranslation ( ) ;
810 const [ singleLineValue , setSingleLineValue ] = useState ( "你尴尬Say个Hi 没位坐下来" ) ;
911 const [ multiLineValue , setMultiLineValue ] = useState (
1012 "你的影子被日落拉长\n思念在很远的地方\n喔喔喔喔 轻轻的唱年少的轻狂\nAabcd1234567890!@#$%^&*()_+"
1113 ) ;
1214 const [ focusState , setFocusState ] = useState ( "none" ) ;
15+ const [ singleLineSubmitValue , setSingleLineSubmitValue ] = useState ( "" ) ;
16+ const [ multiLineSubmitValue , setMultiLineSubmitValue ] = useState ( "" ) ;
17+
18+ const handleSingleLineKeyDown = ( key : number ) => {
19+ if ( key !== GLFW_KEY_ENTER ) {
20+ return false ;
21+ }
22+ setSingleLineSubmitValue ( singleLineValue ) ;
23+ return true ;
24+ } ;
25+
26+ const handleMultiLineKeyDown = (
27+ key : number ,
28+ _shiftKey : boolean ,
29+ ctrlKey : boolean ,
30+ ) => {
31+ if ( key !== GLFW_KEY_ENTER || ! ctrlKey ) {
32+ return false ;
33+ }
34+ setMultiLineSubmitValue ( multiLineValue ) ;
35+ return true ;
36+ } ;
1337
1438 return (
1539 < flex maxHeight = { 500 } enableScrolling >
@@ -40,6 +64,7 @@ const TestPage = memo(() => {
4064 height = { 34 }
4165 fontSize = { 14 }
4266 onChange = { setSingleLineValue }
67+ onKeyDown = { handleSingleLineKeyDown }
4368 onFocus = { ( ) => setFocusState ( "single" ) }
4469 onBlur = { ( ) => setFocusState ( "none" ) }
4570 />
@@ -54,11 +79,14 @@ const TestPage = memo(() => {
5479 caretColor = "#ff00ff"
5580 multiline
5681 onChange = { setMultiLineValue }
82+ onKeyDown = { handleMultiLineKeyDown }
5783 onFocus = { ( ) => setFocusState ( "multi" ) }
5884 onBlur = { ( ) => setFocusState ( "none" ) }
5985 />
6086 < Text fontSize = { 13 } fontWeight = { 900 } > Focused: { focusState } </ Text >
6187 < Text fontSize = { 13 } > Single line value: { singleLineValue } </ Text >
88+ < Text fontSize = { 13 } > Single enter submit: { singleLineSubmitValue || "(empty)" } </ Text >
89+ < Text fontSize = { 13 } > Multi Ctrl+Enter submit: { multiLineSubmitValue || "(empty)" } </ Text >
6290 </ flex >
6391
6492 < flex >
0 commit comments