Note that header line is also included in returned array. Returns data about selection for every rendered line. Why do you need to handle such nuances by yourself when you can just use already working solutions? So, it is what it for.
will give different result than you expect because Google Docs adds special symbols (NBSP, ZWNJ) to display text correctly across different browsers. Also, on further user typing, previous text will be restored while newText will be removed. you can't just change text of element using element.textContent = 'newText', because Google Docs stores current editor state internally. Any events for normal selection will be canceled by Google Docs. Google Docs creates two independent elements: one for text and one for selection overlay. you can't just use window.getSelection() to get selected text. It is good for ensuring that across many different browsers the editor is working as expected, but it makes hard to interact with document programmatically. Google Docs uses its own complex logic for displaying, storing and handling of page elements. Utilities for interaction with Google Docs using JavaScript. Highly unlikely that all existing functionality will be adopted to canvas based rendering.
It is means that all existing functionality will stop working with new canvas based rendering.
This library relies on HTML based rendering. Expected date is around the end of July 2021. Google Docs plans to switch to canvas based rendering instead of HTML based rendering. WARNING: this project may no longer work after July 2021