@@ -6,6 +6,14 @@ class Keyboard {
6
6
const layout = JSON . parse ( require ( "fs" ) . readFileSync ( opts . layout , { encoding : "utf-8" } ) ) ;
7
7
const container = document . getElementById ( opts . container ) ;
8
8
9
+ this . linkedToTerm = true ;
10
+ this . detach = ( ) => {
11
+ this . linkedToTerm = false ;
12
+ } ;
13
+ this . attach = ( ) => {
14
+ this . linkedToTerm = true ;
15
+ } ;
16
+
9
17
// Set default keyboard properties
10
18
container . dataset . isShiftOn = false ;
11
19
container . dataset . isCapsLckOn = false ;
@@ -886,13 +894,42 @@ class Keyboard {
886
894
break ;
887
895
}
888
896
} else if ( cmd === "\n" ) {
889
- window . term [ window . currentTerm ] . writelr ( "" ) ;
890
- } else if ( cmd === ctrlseq [ 19 ] && window . term [ window . currentTerm ] . term . hasSelection ( ) ) {
897
+ if ( window . keyboard . linkedToTerm ) {
898
+ window . term [ window . currentTerm ] . writelr ( "" ) ;
899
+ } else {
900
+ // Do nothing, return not accepted in inputs
901
+ }
902
+ } else if ( cmd === ctrlseq [ 19 ] && window . keyboard . linkedToTerm && window . term [ window . currentTerm ] . term . hasSelection ( ) ) {
891
903
window . term [ window . currentTerm ] . clipboard . copy ( ) ;
892
- } else if ( cmd === ctrlseq [ 20 ] && window . term [ window . currentTerm ] . clipboard . didCopy ) {
904
+ } else if ( cmd === ctrlseq [ 20 ] && window . keyboard . linkedToTerm && window . term [ window . currentTerm ] . clipboard . didCopy ) {
893
905
window . term [ window . currentTerm ] . clipboard . paste ( ) ;
894
906
} else {
895
- window . term [ window . currentTerm ] . write ( cmd ) ;
907
+ if ( window . keyboard . linkedToTerm ) {
908
+ window . term [ window . currentTerm ] . write ( cmd ) ;
909
+ } else {
910
+ if ( typeof document . activeElement . value !== "undefined" ) {
911
+ switch ( cmd ) {
912
+ case "" :
913
+ document . activeElement . value = document . activeElement . value . slice ( 0 , - 1 ) ;
914
+ break ;
915
+ case "OD" :
916
+ document . activeElement . selectionStart -- ;
917
+ document . activeElement . selectionEnd = document . activeElement . selectionStart ;
918
+ break ;
919
+ case "OC" :
920
+ document . activeElement . selectionEnd ++ ;
921
+ document . activeElement . selectionStart = document . activeElement . selectionEnd ;
922
+ break ;
923
+ default :
924
+ if ( ctrlseq . indexOf ( cmd . slice ( 0 , 1 ) ) !== - 1 ) {
925
+ // Prevent trying to write other control sequences
926
+ } else {
927
+ document . activeElement . value = document . activeElement . value + cmd ;
928
+ }
929
+ }
930
+ }
931
+ document . activeElement . focus ( ) ;
932
+ }
896
933
}
897
934
} ;
898
935
@@ -917,7 +954,7 @@ class Keyboard {
917
954
} ) ;
918
955
919
956
// Keep focus on the terminal
920
- window . term [ window . currentTerm ] . term . focus ( ) ;
957
+ if ( window . keyboard . linkedToTerm ) window . term [ window . currentTerm ] . term . focus ( ) ;
921
958
922
959
window . audioManager . beep2 . play ( ) ;
923
960
e . preventDefault ( ) ;
@@ -958,7 +995,7 @@ class Keyboard {
958
995
pressKey ( key ) ;
959
996
960
997
// Keep focus on the terminal
961
- window . term [ window . currentTerm ] . term . focus ( ) ;
998
+ if ( window . keyboard . linkedToTerm ) window . term [ window . currentTerm ] . term . focus ( ) ;
962
999
963
1000
window . audioManager . beep3 . play ( ) ;
964
1001
e . preventDefault ( ) ;
0 commit comments