@@ -6,9 +6,8 @@ module DOM.Util.TextCursor
66 , isCursor , cursorAtStart , cursorAtEnd
77 , isSelection , selectionAtStart , selectionAtEnd
88 , selectAll , moveCursorToStart , moveCursorToEnd
9- , appendLeft , appendRight
109 , modifySelected , modifyAll
11- , insert
10+ , appendl , appendr , insert
1211 ) where
1312
1413import Prelude
@@ -114,12 +113,8 @@ _after = _Newtype <<< prop (SProxy :: SProxy "after")
114113
115114-- | Lens for traversing/setting all three fields.
116115_all :: Traversal' TextCursor String
117- _all = wander trav
118- where
119- -- Monomorphic traverse
120- trav :: forall m . Applicative m => (String -> m String ) -> TextCursor -> m TextCursor
121- trav f (TextCursor { before, selected, after }) =
122- mkTextCursor <$> f before <*> f selected <*> f after
116+ _all = wander \f (TextCursor { before, selected, after }) ->
117+ mkTextCursor <$> f before <*> f selected <*> f after
123118
124119-- | Test whether the cursor or selection touches the start.
125120atStart :: TextCursor -> Boolean
@@ -187,14 +182,6 @@ moveCursorToEnd tc = TextCursor
187182 , after: " "
188183 }
189184
190- -- | Prepend a string, on the left.
191- appendLeft :: String -> TextCursor -> TextCursor
192- appendLeft s tc = over _before (s <> _) tc
193-
194- -- | Append a string, on the right.
195- appendRight :: TextCursor -> String -> TextCursor
196- appendRight tc s = over _after (_ <> s) tc
197-
198185-- | Modify just the selected region with an endomorphism.
199186modifySelected :: (String -> String ) -> TextCursor -> TextCursor
200187modifySelected = over _selected
@@ -204,8 +191,17 @@ modifySelected = over _selected
204191modifyAll :: (String -> String ) -> TextCursor -> TextCursor
205192modifyAll = over _all
206193
194+ -- | Prepend a string, on the left.
195+ appendl :: String -> TextCursor -> TextCursor
196+ appendl s tc = over _before (s <> _) tc
197+
198+ -- | Append a string, on the right.
199+ appendr :: TextCursor -> String -> TextCursor
200+ appendr tc s = over _after (_ <> s) tc
201+
207202-- | Insert a string at the cursor position. If text is selected, the insertion
208203-- | will be part of the selection. Otherwise it is inserted before the cursor.
204+ -- Preserves normalization
209205-- check:
210206-- length (insert insertion textcursor)
211207-- == length insertion + length textcursor
0 commit comments