on master help sign in
When looking at input for an event, don't look too deep.
commitbb55988f033515a947be0e91677f9a22210d6248 authorDmitry Ivanov <ethercrow@gmail.com> dateMon 22 Sep 2014, 02:44 (12 years ago) parent6ba874c
1 file changed+2−1
src/Graphics/Vty/Input/Classify.hs+2−1
src/Graphics/Vty/Input/Classify.hs+2−1
@@ -30,6 +30,7 @@ compile :: ClassifyMap -> [Char] -> KClass
3030compile table = cl' where
3131 -- take all prefixes and create a set of these
3232 prefixSet = S.fromList $ concatMap (init . inits . fst) $ table
33+ maxValidInputLength = maximum (map (length . fst) table)
3334 eventForInput = M.fromList table
3435 cl' [] = Prefix
3536 cl' inputBlock = case M.lookup inputBlock eventForInput of
@@ -45,7 +46,7 @@ compile table = cl' where
4546 -- H: There will always be one match. The prefixSet contains, by definition, all
4647 -- prefixes of an event.
4748 False ->
48− let inputPrefixes = reverse $ tail $ inits inputBlock
49+ let inputPrefixes = reverse $ take maxValidInputLength $ tail $ inits inputBlock
4950 in case mapMaybe (\s -> (,) s `fmap` M.lookup s eventForInput) inputPrefixes of
5051 (s,e) : _ -> Valid e (drop (length s) inputBlock)
5152 -- neither a prefix or a full event.