mirror of
https://github.com/Yvee1/hascard.git
synced 2024-11-22 04:33:06 +03:00
Show open question answer after double enter
The Shift+Tab keybinding was not reliable and there are few good keybindings available. Therefore, we switch to a different approach: show the correct answer(s) when submitting empty answer(s) (which is not correct) or submitting the same answer(s) twice in a row.
This commit is contained in:
parent
d72365b5d4
commit
eec0551772
@ -103,6 +103,7 @@ data CardState =
|
|||||||
, _entered :: Bool
|
, _entered :: Bool
|
||||||
, _correctGaps :: Map Int Bool
|
, _correctGaps :: Map Int Bool
|
||||||
, _failed :: Bool
|
, _failed :: Bool
|
||||||
|
, _previousInput :: Map Int String
|
||||||
}
|
}
|
||||||
| ReorderState
|
| ReorderState
|
||||||
{ _highlighted :: Int
|
{ _highlighted :: Int
|
||||||
@ -124,7 +125,8 @@ defaultCardState OpenQuestion{perforated=perf} = OpenQuestionState
|
|||||||
, _number = nGapsInPerforated perf
|
, _number = nGapsInPerforated perf
|
||||||
, _entered = False
|
, _entered = False
|
||||||
, _correctGaps = M.fromList [(i, False) | i <- [0..nGapsInPerforated perf - 1]]
|
, _correctGaps = M.fromList [(i, False) | i <- [0..nGapsInPerforated perf - 1]]
|
||||||
, _failed = False }
|
, _failed = False
|
||||||
|
, _previousInput = M.empty }
|
||||||
defaultCardState MultipleAnswer{options=opts} = MultipleAnswerState
|
defaultCardState MultipleAnswer{options=opts} = MultipleAnswerState
|
||||||
{ _highlighted = 0
|
{ _highlighted = 0
|
||||||
, _selected = M.fromList [(i, False) | i <- [0..NE.length opts-1]]
|
, _selected = M.fromList [(i, False) | i <- [0..NE.length opts-1]]
|
||||||
|
@ -45,7 +45,7 @@ drawInfo s = if not (s ^. showControls) then emptyWidget else
|
|||||||
DefinitionState {} -> ", Enter: flip card / continue"
|
DefinitionState {} -> ", Enter: flip card / continue"
|
||||||
MultipleChoiceState {} -> ", Enter: submit answer / continue"
|
MultipleChoiceState {} -> ", Enter: submit answer / continue"
|
||||||
MultipleAnswerState {} -> ", Enter: select / continue, c: submit selection"
|
MultipleAnswerState {} -> ", Enter: select / continue, c: submit selection"
|
||||||
OpenQuestionState {} -> ", Left/Right/Tab: navigate gaps, Enter: submit answer / continue, Shift+Tab: show answer"
|
OpenQuestionState {} -> ", Left/Right/Tab: navigate gaps, Enter: submit answer / continue"
|
||||||
ReorderState {} -> ", Enter: grab, c: submit answer"
|
ReorderState {} -> ", Enter: grab, c: submit answer"
|
||||||
|
|
||||||
drawCardBox :: Widget Name -> Widget Name
|
drawCardBox :: Widget Name -> Widget Name
|
||||||
@ -358,15 +358,11 @@ handleEvent (VtyEvent e) =
|
|||||||
|
|
||||||
correctlyAnswered = NE.toList (NE.map isOptionCorrect opts) == map snd (M.toAscList kvs)
|
correctlyAnswered = NE.toList (NE.map isOptionCorrect opts) == map snd (M.toAscList kvs)
|
||||||
|
|
||||||
(OpenQuestionState {_highlighted = i, _number = n, _gapInput = kvs, _correctGaps = cGaps, _failed=fail}, OpenQuestion _ _ perforated) ->
|
(OpenQuestionState {_highlighted = i, _number = n, _gapInput = kvs, _correctGaps = cGaps, _failed=fail, _previousInput = pkvs}, OpenQuestion _ _ perforated) ->
|
||||||
|
let frozen = M.foldr (&&) True cGaps
|
||||||
|
down = scroll s 1
|
||||||
|
up = scroll s (-1) in
|
||||||
case ev of
|
case ev of
|
||||||
V.EvKey (V.KChar '\t') [V.MShift] -> zoom (cs.cardState) $ do
|
|
||||||
gapInput .= correctAnswers
|
|
||||||
entered .= True
|
|
||||||
failed .= True
|
|
||||||
correctGaps .= M.fromAscList [(i, True) | i <- [0..n-1]]
|
|
||||||
where correctAnswers = M.fromAscList $ zip [0..] $ map NE.head (sentenceToGaps (perforatedToSentence perforated))
|
|
||||||
|
|
||||||
V.EvKey (V.KChar '\t') [] -> zoom (cs.cardState) $ do
|
V.EvKey (V.KChar '\t') [] -> zoom (cs.cardState) $ do
|
||||||
if i < n - 1 && not frozen
|
if i < n - 1 && not frozen
|
||||||
then highlighted += 1
|
then highlighted += 1
|
||||||
@ -397,7 +393,7 @@ handleEvent (VtyEvent e) =
|
|||||||
_ -> return ()
|
_ -> return ()
|
||||||
|
|
||||||
V.EvKey V.KEnter [] -> case (frozen, fail) of
|
V.EvKey V.KEnter [] -> case (frozen, fail) of
|
||||||
(False, _) -> zoom cs $ do
|
(False, _) -> zoom (cs.cardState) $ do
|
||||||
let sentence = perforatedToSentence perforated
|
let sentence = perforatedToSentence perforated
|
||||||
gaps = sentenceToGaps sentence
|
gaps = sentenceToGaps sentence
|
||||||
|
|
||||||
@ -406,11 +402,23 @@ handleEvent (VtyEvent e) =
|
|||||||
then elem
|
then elem
|
||||||
else (\word possibilites -> map toLower word `elem` NE.map (map toLower) possibilites)
|
else (\word possibilites -> map toLower word `elem` NE.map (map toLower) possibilites)
|
||||||
|
|
||||||
cardState.correctGaps %= M.mapWithKey (\j _ -> M.findWithDefault "" j kvs `wordIsCorrect` (gaps !! j))
|
allEmpty = all null kvs
|
||||||
cardState.entered .= True
|
sameAsPrevious = kvs == pkvs
|
||||||
|
|
||||||
unlessM (M.foldr (&&) True <$> use (cardState.correctGaps)) $
|
correctGaps %= M.mapWithKey (\j _ -> M.findWithDefault "" j kvs `wordIsCorrect` (gaps !! j))
|
||||||
cardState.failed .= True
|
entered .= True
|
||||||
|
|
||||||
|
allCorrect <- M.foldr (&&) True <$> use correctGaps
|
||||||
|
|
||||||
|
when (allEmpty && not allCorrect || sameAsPrevious) $ do
|
||||||
|
let correctAnswers = M.fromAscList $ zip [0..] $ map NE.head (sentenceToGaps (perforatedToSentence perforated))
|
||||||
|
correctGaps .= M.fromAscList [(i, True) | i <- [0..n-1]]
|
||||||
|
gapInput .= correctAnswers
|
||||||
|
|
||||||
|
unless allCorrect $
|
||||||
|
failed .= True
|
||||||
|
|
||||||
|
previousInput .= kvs
|
||||||
|
|
||||||
(_, True) -> next
|
(_, True) -> next
|
||||||
(_, False) -> do
|
(_, False) -> do
|
||||||
@ -424,10 +432,6 @@ handleEvent (VtyEvent e) =
|
|||||||
|
|
||||||
_ -> return ()
|
_ -> return ()
|
||||||
|
|
||||||
where frozen = M.foldr (&&) True cGaps
|
|
||||||
down = scroll s 1
|
|
||||||
up = scroll s (-1)
|
|
||||||
|
|
||||||
(ReorderState {_highlighted = i, _entered = submitted, _grabbed=dragging, _number = n, _order = kvs }, Reorder _ _ elts) ->
|
(ReorderState {_highlighted = i, _entered = submitted, _grabbed=dragging, _number = n, _order = kvs }, Reorder _ _ elts) ->
|
||||||
case ev of
|
case ev of
|
||||||
V.EvKey V.KUp [] -> up
|
V.EvKey V.KUp [] -> up
|
||||||
|
@ -67,6 +67,4 @@ info = unlines
|
|||||||
, ""
|
, ""
|
||||||
, " * Use the c key for confirming reorder questions or multiple choice questions with more than 1 possible answer"
|
, " * Use the c key for confirming reorder questions or multiple choice questions with more than 1 possible answer"
|
||||||
, ""
|
, ""
|
||||||
, " * Use Shift+Tab to show the answers of a open question"
|
|
||||||
, ""
|
|
||||||
, " * Use Ctrl+Left and Ctrl+Right to move to previous and next cards without having to answer them; this is disabled in review mode"]
|
, " * Use Ctrl+Left and Ctrl+Right to move to previous and next cards without having to answer them; this is disabled in review mode"]
|
||||||
|
Loading…
Reference in New Issue
Block a user