Commit 2a5de574 authored by James Laver's avatar James Laver Committed by Alexandre Delanoë

Add Gargantext.Utils.Selection for working with Text Selection

parent 55e38627
exports._getSelection = function() { return window.getSelection() || null; };
exports._toString = function(thing) { return thing.toString(); };
module Gargantext.Utils.Selection
( class ToString, Selection, toString, getSelection ) where
import Prelude ((<$>))
import Data.Maybe (Maybe)
import Data.Nullable (Nullable, toMaybe)
import Effect (Effect)
-- | Represents a text selection
foreign import data Selection :: Type
-- foreign import data Range :: Type -- Probably coming soon
-- toString
class ToString t
instance toStringSelection :: ToString Selection
-- instance toStringRange :: ToString Range
foreign import _toString :: forall t. t -> String
-- | Renders a selection or range as a string
toString :: forall t. ToString t => t -> String
toString = _toString
-- getSelection
foreign import _getSelection :: Effect (Nullable Selection)
-- | Fetches the current text selection, if any
getSelection :: Effect (Maybe Selection)
getSelection = toMaybe <$> _getSelection
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment