1
1
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:
Yvee1 2024-10-27 19:51:13 +01:00
parent d72365b5d4
commit eec0551772
3 changed files with 25 additions and 21 deletions

View File

@ -103,6 +103,7 @@ data CardState =
, _entered :: Bool
, _correctGaps :: Map Int Bool
, _failed :: Bool
, _previousInput :: Map Int String
}
| ReorderState
{ _highlighted :: Int
@ -124,7 +125,8 @@ defaultCardState OpenQuestion{perforated=perf} = OpenQuestionState
, _number = nGapsInPerforated perf
, _entered = False
, _correctGaps = M.fromList [(i, False) | i <- [0..nGapsInPerforated perf - 1]]
, _failed = False }
, _failed = False
, _previousInput = M.empty }
defaultCardState MultipleAnswer{options=opts} = MultipleAnswerState
{ _highlighted = 0
, _selected = M.fromList [(i, False) | i <- [0..NE.length opts-1]]

View File

@ -45,7 +45,7 @@ drawInfo s = if not (s ^. showControls) then emptyWidget else
DefinitionState {} -> ", Enter: flip card / continue"
MultipleChoiceState {} -> ", Enter: submit answer / continue"
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"
drawCardBox :: Widget Name -> Widget Name
@ -358,15 +358,11 @@ handleEvent (VtyEvent e) =
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
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
if i < n - 1 && not frozen
then highlighted += 1
@ -397,7 +393,7 @@ handleEvent (VtyEvent e) =
_ -> return ()
V.EvKey V.KEnter [] -> case (frozen, fail) of
(False, _) -> zoom cs $ do
(False, _) -> zoom (cs.cardState) $ do
let sentence = perforatedToSentence perforated
gaps = sentenceToGaps sentence
@ -406,11 +402,23 @@ handleEvent (VtyEvent e) =
then elem
else (\word possibilites -> map toLower word `elem` NE.map (map toLower) possibilites)
cardState.correctGaps %= M.mapWithKey (\j _ -> M.findWithDefault "" j kvs `wordIsCorrect` (gaps !! j))
cardState.entered .= True
allEmpty = all null kvs
sameAsPrevious = kvs == pkvs
unlessM (M.foldr (&&) True <$> use (cardState.correctGaps)) $
cardState.failed .= True
correctGaps %= M.mapWithKey (\j _ -> M.findWithDefault "" j kvs `wordIsCorrect` (gaps !! j))
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
(_, False) -> do
@ -424,10 +432,6 @@ handleEvent (VtyEvent e) =
_ -> 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) ->
case ev of
V.EvKey V.KUp [] -> up

View File

@ -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 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"]