title: Any way to highlight current word & sentence in a contentEditable DIV?
body: <p>I have a <code>contentEditable</code> DIV (building a kind of editor component). I am looking for a way to highlight the current word the user is typing and the sentence that word is on. For example, consider the following paragraph:</p>
  
  <pre><code>I am a sample paragraph. I contain words that dont make much sense but are there just to fill the space. I can have only one caret at a time. ...
  </code></pre>
  
  <p>Now if the caret is on the word 'sample' in the first sentence, i want to highlight the word ('sample') and that sentence ('I am a sample paragraph.'). Similarly if the caret is on the word 'sense' in the 2nd sentence, that word itself and the 2nd sentence are to have a highlight and so on.. By highlight, i mean the current sentence to have a light background color, and the current word to have a more prominent background color.</p>
  
  <p>Any techniques to achieve this? I tried separating sentences into <code>&lt;span class="sentence"&gt;..&lt;/span&gt;</code> and words inside each sentence into <code>&lt;span class="word"&gt;..&lt;/span&gt;</code>. But that is just too much of a pain when pasting stuff from clipboard etc. I also thought about finding caret position and traversing back and forth through the whole text to find the current word and current sentence and applying classes on the go etc. but i have a feeling that will make the typing experience sluggish and rather forgettable.</p>
  
  <p>I'm running out of ideas. Any help will be greatly appreciated.</p>
  
  <p>Thank You.</p>