Skip to content

Commit c9de3de

Browse files
author
Nicholas Scheel
authored
Create README.md
1 parent e88eb61 commit c9de3de

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# purescript-textcursor
2+
An isomorphic `TextCursor` type for selections in DOM elements (`<input>` and `<textarea>`). Provides shared DOM methods and TextCursor manipulations.
3+
4+
## Supported elements
5+
All `<textarea>` elements and `<input>` elements with the `type` attribute set to one of the following:
6+
- input (default)
7+
- email
8+
- search
9+
- url
10+
11+
## TextCursor
12+
A `TextCursor` is defined as the following type:
13+
```purescript
14+
newtype TextCursor = TextCursor
15+
{ before :: String
16+
, selected :: String
17+
, after :: String
18+
}
19+
```
20+
21+
It represents a selection in an element in three regions: the text `before` the cursor/selection, the text inside the `selection` (empty if there is just a cursor), and the text `after`.
22+
23+
What this does is allow transformations to occur (such as replacements, white-space simplification) while preserving the relative location of the cursor or selection.
24+
25+
Note that certain transformations will depend on the position of the text cursor or selection within the field, particularly if they rely on a string of characters versus single characters (e.g. a replacement ` ``|'' -> "`, which depends on quote characters being adjacent, as opposed to `[A-Z] -> [a-z]`, which does not care where the cursor falls as it selects a single character without context).

0 commit comments

Comments
 (0)