This repository was archived by the owner on Feb 6, 2023. It is now read-only.
Commit 9a9ccbd
formatPastedText prop
Summary:
A missing use case for draft i've ran into a couple times is that when text is pasted, there are ways to override the default paste handler and do your own thing. Overriding the default paste handler means you have to manage your own fragment, have logic to handle html potentially, and then insert the blocks you generate in the proper place relative to the cursor and selection. More often than not, this seems overkill?
An example: (and the reason I'm posting this RFC) is that i'm trying to turn leading tabs into spaces when pasting markdown lists, since they can't be parsed. Users can't actually _type_ a tab so this is only a problem on pastes. Reimplementing the paste handler for this is doable but using the proposed method, it's implementation becomes a oneliner.
## Precedent
There's some precedent to this type of handler. `blockRendererFn` and `blockStyleFn` both plug into a similar way, overriding the default implementation.
Then `handlePastedText` of course works similarly and I decided to copy its signature, when it comes to naming all `handle*` functions return a handle, which is not what we want in this case.
## Q's
Handling html might be a bit smelly? it is doable but you really don't wanna transform raw html to raw html, at that point you do wanna replace the paste handler.
What I've done is that it's the responsibility of `formatPastedText` to pass the html result through or eat it up and return undefined, formatting only the static text.
I'd be cool with just assuming that if `formatPastedText` exists, we ignore `html` automatically, and that simplifies the signature
Reviewed By: claudiopro
Differential Revision: D22574367
fbshipit-source-id: afe1fac1bb11328e354805161cf9489a77245eff1 parent 862a5b2 commit 9a9ccbd
File tree
2 files changed
+20
-4
lines changed- src/component
- base
- handlers/edit
2 files changed
+20
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
84 | 88 | | |
85 | 89 | | |
86 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
| 97 | + | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
101 | 109 | | |
102 | 110 | | |
103 | 111 | | |
| |||
118 | 126 | | |
119 | 127 | | |
120 | 128 | | |
121 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
122 | 134 | | |
123 | 135 | | |
124 | 136 | | |
125 | | - | |
| 137 | + | |
126 | 138 | | |
127 | 139 | | |
128 | 140 | | |
| |||
0 commit comments