miso
Copyright(C) 2016-2026 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Native.Element.Text.Method

Description

 
Synopsis

Methods

setTextSelection :: MisoString -> SetTextSelection -> action -> (MisoString -> action) -> Effect context props model action Source #

https://lynxjs.org/api/elements/built-in/text.html#setTextSelection

This method sets the selected text based on start and end positions and controls the visibility of selection handles. The response res contains:

data Action = SetText | TextSet | SetTextError MisoString

update :: Action -> Effect props model Action
update = \case
  SetText -> setTextSelection "someImageId" SetText SetTextError
  TextSet -> io_ (consoleLog "text was set")
  SetTextError e -> io_ (consoleLog e)

getTextBoundingRect :: MisoString -> GetTextBoundingRect -> (JSVal -> action) -> (MisoString -> action) -> Effect context props model action Source #

https://lynxjs.org/api/elements/built-in/text.html#gettextboundingrect

This method retrieves the bounding box of a specific range of text.

data Action = RectReceived Rect | GetRect | GotError MisoString

update :: Action -> Effect props model Action
update = \case
  GetRect -> getTextBoundingRect "#box" defaultGetTextBoundingRect RectReceived GotError
  RectReceived rect -> io_ $ consoleLog ("got rect")
  GotError errMsg -> io_ (consoleLog errMsg)

getSelectedText :: MisoString -> (MisoString -> action) -> (MisoString -> action) -> Effect context props model action Source #

https://lynxjs.org/api/elements/built-in/text.html#getselectedtext

This method retrieves the string content of the currently selected text.

data Action = TextReceived MisoString | GetText | GotError MisoString

update :: Action -> Effect props model Action
update = \case
  GetText -> getSelectedText "#box" TextReceived GotError
  TextReceived txt -> io_ (consoleLog ("got text: " <> txt))
  GotError errMsg -> io_ (consoleLog errMsg)

Types

data SetTextSelection Source #

Constructors

SetTextSelection 

Fields

  • startX :: Double

    X/Y-coordinate of the selection start relative to the element

  • startY :: Double

    X/Y-coordinate of the selection start relative to the element

  • endX :: Double

    X/Y-coordinate of the selection end relative to the element

  • endY :: Double

    X/Y-coordinate of the selection end relative to the element

  • showStartHandle :: Bool

    Whether to show or hide the start/end handle

  • showEndHandle :: Bool

    Whether to show or hide the start/end handle

Instances

Instances details
ToJSVal SetTextSelection Source # 
Instance details

Defined in Miso.Native.Element.Text.Method

Smart constructors

defaultGetTextBoundingRect :: GetTextBoundingRect Source #