commit ce0e3626eef7a1869b1499d6056824ac0c7a2755
parent eed7ec41fc66a408e46995e91d9bcc312798d95c
Author: tongong <tongong@gmx.net>
Date: Sat, 15 Jan 2022 20:27:47 +0100
added gesture 10 to delete a character
Diffstat:
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/components/key-boxes.js b/src/components/key-boxes.js
@@ -10,6 +10,9 @@ module.exports = (vnode) => {
let active = [false, false, false];
// contains indizes of pressed key in the order in which they were pressed
let pressed = [];
+ // if there was a point in time during this gesture where all keys were
+ // pressed simultaneously
+ let full = false;
// gestures that are not processed yet
let gestures = [];
return {
@@ -20,6 +23,7 @@ module.exports = (vnode) => {
if (kcb) kcb(e);
if (index != -1) {
active[index] = true;
+ if (active.every(e => e)) full = true;
pressed.push(index);
m.redraw();
}
@@ -30,8 +34,9 @@ module.exports = (vnode) => {
if (index != -1) {
active[index] = false;
if (active.every(e => !e)) {
- gestures.push(input.pressed2gesture(pressed));
+ gestures.push(input.pressed2gesture(pressed, full));
pressed = [];
+ full = false;
let charMaybe = input.gestures2char(gestures);
if (charMaybe) {
icb(charMaybe);
diff --git a/src/components/page-input.js b/src/components/page-input.js
@@ -6,9 +6,11 @@ module.exports = () => {
let written = "> ";
let blind = false;
let oninput = (c) => {
- written += c;
// clear input on "-" -> new bullet point / new thought
if (c == "-") written = "> ";
+ else if (c == input.deletechar)
+ written = written.substring(0, written.length - 1)
+ else written += c;
};
let blindhandler = (e) => {
if (e.key == input.blindkey) blind = !blind;
diff --git a/src/modules/input.js b/src/modules/input.js
@@ -2,9 +2,11 @@
const keys = ["j", "k", "l"];
const hintkey = "h";
const blindkey = "b";
+const deletechar = String.fromCharCode(127);
/* pressed is an array of pressed indizes from one gesture */
-function pressed2gesture(pressed) {
+function pressed2gesture(pressed, full) {
+ if (full) return 10;
if (pressed.length == 1) return pressed[0] + 7;
else {
let m = [
@@ -28,6 +30,8 @@ function gestures2char(gestures) {
return "-";
case 9:
return ".";
+ case 10:
+ return deletechar;
default:
return false;
}
@@ -48,6 +52,7 @@ module.exports = {
keys,
hintkey,
blindkey,
+ deletechar,
pressed2gesture,
gestures2char
}