Skip to content

Commit

Permalink
Fixed problems on Android with Samsung keyboard's too-rapid autorepeat.
Browse files Browse the repository at this point in the history
  • Loading branch information
kshetline committed Jul 30, 2018
1 parent aa450e5 commit 7355f00
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svc-ng",
"version": "1.4.7",
"version": "1.4.8",
"license": "MIT AND GPL-3.0-or-later",
"author": "Kerry Shetline <[email protected]>",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="about-dialog">
<img src="/assets/resources/svc_lunar_eclipse.png" alt="lunar eclipse" width="64" height="64">
<h2>Sky View Café NP</h2>
Version 1.4.7<br><br>
Version 1.4.8<br><br>
Copyright © 2016-2018 Kerry Shetline.
</div>
</p-dialog>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div><canvas #canvas tabindex="0" contenteditable="true"
(mousedown)="onMouseDown($event)" (mouseup)="onMouseUp() " (click)="onClick($event)"
(keydown)="onKeyDown($event)" (keyup)="onKeyUp($event)" (keypress)="onKeyPress($event)"
(keydown)="onKeyDown($event)" (keyup)="onKeyUp()" (keypress)="onKeyPress($event)"
(focus)="onFocus(true)" (blur)="onFocus(false)"
(touchstart)="onTouchStart($event)" (touchmove)="onTouchMove($event)" (touchend)="onTouchEnd($event)"
[@displayState]="displayState" (@displayState.start)="onAnimate()"
Expand Down
26 changes: 12 additions & 14 deletions src/app/widgets/ks-sequence-editor/ks-sequence-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ export interface SequenceItemInfo {
sizing?: string | string[];
}

const NAVIGATION_KEYS = ['Backspace', 'Enter', ' ', 'ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'];

const KEY_REPEAT_DELAY = 500;
const KEY_REPEAT_RATE = 100;
const WARNING_DURATION = 5000;
Expand Down Expand Up @@ -83,7 +81,7 @@ const DEFAULT_BORDER_COLOR = '#D8D8D8';
styleUrls: ['./ks-sequence-editor.component.scss']
})
export class KsSequenceEditorComponent implements AfterViewInit, OnInit, OnDestroy {
private static lastKeydown = 0;
private static lastKeyTimestamp = 0;
private static lastKeyKey = '';
private static useHiddenInput = isAndroid();
private static addFocusOutline = isEdge() || isIE() || isIOS();
Expand Down Expand Up @@ -216,7 +214,7 @@ export class KsSequenceEditorComponent implements AfterViewInit, OnInit, OnDestr

this.hiddenInput.addEventListener('keydown', event => this.onKeyDown(event));
this.hiddenInput.addEventListener('keypress', event => this.onKeyPress(event));
this.hiddenInput.addEventListener('keyup', event => this.onKeyUp(event));
this.hiddenInput.addEventListener('keyup', () => this.onKeyUp());
this.hiddenInput.addEventListener('input', () => this.onInput());
this.hiddenInput.addEventListener('focus', () => this.onHiddenInputFocus(true));
this.hiddenInput.addEventListener('blur', () => this.onHiddenInputFocus(false));
Expand Down Expand Up @@ -609,39 +607,40 @@ export class KsSequenceEditorComponent implements AfterViewInit, OnInit, OnDestr
// for legitimately separate keystrokes, so repeated timestamps have to be expected and allowed there.
//
if (KsSequenceEditorComponent.checkForRepeatedKeyTimestamps &&
(abs(event.timeStamp - KsSequenceEditorComponent.lastKeydown) <= FALSE_REPEAT_THRESHOLD &&
(abs(event.timeStamp - KsSequenceEditorComponent.lastKeyTimestamp) <= FALSE_REPEAT_THRESHOLD &&
key === KsSequenceEditorComponent.lastKeyKey)) {
event.preventDefault();

return false;
}

KsSequenceEditorComponent.lastKeydown = event.timeStamp;
KsSequenceEditorComponent.lastKeyKey = key;

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

return true;
}

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

this.onKey(key);

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

event.preventDefault();
KsSequenceEditorComponent.lastKeyTimestamp = event.timeStamp;
KsSequenceEditorComponent.lastKeyKey = key;

return false;
}

onKeyUp(event: KeyboardEvent): boolean {
onKeyUp(): boolean {
this.stopKeyTimer();

return true;
Expand Down Expand Up @@ -670,9 +669,8 @@ export class KsSequenceEditorComponent implements AfterViewInit, OnInit, OnDestr
}

protected onKey(key: string): void {
if (this.disabled || this.viewOnly || !this.hasFocus || !this.items[this.selection].editable) {
if (this.disabled || this.viewOnly || !this.hasFocus || !this.items[this.selection].editable)
return;
}

if (this.selection !== this.signDigit) {
if (key === '-')
Expand Down
2 changes: 2 additions & 0 deletions src/assets/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
<h2 class="header-sans"><a name="history">What's New / Version History</a></h2>
<div style="padding-left: 1em; text-indent: -1em">

<p><b>1.4.8, 2018-07-30:</b> Fixed problems with one keyboard's too-rapid autorepeat.</p>

<p><b>1.4.7, 2018-07-30:</b> Made pointing with a tablet pen work. Cleaned up console errors.</p>

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

0 comments on commit 7355f00

Please sign in to comment.