summaryrefslogtreecommitdiff
path: root/xP/public
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-18 00:38:31 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-18 01:10:03 +0200
commitb979257c3a7018d18dd85510663979470cbd3092 (patch)
tree05390bca022b7a5bc859472776d5ea902e8714ae /xP/public
parent840b6467009222f743e3c5ac12c0eaf4090b766f (diff)
downloadxK-b979257c3a7018d18dd85510663979470cbd3092.tar.gz
xK-b979257c3a7018d18dd85510663979470cbd3092.tar.xz
xK-b979257c3a7018d18dd85510663979470cbd3092.zip
xP: implement Readline's M-< and M->
Diffstat (limited to 'xP/public')
-rw-r--r--xP/public/xP.js85
1 files changed, 49 insertions, 36 deletions
diff --git a/xP/public/xP.js b/xP/public/xP.js
index 30491d3..71c1b6e 100644
--- a/xP/public/xP.js
+++ b/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,49 @@ 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)
+ first: (b, textarea) => {
+ if (b.historyAt <= 0)
return false
- if (b.historyAt > 0) {
- if (b.historyAt == b.history.length)
- b.input = textarea.value
- textarea.value = b.history[--b.historyAt]
- } else {
- beep()
- }
+ if (b.historyAt == b.history.length)
+ b.input = textarea.value
+ textarea.value = b.history[(b.historyAt = 0)]
return true
},
- next: textarea => {
- let b = buffers.get(bufferCurrent)
- if (b === undefined)
+ last: (b, textarea) => {
+ if (b.historyAt >= b.history.length)
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()
- }
+ 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 +786,33 @@ 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 '<': 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()
},