@@ -2,6 +2,57 @@ import { useBackend, useLocalState } from '../backend';
22import { Box , Button , Divider , Input , Tabs , TextArea , Section , Stack } from '../components' ;
33import { Window } from '../layouts' ;
44
5+ // NTSLTextArea component start
6+ // This is literally just TextArea but without ENTER updating anything, for NTSL
7+ import { toInputValue } from '../components/Input' ;
8+ import { KEY_ESCAPE , KEY_TAB } from 'common/keycodes' ;
9+
10+ class NTSLTextArea extends TextArea {
11+ constructor ( props ) {
12+ super ( props ) ;
13+ const { dontUseTabForIndent = false } = props ;
14+ this . handleKeyDown = ( e ) => {
15+ const { editing } = this . state ;
16+ const { onChange, onInput, onEnter, onKey } = this . props ;
17+ if ( e . keyCode === KEY_ESCAPE ) {
18+ if ( this . props . onEscape ) {
19+ this . props . onEscape ( e ) ;
20+ }
21+ this . setEditing ( false ) ;
22+ if ( this . props . selfClear ) {
23+ e . target . value = '' ;
24+ } else {
25+ e . target . value = toInputValue ( this . props . value ) ;
26+ e . target . blur ( ) ;
27+ }
28+ return ;
29+ }
30+ if ( ! editing ) {
31+ this . setEditing ( true ) ;
32+ }
33+ // Custom key handler
34+ if ( onKey ) {
35+ onKey ( e , e . target . value ) ;
36+ }
37+ if ( ! dontUseTabForIndent ) {
38+ const keyCode = e . keyCode || e . which ;
39+ if ( keyCode === KEY_TAB ) {
40+ e . preventDefault ( ) ;
41+ const { value, selectionStart, selectionEnd } = e . target ;
42+ e . target . value =
43+ value . substring ( 0 , selectionStart ) +
44+ '\t' +
45+ value . substring ( selectionEnd ) ;
46+ e . target . selectionEnd = selectionStart + 1 ;
47+ if ( onInput ) {
48+ onInput ( e , e . target . value ) ;
49+ }
50+ }
51+ }
52+ } ;
53+ }
54+ }
55+ // NTSLTextArea component end
556
657export const NtslEditor = ( props , context ) => {
758 // Make sure we don't start larger than 50%/80% of screen width/height.
@@ -34,7 +85,7 @@ const ScriptEditor = (props, context) => {
3485 return (
3586 < Box width = "100%" height = "100%" >
3687 { user_name ?
37- < TextArea
88+ < NTSLTextArea
3889 noborder
3990 scrollbar
4091 value = { stored_code }
0 commit comments