Skip to content

Commit a96ddd2

Browse files
authored
feat: mark and recall a point (#626)
1 parent 631c469 commit a96ddd2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/js/constants.js

+7
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,13 @@ class Constants {
654654

655655
clientToken = null;
656656

657+
/**
658+
* Mark and recall vars. Used to store the current mark and recall state of the chart.
659+
* @type {Array<number>}
660+
* @default Array(10).fill(null)
661+
*/
662+
mark = Array(10).fill(null);
663+
657664
/**
658665
* Stops the autoplay if it is currently running.
659666
*

src/js/controls.js

+38
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,44 @@ class Control {
548548
},
549549
]);
550550

551+
// mark and recall
552+
// mark with M + # (0-9), recall with m + # (0-9)
553+
// available in chart and braille, not review
554+
let lastKeytime = 0;
555+
let lastKey = null;
556+
constants.events.push([
557+
[constants.chart, constants.brailleInput],
558+
'keydown',
559+
function (e) {
560+
// setup
561+
const now = new Date().getTime();
562+
const key = e.key;
563+
564+
// check for keypress within threshold
565+
if (now - lastKeytime < constants.keypressInterval) {
566+
// mark with M
567+
if (lastKey == 'M' && /[0-9]/.test(key)) {
568+
const markIndex = parseInt(key, 10);
569+
constants.mark[markIndex] = JSON.parse(JSON.stringify(position)); // deep copy
570+
display.announceText('Marked position ' + markIndex);
571+
}
572+
573+
// recall with m
574+
if (lastKey == 'm' && /[0-9]/.test(key)) {
575+
const recallIndex = parseInt(key, 10);
576+
if (constants.mark[recallIndex]) {
577+
position = constants.mark[recallIndex];
578+
control.UpdateAll();
579+
}
580+
}
581+
}
582+
583+
// update last key and time
584+
lastKey = key;
585+
lastKeytime = now;
586+
},
587+
]);
588+
551589
// Init a few things
552590
let lastPlayed = '';
553591
if ([].concat(singleMaidr.type).includes('bar')) {

0 commit comments

Comments
 (0)