Note that there are some explanatory texts on larger screens.

plurals
  1. POKeep caret position in contenteditable after editing the content via jscript
    primarykey
    data
    text
    <p>I've got a contenteditable div which's content is being edited via javascript after each textchange(<a href="http://zurb.com/playground/jquery-text-change-custom-event" rel="nofollow">textchange.js</a>) like adding html tags(only span-tags for changing the color of some words) and adding or removing some whitespaces here and there, but my problem is since the content is being changed while the user is editing it, the caret changes its position after every keypress, which makes it nearly impossible to write a single word. I'm at the moment searching for a way to prevent this jumping around, I've already thought of adding a special char which wouldn't be used anyway as a kind of marker at the position of the caret before editing it, removing it when finished and putting the caret back to this position, but since I'm using regex a lot(currently about 25 times after each textchange) this special character would ruin nearly every single one of them and I would have to add something like <code>\x40?</code> every where, which would not look nice and clear at all:</p> <pre><code>/\s&lt;span class="b0"&gt;hello\sworld&lt;/span&gt;/g </code></pre> <p>to:</p> <pre><code>/\s\x40?&lt;span class="b0"&gt;\x40?h\x40?e\x40?l\x40?l\x40?o\x40?\s\x40?w\x40?o\x40?r\x40?l\x40?d\x40?&lt;/span&gt;/g </code></pre> <p>I don't know if it helps but here is an example on how the content is changed(after each keypress):</p> <pre><code>foo +++ &lt;span class="c3"&gt;bar&lt;/span&gt; - baz -&lt;span class="c0"&gt;qux&lt;/span&gt; </code></pre> <p>to:</p> <pre><code>&lt;span class="c1"&gt;foo&lt;/span&gt; + &lt;span class="c3"&gt;bar&lt;/span&gt; - &lt;span class="c1"&gt;baz&lt;/span&gt; * &lt;span class="c0"&gt;qux&lt;/span&gt; </code></pre> <p>I'd be grateful for every advice, tip or hint on how to solve this problem, or a better way to do this marker-thing.</p> <p>Thank you :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload