Skip to content

Commit fb69b65

Browse files
Rewrite modifyAll with traversal _all
1 parent 545a20c commit fb69b65

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/DOM/Util/TextCursor.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module DOM.Util.TextCursor
66
, isCursor, cursorAtStart, cursorAtEnd
77
, isSelection, selectionAtStart, selectionAtEnd
88
, selectAll, moveCursorToStart, moveCursorToEnd
9+
, appendLeft, appendRight
910
, modifySelected, modifyAll
1011
, insert
1112
) where
@@ -173,6 +174,14 @@ moveCursorToEnd tc = TextCursor
173174
, after: ""
174175
}
175176

177+
-- | Prepend a string, on the left.
178+
appendLeft :: String -> TextCursor -> TextCursor
179+
appendLeft s tc = over _before (s <> _) tc
180+
181+
-- | Append a string, on the right.
182+
appendRight :: TextCursor -> String -> TextCursor
183+
appendRight tc s = over _after (_ <> s) tc
184+
176185
-- | Modify just the selected region with an endomorphism.
177186
modifySelected :: (String -> String) -> TextCursor -> TextCursor
178187
modifySelected = over _selected

0 commit comments

Comments
 (0)