Fix the space-clicking behavior

This commit is contained in:
Tessa Kelly 2023-04-05 11:48:56 -06:00
parent 4a928460c8
commit d600027ef5
2 changed files with 37 additions and 3 deletions

View File

@ -576,6 +576,7 @@ saveHinted marker =
_ ->
Highlightable.clearHint highlightable
)
>> trimHighlightableGroups
toggleHinted : Int -> Tool.MarkerModel marker -> List (Highlightable marker) -> List (Highlightable marker)
@ -598,6 +599,30 @@ toggleHinted index marker highlightables =
highlightable
in
List.map (toggle >> Highlightable.clearHint) highlightables
|> trimHighlightableGroups
{-| This removes all-static highlights. We need to track events on static elements,
so that we don't miss mouse events if a user starts or ends a highlight on a space, say,
but we should only persist changes to interactive segments.
It is meant to be called as a clean up after the highlightings have been changed.
-}
trimHighlightableGroups : List (Highlightable marker) -> List (Highlightable marker)
trimHighlightableGroups highlightables =
highlightables
|> List.Extra.groupWhile (\a b -> a.marked == b.marked)
|> List.concatMap (\( h, hs ) -> killOnlyStaticHighlights (h :: hs))
killOnlyStaticHighlights : List (Highlightable marker) -> List (Highlightable marker)
killOnlyStaticHighlights highlightables =
if List.all (\h -> h.type_ == Highlightable.Static) highlightables then
removeHighlights_ highlightables
else
highlightables
{-| Finds the group indexes of the groups which are in the same highlighting as the group index
@ -630,7 +655,12 @@ removeHinted =
{-| -}
removeHighlights : Model marker -> Model marker
removeHighlights model =
{ model | highlightables = List.map (Highlightable.set Nothing) model.highlightables }
{ model | highlightables = removeHighlights_ model.highlightables }
removeHighlights_ : List (Highlightable m) -> List (Highlightable m)
removeHighlights_ =
List.map (Highlightable.set Nothing)
{-| You are not likely to need this helper unless you're working with inline commenting.

View File

@ -32,14 +32,18 @@ mouseTests : List Test
mouseTests =
[ test "clicking on a static element does nothing" <|
\() ->
[ Highlightable.initStatic [] 0 "Pothos", Highlightable.initInteractive [] 1 "Philodendron" ]
[ Highlightable.init Highlightable.Static [] 0 ( [], "Pothos" )
, Highlightable.init Highlightable.Interactive [] 1 ( [], "Philodendron" )
]
|> program { markerName = Nothing, joinAdjacentInteractiveHighlights = False }
|> click "Pothos"
|> ensureViewHasNot [ Selector.tag "mark" ]
|> done
, test "starting a highlight from a static element works" <|
\() ->
[ Highlightable.initStatic [] 0 "Pothos", Highlightable.initInteractive [] 1 "Philodendron" ]
[ Highlightable.init Highlightable.Static [] 0 ( [], "Pothos" )
, Highlightable.init Highlightable.Interactive [] 1 ( [], "Philodendron" )
]
|> program { markerName = Nothing, joinAdjacentInteractiveHighlights = False }
|> mouseDown "Philodendron"
|> mouseUp "Pothos"