@@ -11,6 +11,7 @@ import * as RCM from 'react-codemirror';
11
11
12
12
import './code.css' ;
13
13
14
+ import { getLocString } from '../react-common/locReactSide' ;
14
15
import { Cursor } from './cursor' ;
15
16
import { InputHistory } from './inputHistory' ;
16
17
@@ -22,6 +23,7 @@ export interface ICodeProps {
22
23
readOnly : boolean ;
23
24
history : string [ ] ;
24
25
cursorType : string ;
26
+ showWatermark : boolean ;
25
27
onSubmit ( code : string ) : void ;
26
28
onChangeLineCount ( lineCount : number ) : void ;
27
29
@@ -33,6 +35,7 @@ interface ICodeState {
33
35
cursorTop : number ;
34
36
cursorBottom : number ;
35
37
charUnderCursor : string ;
38
+ allowWatermark : boolean ;
36
39
}
37
40
38
41
export class Code extends React . Component < ICodeProps , ICodeState > {
@@ -43,7 +46,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
43
46
44
47
constructor ( prop : ICodeProps ) {
45
48
super ( prop ) ;
46
- this . state = { focused : false , cursorLeft : 0 , cursorTop : 0 , cursorBottom : 0 , charUnderCursor : '' } ;
49
+ this . state = { focused : false , cursorLeft : 0 , cursorTop : 0 , cursorBottom : 0 , charUnderCursor : '' , allowWatermark : true } ;
47
50
this . history = new InputHistory ( this . props . history ) ;
48
51
}
49
52
@@ -57,6 +60,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
57
60
public render ( ) {
58
61
const readOnly = this . props . testMode || this . props . readOnly ;
59
62
const classes = readOnly ? 'code-area' : 'code-area code-area-editable' ;
63
+ const waterMarkClass = this . props . showWatermark && this . state . allowWatermark && ! readOnly ? 'code-watermark' : 'hide' ;
60
64
return (
61
65
< div className = { classes } >
62
66
< Cursor
@@ -92,6 +96,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
92
96
onFocusChange = { this . onFocusChange }
93
97
onCursorActivity = { this . onCursorActivity }
94
98
/>
99
+ < div className = { waterMarkClass } > { this . getWatermarkString ( ) } </ div >
95
100
</ div >
96
101
) ;
97
102
}
@@ -104,6 +109,10 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
104
109
}
105
110
}
106
111
112
+ private getWatermarkString = ( ) : string => {
113
+ return getLocString ( 'DataScience.inputWatermark' , 'Shift-enter to run' ) ;
114
+ }
115
+
107
116
private onCursorActivity = ( codeMirror : CodeMirror . Editor ) => {
108
117
// Update left/top/char for cursor
109
118
if ( codeMirror ) {
@@ -245,5 +254,6 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
245
254
246
255
private onChange = ( newValue : string , change : CodeMirror . EditorChange ) => {
247
256
this . history . onChange ( ) ;
257
+ this . setState ( { allowWatermark : false } ) ;
248
258
}
249
259
}
0 commit comments