Gernot Frisch wrote:
[snip]
I want to be able to select 3 rows of a textarea, and when pressing
"Tab/shift Tab" indent the source code edited. Can I do this with
JavaScript?
[/snip]
You can, but it would require a bit of work. Further pointers for
research are:-
1. Event handling. You will need to set "onkeypress " (or perhaps
"onkeydown"/"onkeyup") event handlers on the TEXTAREA element to
capture key presses and trigger your JavaScript function.
2. Event object. You will need to research the browser event
object, how it is delivered to/available to a function, and the keyCode
and shiftKey properties, to enable you to detect which keys were
pressed.
3. You will need to override the normal effect of the TAB key event,
as a TAB normally changes focus (Look for IE event.returnVal ue, Firefox
event.preventDe fault()).
4. You will need to research the browser selection model. Each
browser seems to have its own way of handling text selections. For IE
you need to research the "selection" and "TextRange" objects. For
Mozilla and Safari/KHTML - the selectionStart and selectionEnd
properties of the TEXTAREA element. For others, I do not know. I
think Opera is limited in this respect.
5. You will need to write a function to extract the text from the
selection, manipulate the string to add remove tabs, and paste the text
back into the selection.
Of couse, someone alse may have a working script for all of this.
Regards
Julian Turner