Save last input

This commit is contained in:
He4eT 2021-03-25 15:41:27 +05:00
commit 944746aad2

View file

@ -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
} }
} }