diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2022-09-18 01:09:41 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2022-09-18 01:10:03 +0200 |
commit | e2ef7d668c6d4526ddd1e1e21e60bc0a69e99c2e (patch) | |
tree | 4b05d37d98e320c9b78ba36effa0af976ee856c9 | |
parent | b979257c3a7018d18dd85510663979470cbd3092 (diff) | |
download | xK-e2ef7d668c6d4526ddd1e1e21e60bc0a69e99c2e.tar.gz xK-e2ef7d668c6d4526ddd1e1e21e60bc0a69e99c2e.tar.xz xK-e2ef7d668c6d4526ddd1e1e21e60bc0a69e99c2e.zip |
xP: implement Readline's M-b and M-f
-rw-r--r-- | xP/public/xP.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/xP/public/xP.js b/xP/public/xP.js index 71c1b6e..aa2c39a 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -742,6 +742,33 @@ let Input = { return true }, + backward: (b, textarea) => { + if (textarea.selectionStart !== textarea.selectionEnd) + return false + + let point = textarea.selectionStart + if (point < 1) + return false + while (point && /\s/.test(textarea.value.charAt(--point))) {} + while (point-- && !/\s/.test(textarea.value.charAt(point))) {} + point++ + textarea.setSelectionRange(point, point) + return true + }, + + forward: (b, textarea) => { + if (textarea.selectionStart !== textarea.selectionEnd) + return false + + let point = textarea.selectionStart, len = textarea.value.length + if (point + 1 > len) + return false + while (point < len && /\s/.test(textarea.value.charAt(point))) point++ + while (point < len && !/\s/.test(textarea.value.charAt(point))) point++ + textarea.setSelectionRange(point, point) + return true + }, + first: (b, textarea) => { if (b.historyAt <= 0) return false @@ -796,6 +823,8 @@ let Input = { if (hasShortcutModifiers(event)) { handled = true switch (event.key) { + case 'b': success = Input.backward(b, textarea); break + case 'f': success = Input.forward(b, textarea); break case '<': success = Input.first(b, textarea); break case '>': success = Input.last(b, textarea); break case 'p': success = Input.previous(b, textarea); break |