The goog.dom.SavedCaretRange Class

goog.dom.SavedCaretRange
> goog.dom.SavedRange
> goog.Disposable

goog.dom.SavedCaretRange(range)

A struct for holding context about saved selections. This can be used to preserve the selection and restore while the DOM is manipulated, or through an asynchronous call. Use goog.dom.Range factory methods to obtain an {@see goog.dom.AbstractRange} instance, and use {@see goog.dom.AbstractRange#saveUsingCarets} to obtain a SavedCaretRange. For editor ranges under content-editable elements or design-mode iframes, prefer using {@see goog.editor.range.saveUsingNormalizedCarets}.

range {goog.dom.AbstractRange}
The range being saved.

.CARET_REGEX {RegExp}

A regex that will match all saved range carets in a string.

.addOnDisposeCallback(callback, opt_scope)

Inherited from goog.Disposable .

Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.

callback {!Function}
The callback function.
opt_scope {Object=}
An optional scope to call the callback in.

.creationStack {string}

Inherited from goog.Disposable .

If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.

.dispose()

Inherited from goog.Disposable .

Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.

returns {void}
Nothing.

.getCaret(start)

Gets carets.

start {boolean}
If true, returns the start caret. Otherwise, get the end caret.
returns {Element}
The start or end caret in the given document.

.htmlEqual(str1, str2)

Returns whether two strings of html are equal, ignoring any saved carets. Thus two strings of html whose only difference is the id of their saved carets will be considered equal, since they represent html with the same selection.

str1 {string}
The first string.
str2 {string}
The second string.
returns {boolean}
Whether two strings of html are equal, ignoring any saved carets.

.isDisposed()

Inherited from goog.Disposable .

returns {boolean}
Whether the object has been disposed of.

.registerDisposable(disposable)

Inherited from goog.Disposable .

Associates a disposable object with this object so that they will be disposed together.

disposable {goog.disposable.IDisposable}
that will be disposed when this object is disposed.

.removeCarets(opt_range)

Removes the carets from the current restoration document.

opt_range {goog.dom.AbstractRange=}
A range whose offsets have already been adjusted for caret removal; it will be adjusted if it is also affected by post-removal operations, such as text node normalization.
returns {goog.dom.AbstractRange|undefined}
The adjusted range, if opt_range was provided.

.restore(opt_stayAlive)

Inherited from goog.dom.SavedRange .

Restores the range and by default disposes of the saved copy. Take note: this means the by default SavedRange objects are single use objects.

opt_stayAlive {boolean=}
Whether this SavedRange should stay alive (not be disposed) after restoring the range. Defaults to false (dispose).
returns {goog.dom.AbstractRange}
The restored range.

.setRestorationDocument(doc)

Sets the document where the range will be restored.

doc {!Document}
An HTML document.

.toAbstractRange()

Gets the range that this SavedCaretRage represents, without selecting it or removing the carets from the DOM.

returns {goog.dom.AbstractRange?}
An abstract range.