xP: implement Readline's M-b and M-f

This commit is contained in:
Přemysl Eric Janouch 2022-09-18 01:09:41 +02:00
parent b979257c3a
commit e2ef7d668c
Signed by: p
GPG Key ID: A0420B94F92B9493

View File

@ -742,6 +742,33 @@ let Input = {
return true 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) => { first: (b, textarea) => {
if (b.historyAt <= 0) if (b.historyAt <= 0)
return false return false
@ -796,6 +823,8 @@ let Input = {
if (hasShortcutModifiers(event)) { if (hasShortcutModifiers(event)) {
handled = true handled = true
switch (event.key) { 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.first(b, textarea); break
case '>': success = Input.last(b, textarea); break case '>': success = Input.last(b, textarea); break
case 'p': success = Input.previous(b, textarea); break case 'p': success = Input.previous(b, textarea); break