Skip to content

Commit 7355f00

Browse files
committed
Fixed problems on Android with Samsung keyboard's too-rapid autorepeat.
1 parent aa450e5 commit 7355f00

6 files changed

Lines changed: 18 additions & 18 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svc-ng",
3-
"version": "1.4.7",
3+
"version": "1.4.8",
44
"license": "MIT AND GPL-3.0-or-later",
55
"author": "Kerry Shetline <kerry@shetline.com>",
66
"scripts": {

src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="about-dialog">
33
<img src="/assets/resources/svc_lunar_eclipse.png" alt="lunar eclipse" width="64" height="64">
44
<h2>Sky View Café NP</h2>
5-
Version 1.4.7<br><br>
5+
Version 1.4.8<br><br>
66
Copyright © 2016-2018 Kerry Shetline.
77
</div>
88
</p-dialog>

src/app/widgets/ks-sequence-editor/ks-sequence-editor.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div><canvas #canvas tabindex="0" contenteditable="true"
22
(mousedown)="onMouseDown($event)" (mouseup)="onMouseUp() " (click)="onClick($event)"
3-
(keydown)="onKeyDown($event)" (keyup)="onKeyUp($event)" (keypress)="onKeyPress($event)"
3+
(keydown)="onKeyDown($event)" (keyup)="onKeyUp()" (keypress)="onKeyPress($event)"
44
(focus)="onFocus(true)" (blur)="onFocus(false)"
55
(touchstart)="onTouchStart($event)" (touchmove)="onTouchMove($event)" (touchend)="onTouchEnd($event)"
66
[@displayState]="displayState" (@displayState.start)="onAnimate()"

src/app/widgets/ks-sequence-editor/ks-sequence-editor.component.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ export interface SequenceItemInfo {
3636
sizing?: string | string[];
3737
}
3838

39-
const NAVIGATION_KEYS = ['Backspace', 'Enter', ' ', 'ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'];
40-
4139
const KEY_REPEAT_DELAY = 500;
4240
const KEY_REPEAT_RATE = 100;
4341
const WARNING_DURATION = 5000;
@@ -83,7 +81,7 @@ const DEFAULT_BORDER_COLOR = '#D8D8D8';
8381
styleUrls: ['./ks-sequence-editor.component.scss']
8482
})
8583
export class KsSequenceEditorComponent implements AfterViewInit, OnInit, OnDestroy {
86-
private static lastKeydown = 0;
84+
private static lastKeyTimestamp = 0;
8785
private static lastKeyKey = '';
8886
private static useHiddenInput = isAndroid();
8987
private static addFocusOutline = isEdge() || isIE() || isIOS();
@@ -216,7 +214,7 @@ export class KsSequenceEditorComponent implements AfterViewInit, OnInit, OnDestr
216214

217215
this.hiddenInput.addEventListener('keydown', event => this.onKeyDown(event));
218216
this.hiddenInput.addEventListener('keypress', event => this.onKeyPress(event));
219-
this.hiddenInput.addEventListener('keyup', event => this.onKeyUp(event));
217+
this.hiddenInput.addEventListener('keyup', () => this.onKeyUp());
220218
this.hiddenInput.addEventListener('input', () => this.onInput());
221219
this.hiddenInput.addEventListener('focus', () => this.onHiddenInputFocus(true));
222220
this.hiddenInput.addEventListener('blur', () => this.onHiddenInputFocus(false));
@@ -609,39 +607,40 @@ export class KsSequenceEditorComponent implements AfterViewInit, OnInit, OnDestr
609607
// for legitimately separate keystrokes, so repeated timestamps have to be expected and allowed there.
610608
//
611609
if (KsSequenceEditorComponent.checkForRepeatedKeyTimestamps &&
612-
(abs(event.timeStamp - KsSequenceEditorComponent.lastKeydown) <= FALSE_REPEAT_THRESHOLD &&
610+
(abs(event.timeStamp - KsSequenceEditorComponent.lastKeyTimestamp) <= FALSE_REPEAT_THRESHOLD &&
613611
key === KsSequenceEditorComponent.lastKeyKey)) {
614612
event.preventDefault();
615613

616614
return false;
617615
}
618616

619-
KsSequenceEditorComponent.lastKeydown = event.timeStamp;
620-
KsSequenceEditorComponent.lastKeyKey = key;
621-
622617
// In at least one version of Android many key events carry no useful information about the key that was
623618
// pressed. They instead match the following test and we have to grab a character out of the hidden
624619
// input field to find out what was actually typed in.
625620
if (this.hiddenInput && key === 'Unidentified' && event.keyCode === 229) {
626621
this.getCharFromInputEvent = true;
622+
KsSequenceEditorComponent.lastKeyTimestamp = event.timeStamp;
627623

628624
return true;
629625
}
630626

631627
if (key === 'Tab' || event.altKey || event.ctrlKey || event.metaKey)
632628
return true;
633629

634-
this.onKey(key);
635-
636-
if (NAVIGATION_KEYS.includes(key) && !this.keyTimer)
630+
// If the built-in auto-repeat is in effect, ignore keystrokes that come along until that auto-repeat ends.
631+
if (!this.keyTimer) {
632+
this.onKey(key);
637633
this.keyTimer = timer(KEY_REPEAT_DELAY, KEY_REPEAT_RATE).subscribe(() => this.onKey(key));
634+
}
638635

639636
event.preventDefault();
637+
KsSequenceEditorComponent.lastKeyTimestamp = event.timeStamp;
638+
KsSequenceEditorComponent.lastKeyKey = key;
640639

641640
return false;
642641
}
643642

644-
onKeyUp(event: KeyboardEvent): boolean {
643+
onKeyUp(): boolean {
645644
this.stopKeyTimer();
646645

647646
return true;
@@ -670,9 +669,8 @@ export class KsSequenceEditorComponent implements AfterViewInit, OnInit, OnDestr
670669
}
671670

672671
protected onKey(key: string): void {
673-
if (this.disabled || this.viewOnly || !this.hasFocus || !this.items[this.selection].editable) {
672+
if (this.disabled || this.viewOnly || !this.hasFocus || !this.items[this.selection].editable)
674673
return;
675-
}
676674

677675
if (this.selection !== this.signDigit) {
678676
if (key === '-')

src/assets/about.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
<h2 class="header-sans"><a name="history">What's New / Version History</a></h2>
6161
<div style="padding-left: 1em; text-indent: -1em">
6262

63+
<p><b>1.4.8, 2018-07-30:</b> Fixed problems with one keyboard's too-rapid autorepeat.</p>
64+
6365
<p><b>1.4.7, 2018-07-30:</b> Made pointing with a tablet pen work. Cleaned up console errors.</p>
6466

6567
<p><b>1.4.6, 2018-07-29:</b> Early steps at making SVC more mobile tablet-friendly. Improved info marquee.</p>

0 commit comments

Comments
 (0)