A Selection object represents a document's selection (which could be an insertion point). The special object called Selection always represents the user's selection in the active document. Selection is evaluated dynamically and always takes its value from the current active document. This is true even when it is represented by a variable. For example, if you define:
var sel=Application.Selection;
and a different document becomes active, a reference to sel will return the user's selection in the new active document.
By contrast, a Range object can represent a selection in any open document. The Range interface inherits the Selection interface, so we will regard Range objects as Selection objects also. However, the special Selection object can be considered to be the only `pure' instance of the Selection interface: that is, it is the only Selection object that is not also a Range object.
In the Usage sections, the expression Selection_object refers equally to Selection and Range objects.
Some Selection properties and methods apply to the selection's container. This refers to the markup construct that surrounds the selection: usually this is an element, but can also be a section, processing instruction, or comment. Other properties and methods apply specifically to the current element.
In HoTMetaL PRO 1.0, the Selection interface is used for manipulating selections, but it also provides an interface to many other document-manipulation operations. This is because the DOM objects are read-only in this version of HoTMetaL PRO, and therefore Selection methods are used to modify the document.
However, it is
generally better to use Selection methods with Range
objects when modifying the document's structure (for example, inserting elements) or moving around
in the document. This is because Selection and Range work
differently in the HoTMetaL PRO Normal
view (they work the same in Tags
On
view). In Normal
view, a Selection object can
be placed only where text is allowed: this means that it cannot be placed between tags unless text
is also allowed there. By contrast, Range objects can be placed anywhere in
Normal
view.
Macros that are expected to work the same in the
Normal
and Tags On
views should therefore use
Range objects when moving around, but place the user selection appropriately
at the end of the macro. You may wish to code all of your macros in this way, even if you intend
them to work only in Tags On
view, in case they are later re-purposed for
Normal
view operations.
Copyright © SoftQuad Software Inc. 1999