How can I select text and get that selected text using Rangy
? For example, if I want to build a text editor like the one on Stack Overflow, where if I select a piece of text and click the B button, that text is replaced by two asterisks preceding and following the text.
I know that the underlying Javascript must capture the selected text's offset, prepend and append that text by asterisks, and output the new text replacing the previous selected text. How do I accomplish this? The native DOM 3 setSelection
methods provide some functionality, but these are not highly cross-browser-compatible, whereas Rangy
is cross-browser. Unfortunately Rangy's documentation is quite poor.