1
1
import { Component , Input , OnInit , Output , EventEmitter } from '@angular/core'
2
- import { C , V , SPACE } from '@angular/cdk/keycodes'
2
+ import { C , V } from '@angular/cdk/keycodes'
3
3
@Component ( {
4
4
selector : 'amt-terminal' ,
5
5
templateUrl : './terminal.component.html'
@@ -17,15 +17,23 @@ export class TerminalComponent implements OnInit {
17
17
} )
18
18
this . term . attachCustomKeyEventHandler ( ( e : any ) => {
19
19
e . stopPropagation ( )
20
- e . preventDefault ( )
21
- if ( e . ctrlKey === true && e . shiftKey === true && e . keyCode === C ) {
22
- return navigator . clipboard . writeText ( this . term . getSelection ( ) )
23
- } else if ( e . ctrlKey === true && e . shiftKey === true && e . keyCode === V ) {
24
- return navigator . clipboard . readText ( ) . then ( text => {
25
- this . handleKeyPress . emit ( text )
26
- } )
27
- } else if ( e . code === SPACE ) {
28
- return this . handleKeyPress . emit ( e . key )
20
+ // Due to a new 'HACK' in xtermjs, calling e.preventDefault() here
21
+ // results in all upper case charaters being dropped,
22
+ // so only call it if we 'consume' the keydown here.
23
+ // Note: this function can be called for 'keypress' and 'keyup' events as well as 'keydown' events
24
+ if ( e . type === 'keydown' ) {
25
+ if ( e . ctrlKey === true && e . shiftKey === true && e . keyCode === C ) {
26
+ e . preventDefault ( )
27
+ return navigator . clipboard . writeText ( this . term . getSelection ( ) )
28
+ } else if ( e . ctrlKey === true && e . shiftKey === true && e . keyCode === V ) {
29
+ e . preventDefault ( )
30
+ return navigator . clipboard . readText ( ) . then ( text => {
31
+ this . handleKeyPress . emit ( text )
32
+ } )
33
+ } else if ( e . code === 'Space' ) { // or e.keyCode === SPACE
34
+ e . preventDefault ( )
35
+ this . handleKeyPress . emit ( e . key )
36
+ }
29
37
}
30
38
} )
31
39
}
0 commit comments