mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-05 01:17:22 +00:00
Save last input
This commit is contained in:
parent
86d3c67026
commit
944746aad2
1 changed files with 17 additions and 0 deletions
|
|
@ -35,6 +35,7 @@ const keyNames = {
|
||||||
|
|
||||||
export default function ({ currentWindow, inputType, sendMessage }) {
|
export default function ({ currentWindow, inputType, sendMessage }) {
|
||||||
const [inputText, setInputText] = useState('')
|
const [inputText, setInputText] = useState('')
|
||||||
|
const [lastInput, setLastInput] = useState('')
|
||||||
const inputEl = useRef(null)
|
const inputEl = useRef(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -43,6 +44,7 @@ export default function ({ currentWindow, inputType, sendMessage }) {
|
||||||
|
|
||||||
const send = x => {
|
const send = x => {
|
||||||
sendMessage(x, currentWindow)
|
sendMessage(x, currentWindow)
|
||||||
|
setLastInput(x)
|
||||||
setInputText('')
|
setInputText('')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,6 +64,20 @@ export default function ({ currentWindow, inputType, sendMessage }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lineArrowHandler = ({ keyCode }) => {
|
||||||
|
if (keyCode === keyCodes.KEY_UP) {
|
||||||
|
setInputText(lastInput)
|
||||||
|
|
||||||
|
setTimeout(_ => {
|
||||||
|
const end = lastInput.length
|
||||||
|
inputEl.current.setSelectionRange(end, end)
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
if (keyCode === keyCodes.KEY_DOWN) {
|
||||||
|
setInputText('')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const inputHandlers = {
|
const inputHandlers = {
|
||||||
char: {
|
char: {
|
||||||
placeholder: 'Press any key here',
|
placeholder: 'Press any key here',
|
||||||
|
|
@ -69,6 +85,7 @@ export default function ({ currentWindow, inputType, sendMessage }) {
|
||||||
},
|
},
|
||||||
line: {
|
line: {
|
||||||
placeholder: ' > ',
|
placeholder: ' > ',
|
||||||
|
onKeyDown: lineArrowHandler,
|
||||||
onKeyPress: lineHandler
|
onKeyPress: lineHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue