Text Editor

Line numbers

Line numbers are 'counted' when opening the page, when you have stopped typing for 1 second, or when the window is resized. They should account for Firefox-style word wrap but will not account for variable width fonts or wider unicode characters.

Goto line number

Does what it says, passing line=123 in the query string works too (as in error in <a href="edit/file?line=123">file on line 123</a>).

Auto indent

Press return after {, (, [, :, or an opening HTML tag and the new line will be indented.

Auto unindent

Type }, case (followed by a space), default:, else:, elseif (followed by a space), endif;, endwhile;, endfor;, endforeach;, endswitch; or </ on a line preceded only by white space and the line will be unindented.

Maintain indent level

Except where indenting (see above) when pressing return white space from the beginning of the previous line is copied to the new line to keep things aligned. Press shift+return to prevent the new line from indenting.

Multi-line comment markers

If you press return after a line beginning with /* the new line will have * (followed by a space) at the start aligned with the line above. Return after a line with */ will unindent if appropriate, return after a line with * */ will change that line to */ and unindent the next line. Press shift+return to only add a new line.

Tab

If the capture tab key box is checked pressing the tab key will insert upto 4 spaces (not a tab) instead of moving to the next field.

Block indent/unident

If the capture tab key box is checked, select a block of text and press tab to indent or shift+tab to unindent.

Home key

Pressing home will move to the beginning of the non-white space characters on the current line, or the beginning of the line if already there.

Backspace

Backspace after white space at the start of a line will unindent the line.

Tag List

Insert commonly used text, or wrap around a selection.

Find and Replace

Search for or replace text, using plain text, regular expressions, or wildcards.

F3

Select text and press ctrl+F3 to set search text and find next match, F3 to find next match, shift+F3 to find previous match. This will wrap around at the start or end of the text.

Ctrl+f

Focus on the find input box.

Ctrl+g

Goto line prompt.

Ctrl+u

Make selected text uppercase.

Ctrl+shift+u

Make selected text lowercase.

Browser Support

Tested with Firefox/1.5 on Linux, since that is what I use. Should work on other operating systems. Line numbers mostly work in MSIE6, nothing else does. Other browsers have not been tested.

Interferes With

Undo, some of the time. Tab key navigation if the capture tab key box is checked (shift+tab with no text selected still works).

Usage

You will need texteditor.js, texteditor.css and tab_remove.png.

<script type="text/javascript" src="texteditor.js"></script>
<link rel="stylesheet" type="text/css" href="texteditor.css" />
...
<body onload="textEditor('fcontents')">
...
<textarea name="contents" id="fcontents" rows="30" cols="60"></textarea>

Names, IDs and sizes as you see fit.