nsISelection

content/base/public/nsISelection.idlScriptable
??? Add brief description of Interface ???
Inherits from: nsISupports Last changed in Gecko 13.0 (Firefox 13.0 / Thunderbird 13.0 / SeaMonkey 2.10)

Interface for manipulating and querying the current selected range of nodes within the document.

Implemented by: ?????????????????????????????????????. To create an instance, use:

Implemented by: ????????????????????????????????????? as a service:

var selection = Components.classes["@mozilla.org/????????????????????????????"]
                .createInstance(Components.interfaces.nsISelection);

Method overview

void addRange(in nsIDOMRange range);
void collapse(in nsIDOMNode parentNode, in long offset);
[noscript,notxpcom,nostdcall] boolean collapsed();
void collapseNative(in nsIDOMNode parentNode, in long offset); Native code only!
void collapseToEnd();
void collapseToStart();
boolean containsNode(in nsIDOMNode node, in boolean partlyContained);
void deleteFromDocument();
void extend(in nsIDOMNode parentNode, in long offset);
void extendNative(in nsIDOMNode parentNode, in long offset); Native code only!
nsIDOMRange getRangeAt(in long index);
void modify(in DOMString alter, in DOMString direction, in DOMString granularity);
void removeAllRanges();
void removeRange(in nsIDOMRange range);
void selectAllChildren(in nsIDOMNode parentNode);
void selectionLanguageChange(in boolean langRTL);
DOMString toString();

Attributes

Attribute Type Description
anchorNode nsIDOMNode Returns the node in which the selection begins. Read only.
anchorOffset long The offset within the (text) node where the selection begins. Read only.
focusNode nsIDOMNode Returns the node in which the selection ends. Read only.
focusOffset long The offset within the (text) node where the selection ends. Read only.
isCollapsed boolean Indicates if the selection is collapsed() or not. Read only.
rangeCount long Returns the number of ranges in the selection. Read only.

Methods

addRange()

Adds a nsIDOMRange to the current selection.

void addRange(
  in nsIDOMRange range
);
Parameters
range
The nsIDOMRange to add

collapse()

Collapses the selection to a single point, at the specified offset in the given nsIDOMNode. When the selection is collapsed(), and the content is focused and editable, the caret will blink there.

void collapse(
  in nsIDOMNode parentNode,
  in long offset
);
Parameters
parentNode
The given nsIDOMNode where the selection will be set.
offset
Where in the given dom node to place the selection (the offset into the given node).

collapsed()

[noscript,notxpcom,nostdcall] boolean collapsed();

Native code only!

collapseNative

void collapseNative(
  in nsINode parentNode,
  in long offset
);
Parameters
parentNode
offset

collapseToEnd()

Collapses the whole selection to a single point at the end of the current selection (regardless of direction). If content is focused and editable, the caret will blink there.

void collapseToEnd();
Parameters

None

collapseToStart()

Collapses the whole selection to a single point at the start of the current selection (regardless of direction). If content is focused and editable, the caret will blink there.

void collapseToStart();

containsNode()

Indicates whether the nsIDOMNode is part of the selection. If partlyContained is set to PR_TRUE, the function returns true when some part of the node is part of the selection. If partlyContained is set to PR_FALSE, the function only returns true when the entire node is part of the selection.

boolean containsNode(
  in nsIDOMNode node,
  in boolean partlyContained
);
Parameters
node
The nsIDOMNode to look for
partlyContained
If partlyContained is set to PR_FALSE, the function only returns true when the entire node is part of the selection.
Return value

Whether or not the range contains the requested noe.

deleteFromDocument()

Deletes this selection from the document the nodes belong to.

void deleteFromDocument();

extend()

Extends the selection by moving the selection end to the specified nsIDOMNode and offset, preserving the selection begin position. The new selection end result will always be from the anchorNode to the new focusNode, regardless of direction.

void extend(
  in nsIDOMNode parentNode,
  in long offset
);
Parameters
parentNode
The node where the selection will be extended to.
offset
Where in the node to place the offset in the new selection end.

Native code only!

extendNative

void extendNative(
  in nsINode parentNode,
  in long offset
);
Parameters
parentNode
offset

getRangeAt()

Returns the nsIDOMRange at the specified index.

nsIDOMRange getRangeAt(
  in long index
);
Parameters
index
Return value

The nsIDOMRange requested

modify()

Modifies the selection. Note that the parameters are case-insensitive.

void modify(
  in DOMString alter,
  in DOMString direction,
  in DOMString granularity
);
Parameters
alter
Can be one of { "move", "extend()" }
direction
Can be one of { "forward", "backward", "left", "right" }
granularity
Can be one of { "character", "word", "line", "lineboundary" }

removeAllRanges()

Removes all nsIDOMRanges from the current selection.

void removeAllRanges();
Parameters

None

removeRange()

Removes a range from the current selection.

void removeRange(
  in nsIDOMRange range
);
Parameters
range

selectAllChildren()

Adds all children of the specified node to the selection.

void selectAllChildren(
  in nsIDOMNode parentNode
);
Parameters
parentNode
The parent of the children to be added to the selection.

selectionLanguageChange()

Modifies the cursor Bidi level after a change in keyboard direction.

void selectionLanguageChange(
  in boolean langRTL
);
Parameters
langRTL
Is PR_TRUE if the new language is right-to-left or PR_FALSE if the new language is left-to-right.

toString()

Returns the whole selection into a plain text string.

DOMString toString();

Remarks

 

See also