You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.



You are here: Editor project page > Ender HTML Typing Rules

Ender HTML Typing Rules

The document on writing new rule sets is here.

Here is the current thinking on the typing rules for the HTML editor. Note that these are different from the Plaintext editor rules, and there may someday be yet another flavor of editor rules for a a more style-savvy editor. The purpose of these editor rules are to give a word processing feel to the user editing HTML documents, such as in a mail compose window.

Space Rules:

"Word" refers to any run of non-whitespace characters. All sorts of things count as non-whitespace characters, including inline images and &nbsp's. Whitespace is a space, tab, or newline (plus a funky zero-width whitespace character).

Selection State Results
collapsed; in a block with style white-space: pre; space inserted
collapsed; in the middle of a word space inserted
collapsed; after a word and before whitespace &nbsp inserted
collapsed; after whitespace before a word existing space replaced with nbsp+space
collapsed; surrounded by whitespace &nbsp inserted
non-collapsed delete the selection range(s) and obtain a collapsed selection, then same as above
not covered by above space inserted

Tab Rules:

In the tab rules, N is the tab width, which is based on a user pref.

Selection State Results
collapsed; in a table cell other than the last set selection to next table cell
collapsed; in the last table cell insert new table row and set selection to first cell in last row
collapsed; in a block with style white-space: pre; tab inserted
collapsed; in the middle of a word insert N-1 &nbsp's followed by a space
collapsed; after a word and before whitespace insert N &nbsp's
collapsed; after whitespace before a word existing space replaced with N &nbsp's+space
collapsed; surrounded by whitespace insert N &nbsp's
non-collapsed; no portion of table selected delete selection then apply collapsed selection rule
non-collapsed; inside single table cell as if collapsed selection in that cell
non-collapsed; not contained in single table cell do nothing
not covered by above insert N &nbsp's

Return rules:

"Block parent" refers to the first ancestor of the node (or the node itself) that has block formatting; in other words, that is not inline. A collapsed selection is assumed for the return rules.

Selection State Results
Block parent has white-space: pre; insert a newline character
Block parent is {OL,UL} close any <li> we are in, insert new <li>
Block parent is <dl> if in <dt>, close <dt> and insert <dd>
if in <dd> insert <br>
else insert a <dt>
Block parent is one of: {H1, ... H6} close block
Block parent is one of: {P, BODY, DIV, NOSCRIPT, BLOCKQUOTE, ADDRESS}
no <br> tags are adjacent to insertion point
insert a <br>
Block parent is <p>
a <br> tag is adjacent to insertion point
remove <br> then split <p>, with contents before insertion point in first <p> and the rest in the second <p>
Block parent is one of {BODY, DIV, NOSCRIPT, BLOCKQUOTE, ADDRESS}
a <br> tag is adjacent to insertion point
remove <br> and insert <p>
not covered by above insert a <br>

Backspace Rules:

A collapsed selection is assumed for the backspace rules.
Note that if I don't mention a tag below, it is considered inline and deletion moves through it (such as the <a> tag, for instance).

Selection State Results
after a &nbsp-space combination (in same block parent) replace &nbsp-space with space
after non-whitespace (in same block parent) delete previous character
after the close of <table> do nothing
between <td>s, or at beginning of <td> do nothing
after close of {HR, IMG, BR, MAP, OBJECT, form element} delete element
after close of {DIV, BLOCKQUOTE, NOSCRIPT, ADDRESS, FORM} pretend you are in same block, i.e., text inside these counts as if it were in your same block for deletion purposes
after </p><p> join <p>s, insert <br>
between two like elements that are one of {H*,LI} join elements
not covered by above do nothing

Forward delete rules will be similar to backspace rules (only deleting forwards, of course).

If you backspace/delete completely through an inline block, that block will be removed. But the editor will remember the "typing style" of your cursor location, so if you backspace up to the last character of, say, a <b> tag, but no further, and then type again, the <b> will be reinserted and text you type will be bold (modulo your style sheet).

The HTML editor is not style sheet savvy and no plans are made for any of the typing rules to use style to make rules decisions except for the determination of the white-space: pre; style.