Skip to content

Commit

Permalink
feat: mark and recall a point
Browse files Browse the repository at this point in the history
  • Loading branch information
ellvix committed Dec 27, 2024
1 parent 631c469 commit a3a3423
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,13 @@ class Constants {

clientToken = null;

/**
* Mark and recall vars. Used to store the current mark and recall state of the chart.
* @type {Array<number>}
* @default Array(10).fill(null)
*/
mark = Array(10).fill(null);

/**
* Stops the autoplay if it is currently running.
*
Expand Down
38 changes: 38 additions & 0 deletions src/js/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,44 @@ class Control {
},
]);

// mark and recall
// mark with M + # (0-9), recall with m + # (0-9)
// available in chart and braille, not review
let lastKeytime = 0;
let lastKey = null;
constants.events.push([
[constants.chart, constants.brailleInput],
'keydown',
function (e) {
// setup
const now = new Date().getTime();
const key = e.key;

// check for keypress within threshold
if (now - lastKeytime < constants.keypressInterval) {
// mark with M
if (lastKey == 'M' && /[0-9]/.test(key)) {
const markIndex = parseInt(key, 10);
constants.mark[markIndex] = JSON.parse(JSON.stringify(position)); // deep copy
display.announceText('Marked position ' + markIndex);
}

// recall with m
if (lastKey == 'm' && /[0-9]/.test(key)) {
const recallIndex = parseInt(key, 10);
if (constants.mark[recallIndex]) {
position = constants.mark[recallIndex];
control.UpdateAll();
}
}
}

// update last key and time
lastKey = key;
lastKeytime = now;
},
]);

// Init a few things
let lastPlayed = '';
if ([].concat(singleMaidr.type).includes('bar')) {
Expand Down

0 comments on commit a3a3423

Please sign in to comment.