Re:Show HN: Gemini-Powered Contextual Text Editor with Inlin...
by ShaggyHotDog on Tuesday December 24, 2024 @12:52AM
(#42499976)
That is impressive, any examples that I can see, maybe something you followed or learned from?
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.