File tree Expand file tree Collapse file tree 5 files changed +35
-10
lines changed
src/components/react-web-terminal Expand file tree Collapse file tree 5 files changed +35
-10
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " react-web-terminal" ,
3
- "version" : " 0.2.0 " ,
3
+ "version" : " 0.2.1 " ,
4
4
"description" : " A web-based terminal facade built on reactjs" ,
5
5
"repository" : {
6
6
"type" : " git" ,
Original file line number Diff line number Diff line change @@ -22,14 +22,14 @@ export default class WebTerminalCursor extends React.Component {
22
22
this . setState ( this . state ) ;
23
23
}
24
24
25
- moveLeft ( ) {
25
+ moveLeft ( amount = 1 ) {
26
26
if ( this . state . cursorPos > 0 )
27
- this . setCursorPos ( this . getCursorPos ( ) - 1 ) ;
27
+ this . setCursorPos ( this . getCursorPos ( ) - amount ) ;
28
28
}
29
29
30
- moveRight ( ) {
30
+ moveRight ( amount = 1 ) {
31
31
if ( this . state . cursorPos < this . getInput ( ) . length )
32
- this . setCursorPos ( this . getCursorPos ( ) + 1 ) ;
32
+ this . setCursorPos ( this . getCursorPos ( ) + amount ) ;
33
33
}
34
34
35
35
moveToBegining ( ) {
Original file line number Diff line number Diff line change @@ -13,14 +13,20 @@ export default class WebTerminalInputBuffer extends React.Component {
13
13
}
14
14
15
15
getInput ( ) {
16
- return this . state . input ;
16
+ return this . state . input ;
17
17
}
18
18
19
19
resetInputBuffer ( ) {
20
20
this . state . input = '' ;
21
21
this . cursor . moveToBegining ( ) ;
22
22
}
23
23
24
+ insertText ( text ) {
25
+ this . state . input = this . getPreCursorStr ( ) + text + this . cursor . getCursorChar ( ) + this . getPostCursorStr ( ) ;
26
+ this . cursor . moveRight ( text . length ) ;
27
+ this . setState ( this . state ) ;
28
+ }
29
+
24
30
handleKeyDown ( e ) {
25
31
const key = getKey ( e ) ;
26
32
if ( key === 'Enter' ) {
@@ -36,13 +42,24 @@ export default class WebTerminalInputBuffer extends React.Component {
36
42
} else if ( key === 'ArrowRight' ) {
37
43
this . cursor . moveRight ( ) ;
38
44
this . forceUpdate ( ) ;
45
+ } else if ( navigator . appVersion . indexOf ( 'Mac' ) !== - 1 && e . metaKey && key === 'c' ) {
46
+ return ;
47
+ } else if ( navigator . appVersion . indexOf ( 'Mac' ) !== - 1 && e . metaKey && key === 'v' ) {
48
+ return ;
49
+ } else if ( e . ctrlKey && key === 'c' ) {
50
+ return ;
51
+ } else if ( e . ctrlKey && key === 'v' ) {
52
+ return ;
39
53
} else if ( nonPrintableKeys . indexOf ( key ) === - 1 ) {
40
- this . state . input = this . getPreCursorStr ( ) + key + this . cursor . getCursorChar ( ) + this . getPostCursorStr ( ) ;
41
- this . cursor . moveRight ( ) ;
42
- this . setState ( this . state ) ;
54
+ this . insertText ( key ) ;
43
55
}
44
56
}
45
57
58
+ onPaste ( e ) {
59
+ const pastedText = e . clipboardData . getData ( 'Text' ) ;
60
+ this . insertText ( pastedText ) ;
61
+ }
62
+
46
63
onCommandEntered ( ) {
47
64
if ( this . props . onCommandEntered ) this . props . onCommandEntered ( ) ;
48
65
}
Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ export default class WebTerminalInput extends React.Component {
23
23
this . buffer . handleKeyDown ( e ) ;
24
24
}
25
25
26
+ onPaste ( e ) {
27
+ this . buffer . onPaste ( e ) ;
28
+ }
29
+
26
30
onCommandEntered ( ) {
27
31
if ( this . props . onCommandEntered ) this . props . onCommandEntered ( ) ;
28
32
}
Original file line number Diff line number Diff line change @@ -54,6 +54,10 @@ export default class WebTerminal extends React.Component {
54
54
if ( ! this . keyStrokeMapHandler ( e ) ) this . inputComp . handleKeyDown ( e ) ;
55
55
}
56
56
57
+ onPaste ( e ) {
58
+ this . inputComp . onPaste ( e ) ;
59
+ }
60
+
57
61
onCommandEntered ( ) {
58
62
this . addToLog ( this . inputComp . state . prompt + this . input ( ) , 'react-web-terminal-input' ) ;
59
63
@@ -82,7 +86,7 @@ export default class WebTerminal extends React.Component {
82
86
} ) ;
83
87
84
88
return (
85
- < div tabIndex = "-1" ref = { ( root ) => { this . root = root } } className = "react-web-terminal" onKeyDown = { this . handleKeyDown . bind ( this ) } >
89
+ < div tabIndex = "-1" ref = { ( root ) => { this . root = root } } className = "react-web-terminal" onKeyDown = { this . handleKeyDown . bind ( this ) } onPaste = { this . onPaste . bind ( this ) } >
86
90
{ logNodes }
87
91
< WebTerminalInput ref = { ( input ) => { this . inputComp = input } } prompt = { this . props . prompt } onCommandEntered = { this . onCommandEntered . bind ( this ) } />
88
92
</ div >
You can’t perform that action at this time.
0 commit comments