support Home, End and Del keys (#87)

* add Home and End keys

* support Delete key

* simplify updateTermState
This commit is contained in:
Evgeny Poberezkin 2021-04-10 12:53:22 +01:00 committed by GitHub
parent ee8814dd25
commit a819fcb86b

View File

@ -51,6 +51,9 @@ updateTermState ac tw (key, ms) ts@TerminalState {inputString = s, inputPosition
| otherwise -> ts
TabKey -> insertCharsWithContact " "
BackspaceKey -> backDeleteChar
DeleteKey -> deleteChar
HomeKey -> setPosition 0
EndKey -> setPosition $ length s
ArrowKey d -> case d of
Leftwards
| ms == mempty -> setPosition $ max 0 (p - 1)
@ -85,10 +88,12 @@ updateTermState ac tw (key, ms) ts@TerminalState {inputString = s, inputPosition
Nothing -> ""
backDeleteChar
| p == 0 || null s = ts
| p >= length s = ts' backDeleteLast
| otherwise = ts' backDelete
backDeleteLast = if null s then (s, 0) else let s' = init s in (s', length s')
backDelete = let (b, a) = splitAt p s in (init b <> a, p - 1)
| p >= length s = ts' (init s, length s - 1)
| otherwise = let (b, a) = splitAt p s in ts' (init b <> a, p - 1)
deleteChar
| p >= length s || null s = ts
| p == 0 = ts' (tail s, 0)
| otherwise = let (b, a) = splitAt p s in ts' (b <> tail a, p)
setPosition p' = ts' (s, p')
prevWordPos
| p == 0 || null s = p