Compare commits
2 Commits
840b646700
...
e2ef7d668c
Author | SHA1 | Date | |
---|---|---|---|
e2ef7d668c | |||
b979257c3a |
114
xP/public/xP.js
114
xP/public/xP.js
@ -692,7 +692,7 @@ let Input = {
|
||||
textarea.selectionStart, textarea.selectionEnd, textarea.value]
|
||||
},
|
||||
|
||||
complete: textarea => {
|
||||
complete: (b, textarea) => {
|
||||
if (textarea.selectionStart !== textarea.selectionEnd)
|
||||
return false
|
||||
|
||||
@ -726,7 +726,7 @@ let Input = {
|
||||
return true
|
||||
},
|
||||
|
||||
submit: textarea => {
|
||||
submit: (b, textarea) => {
|
||||
rpc.send({
|
||||
command: 'BufferInput',
|
||||
bufferName: bufferCurrent,
|
||||
@ -736,41 +736,76 @@ let Input = {
|
||||
// b.history[b.history.length] is virtual, and is represented
|
||||
// either by textarea contents when it's currently being edited,
|
||||
// or by b.input in all other cases.
|
||||
let b = buffers.get(bufferCurrent)
|
||||
b.history.push(textarea.value)
|
||||
b.historyAt = b.history.length
|
||||
textarea.value = ''
|
||||
return true
|
||||
},
|
||||
|
||||
previous: textarea => {
|
||||
let b = buffers.get(bufferCurrent)
|
||||
if (b === undefined)
|
||||
backward: (b, textarea) => {
|
||||
if (textarea.selectionStart !== textarea.selectionEnd)
|
||||
return false
|
||||
|
||||
if (b.historyAt > 0) {
|
||||
if (b.historyAt == b.history.length)
|
||||
b.input = textarea.value
|
||||
textarea.value = b.history[--b.historyAt]
|
||||
} else {
|
||||
beep()
|
||||
}
|
||||
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
|
||||
},
|
||||
|
||||
next: textarea => {
|
||||
let b = buffers.get(bufferCurrent)
|
||||
if (b === undefined)
|
||||
forward: (b, textarea) => {
|
||||
if (textarea.selectionStart !== textarea.selectionEnd)
|
||||
return false
|
||||
|
||||
if (b.historyAt < b.history.length) {
|
||||
if (++b.historyAt == b.history.length)
|
||||
textarea.value = b.input
|
||||
else
|
||||
textarea.value = b.history[b.historyAt]
|
||||
} else {
|
||||
beep()
|
||||
}
|
||||
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
|
||||
|
||||
if (b.historyAt == b.history.length)
|
||||
b.input = textarea.value
|
||||
textarea.value = b.history[(b.historyAt = 0)]
|
||||
return true
|
||||
},
|
||||
|
||||
last: (b, textarea) => {
|
||||
if (b.historyAt >= b.history.length)
|
||||
return false
|
||||
|
||||
b.historyAt = b.history.length
|
||||
textarea.value = b.input
|
||||
return true
|
||||
},
|
||||
|
||||
previous: (b, textarea) => {
|
||||
if (b.historyAt <= 0)
|
||||
return false
|
||||
|
||||
if (b.historyAt == b.history.length)
|
||||
b.input = textarea.value
|
||||
textarea.value = b.history[--b.historyAt]
|
||||
return true
|
||||
},
|
||||
|
||||
next: (b, textarea) => {
|
||||
if (b.historyAt >= b.history.length)
|
||||
return false
|
||||
|
||||
if (++b.historyAt == b.history.length)
|
||||
textarea.value = b.input
|
||||
else
|
||||
textarea.value = b.history[b.historyAt]
|
||||
return true
|
||||
},
|
||||
|
||||
@ -778,28 +813,35 @@ let Input = {
|
||||
// TODO: And perhaps on other actions, too.
|
||||
rpc.send({command: 'Active'})
|
||||
|
||||
let b = buffers.get(bufferCurrent)
|
||||
if (b === undefined)
|
||||
return
|
||||
|
||||
let textarea = event.currentTarget
|
||||
let handled = false
|
||||
let success = true
|
||||
if (hasShortcutModifiers(event)) {
|
||||
handled = true
|
||||
switch (event.key) {
|
||||
case 'p':
|
||||
handled = Input.previous(textarea)
|
||||
break
|
||||
case 'n':
|
||||
handled = Input.next(textarea)
|
||||
break
|
||||
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
|
||||
case 'n': success = Input.next(b, textarea); break
|
||||
default: handled = false
|
||||
}
|
||||
} else if (!event.altKey && !event.ctrlKey && !event.metaKey &&
|
||||
!event.shiftKey) {
|
||||
handled = true
|
||||
switch (event.keyCode) {
|
||||
case 9:
|
||||
handled = Input.complete(textarea)
|
||||
break
|
||||
case 13:
|
||||
handled = Input.submit(textarea)
|
||||
break
|
||||
case 9: success = Input.complete(b, textarea); break
|
||||
case 13: success = Input.submit(b, textarea); break
|
||||
default: handled = false
|
||||
}
|
||||
}
|
||||
if (!success)
|
||||
beep()
|
||||
if (handled)
|
||||
event.preventDefault()
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user