Dear @timdown ,
I have been able to replicate this problem but wasn't able to setup a plunkr. I will try to come back to create one later.
OS: Max OSX Yosemite
Browser: Chrome 40.0.2214.115 (64-bit)
When there is the following html:
<pre class="code-block lang-javascript ng-scope"><span class="hljs-keyword">var</span> </pre>
when the cursor is at the end of the <pre> block, the getCharacterRanges return position 12 instead of 4.
happens in Chrome.