xP: implement Readline's M-b and M-f
This commit is contained in:
parent
b979257c3a
commit
e2ef7d668c
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue