Adds joinAdjacentInteractiveHighlights to API

This commit is contained in:
Tessa Kelly 2023-01-09 13:15:06 -07:00
parent 0ea1137510
commit 11494ec179
3 changed files with 14 additions and 2 deletions

View File

@ -11,6 +11,7 @@ module Nri.Ui.Highlighter.V2 exposing
{-| Changes from V1:
- Remove emptyIntent, which is not used
- adds setting for joining adjacent interactive highlights of the same type
Highlighter provides a view/model/update to display a view to highlight text and show marks.
@ -79,6 +80,7 @@ type alias Model marker =
id : String
, highlightables : List (Highlightable marker) -- The actual highlightable elements
, marker : Tool.Tool marker -- Currently used marker
, joinAdjacentInteractiveHighlights : Bool
-- Internal state to track user's interactions
, mouseDownIndex : Maybe Int
@ -103,17 +105,22 @@ type Initialized
{-| Setup initial model
joinAdjacentInteractiveHighlights - When true, and static highlightables are sandwiched by highlighted interactive highlightables of the same type, apply the highlight to the static highlightable as well.
-}
init :
{ id : String
, highlightables : List (Highlightable marker)
, marker : Tool.Tool marker
, joinAdjacentInteractiveHighlights : Bool
}
-> Model marker
init config =
{ id = config.id
, highlightables = config.highlightables
, marker = config.marker
, joinAdjacentInteractiveHighlights = config.joinAdjacentInteractiveHighlights
, mouseDownIndex = Nothing
, mouseOverIndex = Nothing
, isInitialized = NotInitialized

View File

@ -343,6 +343,7 @@ initHighlighter settings previousHighlightables =
else
highlightables
, marker = settings.tool
, joinAdjacentInteractiveHighlights = settings.joinAdjacentInteractiveHighlights
}
@ -356,6 +357,7 @@ exampleParagraph =
type alias Settings =
{ splitOnSentences : Bool
, joinAdjacentInteractiveHighlights : Bool
, asMarkdown : Bool
, tool : Tool.Tool ()
}
@ -365,6 +367,7 @@ controlSettings : Control Settings
controlSettings =
Control.record Settings
|> Control.field "splitOnSentences" (Control.bool True)
|> Control.field "joinAdjacentInteractiveHighlights" (Control.bool False)
|> Control.field "asMarkdown" (Control.bool True)
|> Control.field "tool"
(Control.choice

View File

@ -5,7 +5,7 @@ import Expect exposing (Expectation)
import Html.Styled exposing (toUnstyled)
import Nri.Ui.Colors.V1 as Colors
import Nri.Ui.Highlightable.V1 as Highlightable exposing (Highlightable)
import Nri.Ui.Highlighter.V1 as Highlighter
import Nri.Ui.Highlighter.V2 as Highlighter
import Nri.Ui.HighlighterTool.V1 as Tool exposing (Tool)
import ProgramTest exposing (..)
import Regex exposing (Regex)
@ -18,7 +18,7 @@ import Test.Html.Selector as Selector
spec : Test
spec =
describe "Nri.Ui.Highlighter.V1"
describe "Nri.Ui.Highlighter.V2"
[ describe "keyboard behavior" keyboardTests
, describe "markdown behavior" markdownTests
]
@ -249,6 +249,7 @@ markdownTests =
{ id = "markdown-tests-highlighter-container"
, highlightables = highlightables
, marker = marker Nothing
, joinAdjacentInteractiveHighlights = False
}
, update = \_ m -> m
, view = view >> toUnstyled
@ -442,6 +443,7 @@ program name highlightables =
{ id = "test-highlighter-container"
, highlightables = highlightables
, marker = marker name
, joinAdjacentInteractiveHighlights = False
}
, update =
\msg model ->