> Nice work - it almost solves the problem for me.  Would you have some
> thoughts on how I find the current cursor position in the text area?

I wrote a plugin to allow keyboard shortcuts while editing a tiddler a
while back [1]; it uses jQuery to get the textarea as a DOM element,
which has the properties selectionStart and selectionEnd. These give
the position of selected text in characters relative to the textare
text (value property) and are the same if nothing is selected.

So, for example, suppose the textarea contains "Now is | time" and you
want to insert "the" at the cursor position and reposition the cursor
after it:

var domEl = jQuery('textarea').get(0);
var cStart = domEl.selectionStart;
var cEnd = domEl.selectionEnd;
var newText = domEl.value.substring(0,cStart) + "the";
newText += domEl.value.substring(cEnd);
domEl.value = newText;
cEnd += 3;
domEl.setSelectionRange(cEnd,cEnd);

Hope that helps,
Jon

[1] http://twkeys.tiddlyspace.com

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/tiddlywikidev?hl=en.

Reply via email to