views:

76

answers:

1

I am trying to write a simple text editor in a browser. What I am currently stuck on is when a user clicks to change the mouse position, how can I get the index in the string of the new position?

Example:

User types:

Hello World!

My name is John.

Currently cursor is after the period after John. What I would like to be able to do is get the index of the cursor when the user tries to append more after the ! in Hello World!.

I am trying to do this to check for number of tabs currently used in the line so when the user presses enter, the correct number of tabs can be applied to the beginning of the string.

Thank you,

Jordan

A: 

I think this jQuery plugin can provide all the information you need: http://laboratorium.0xab.cd/jquery/fieldselection/0.1.0/test.html

The plugin code looks very simple and nicely written, maybe you can start from there...

Jasperdc