Question

Say I have the following text:

this is some example c|ode

The pipe symbol is where the cursor is in a nicEditor div. nicEditor has a function to get the position of the cursor "getRng()".

However getRng() doesn't get the position of the cursor including HTML, and as far as I can see no such function exists (correct me if I'm wrong).

The code in the nicEditor div might actually be:

<span style='font-weig|ht: bold;'>this i</span>s some example code

You can see my problem. I'm trying to insert something into the nicEditor div and it gets inserted into the middle of a HTML tag.

My question is this: Is there a way to convert the position of the cursor with the HTML tags included? Or is there any other alternative solution?

Was it helpful?

Solution

I worked it out in the end, it wasn't an easy solution. I had to write a state machine which has four states "Text"=>"HTML"=>"String"=>"Character". Basically I wrote jQuery plugin which takes the string and the position and shifts accordingly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top