|
|
|
|
|
by ShaggyHotDog
538 days ago
|
|
I like the subtle editor. What did you use to build the editor? Lexical or TipTap? Also you might want to limit the AI generation (Cost wise) in some way before posting on hacker news, maybe only authenticated user can generate content. |
|
The editor keeps track of the original text and the modified text (not yet accepted text). The rendering starts by calculating the diff between the two texts and building a virtual DOM tree with special markers for changes. Then, cursors and selections are inserted into the virtual DOM, after which the DOM is processed by the markdown parser. The parser converts markdown syntax into formatted DOM elements. Finally, the virtual DOM is diffed against the contenteditable DOM, and the minimal updates are applied. There is some additional logic to handle cursor positioning between the updates and to manage the history.