Skip to content

Commit 96f80f7

Browse files
orinemrsdmike
authored andcommitted
fix: issue 332 - A-Z and space not being sent over SOL
1 parent f220e6f commit 96f80f7

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"root": true,
33
"ignorePatterns": [
4-
"**/*.js"
4+
"**/*.js",
5+
"dist/"
56
],
67
"env": {
78
"es2020": true,

projects/sol/src/lib/sol.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'
22
import { BrowserModule } from '@angular/platform-browser'
3+
import { CommonModule } from '@angular/common'
34
import { HttpClientModule } from '@angular/common/http'
45
import { SolComponent } from './sol.component'
56
import { TerminalComponent } from './terminal/terminal.component'
@@ -11,6 +12,7 @@ import { TerminalComponent } from './terminal/terminal.component'
1112
],
1213
imports: [
1314
HttpClientModule,
15+
CommonModule,
1416
BrowserModule
1517
],
1618
exports: [

projects/sol/src/lib/terminal/terminal.component.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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'
33
@Component({
44
selector: 'amt-terminal',
55
templateUrl: './terminal.component.html'
@@ -17,15 +17,23 @@ export class TerminalComponent implements OnInit {
1717
})
1818
this.term.attachCustomKeyEventHandler((e: any) => {
1919
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+
}
2937
}
3038
})
3139
}

0 commit comments

Comments
 (0)