JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
/*!
|
2012-07-19 00:11:26 +00:00
|
|
|
* VisualEditor Document class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2013-02-19 23:37:34 +00:00
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
2012-07-19 00:11:26 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2012-05-10 04:11:09 +00:00
|
|
|
/**
|
|
|
|
* Generic document.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-10 04:11:09 +00:00
|
|
|
* @class
|
2013-10-15 11:58:04 +00:00
|
|
|
* @mixins OO.EventEmitter
|
2013-05-01 22:21:32 +00:00
|
|
|
*
|
2012-05-10 04:11:09 +00:00
|
|
|
* @constructor
|
2012-09-17 13:30:50 +00:00
|
|
|
* @param {ve.Node} model Model to observe
|
2012-05-10 04:11:09 +00:00
|
|
|
*/
|
2012-10-08 04:12:50 +00:00
|
|
|
ve.Document = function VeDocument( documentNode ) {
|
2013-05-01 22:21:32 +00:00
|
|
|
// Mixin constructors
|
2013-10-15 11:58:04 +00:00
|
|
|
OO.EventEmitter.call( this );
|
2013-05-01 22:21:32 +00:00
|
|
|
|
2012-05-10 04:11:09 +00:00
|
|
|
// Properties
|
|
|
|
this.documentNode = documentNode;
|
|
|
|
};
|
|
|
|
|
2013-03-15 04:03:13 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-15 11:58:04 +00:00
|
|
|
OO.mixinClass( ve.Document, OO.EventEmitter );
|
2013-03-15 04:03:13 +00:00
|
|
|
|
2012-05-10 04:11:09 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the root of the document's node tree.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-10 04:11:09 +00:00
|
|
|
* @method
|
|
|
|
* @returns {ve.Node} Root of node tree
|
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.Document.prototype.getDocumentNode = function () {
|
2012-05-10 04:11:09 +00:00
|
|
|
return this.documentNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a list of nodes and the ranges within them that a selection of the document covers.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-10 04:11:09 +00:00
|
|
|
* @method
|
|
|
|
* @param {ve.Range} range Range within document to select nodes
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} [mode='leaves'] Type of selection to perform:
|
|
|
|
*
|
|
|
|
* - `leaves`: Return all leaf nodes in the given range (descends all the way down)
|
|
|
|
* - `branches`': Return all branch nodes in the given range
|
|
|
|
* - `covered`: Do not descend into nodes that are entirely covered by the range. The result
|
2013-07-25 02:02:50 +00:00
|
|
|
* is similar to that of 'leaves' except that if a node is entirely covered, its
|
|
|
|
* children aren't returned separately.
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* - `siblings`: Return a set of adjacent siblings covered by the range (descends as long as the
|
|
|
|
* range is in a single node)
|
|
|
|
* @returns {Array} List of objects describing nodes in the selection and the ranges therein:
|
|
|
|
*
|
|
|
|
* - `node`: Reference to a ve.dm.Node
|
|
|
|
* - `range`: ve.Range, missing if the entire node is covered
|
|
|
|
* - `index`: Index of the node in its parent, missing if node has no parent
|
|
|
|
* - `indexInNode`: If range is a zero-length range between two children of node,
|
|
|
|
* this is set to the index of the child following range (or to
|
|
|
|
* `node.children.length + 1` if range is between the last child and
|
2013-06-14 01:19:39 +00:00
|
|
|
* the end). If range is a zero-length range inside an empty non-content branch node, this is 0.
|
|
|
|
* Missing in all other cases.
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* - `nodeRange`: Range covering the inside of the entire node, not including wrapper
|
|
|
|
* - `nodeOuterRange`: Range covering the entire node, including wrapper
|
|
|
|
* - `parentOuterRange`: Outer range of node's parent. Missing if there is no parent
|
2013-07-25 02:02:50 +00:00
|
|
|
* or if indexInNode is set.
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
*
|
|
|
|
* @throws {Error} Range.start is out of range
|
|
|
|
* @throws {Error} Range.end is out of range
|
2012-05-10 04:11:09 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.Document.prototype.selectNodes = function ( range, mode ) {
|
2012-07-20 00:24:54 +00:00
|
|
|
var doc = this.documentNode,
|
2012-05-10 04:11:09 +00:00
|
|
|
retval = [],
|
|
|
|
start = range.start,
|
|
|
|
end = range.end,
|
2012-05-10 22:03:23 +00:00
|
|
|
stack = [ {
|
2012-05-10 22:57:58 +00:00
|
|
|
// Node we are currently stepping through
|
|
|
|
// Note each iteration visits a child of node, not node itself
|
2012-05-10 22:03:23 +00:00
|
|
|
'node': doc,
|
2012-05-10 22:57:58 +00:00
|
|
|
// Index of the child in node we're visiting
|
2012-05-10 22:03:23 +00:00
|
|
|
'index': 0,
|
2012-05-10 22:57:58 +00:00
|
|
|
// First offset inside node
|
2012-05-11 03:04:13 +00:00
|
|
|
'startOffset': 0
|
2012-05-10 22:03:23 +00:00
|
|
|
} ],
|
2012-05-10 04:11:09 +00:00
|
|
|
node,
|
|
|
|
prevNode,
|
|
|
|
nextNode,
|
|
|
|
left,
|
|
|
|
right,
|
|
|
|
currentFrame = stack[0],
|
2012-05-10 22:03:23 +00:00
|
|
|
parentFrame,
|
2012-05-10 04:11:09 +00:00
|
|
|
startInside,
|
|
|
|
endInside,
|
|
|
|
startBetween,
|
|
|
|
endBetween,
|
2012-06-04 23:18:29 +00:00
|
|
|
startFound = false,
|
|
|
|
nodeRange,
|
2012-10-19 22:28:26 +00:00
|
|
|
parentRange,
|
2012-10-22 22:52:19 +00:00
|
|
|
isWrapped,
|
|
|
|
isPrevUnwrapped,
|
2013-06-14 01:19:39 +00:00
|
|
|
isNextUnwrapped,
|
|
|
|
isEmptyBranch;
|
2012-05-10 04:11:09 +00:00
|
|
|
|
|
|
|
mode = mode || 'leaves';
|
2012-09-24 13:16:25 +00:00
|
|
|
if ( mode !== 'leaves' && mode !== 'branches' && mode !== 'covered' && mode !== 'siblings' ) {
|
2012-08-08 17:48:53 +00:00
|
|
|
throw new Error( 'Invalid mode: ' + mode );
|
2012-05-10 04:11:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( start < 0 || start > doc.getLength() ) {
|
2012-08-08 17:48:53 +00:00
|
|
|
throw new Error( 'Invalid start offset: ' + start );
|
2012-05-10 04:11:09 +00:00
|
|
|
}
|
|
|
|
if ( end < 0 || end > doc.getLength() ) {
|
2012-08-08 17:48:53 +00:00
|
|
|
throw new Error( 'Invalid end offset: ' + end );
|
2012-05-10 04:11:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !doc.children || doc.children.length === 0 ) {
|
2012-05-10 22:03:23 +00:00
|
|
|
// Document has no children. This is weird
|
2012-06-04 23:18:29 +00:00
|
|
|
nodeRange = new ve.Range( 0, doc.getLength() );
|
2012-05-10 22:03:23 +00:00
|
|
|
return [ {
|
|
|
|
'node': doc,
|
|
|
|
'range': new ve.Range( start, end ),
|
|
|
|
'index': 0,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': nodeRange,
|
|
|
|
'nodeOuterRange': nodeRange
|
2012-05-10 22:03:23 +00:00
|
|
|
} ];
|
2012-05-10 04:11:09 +00:00
|
|
|
}
|
|
|
|
left = doc.children[0].isWrapped() ? 1 : 0;
|
|
|
|
|
2012-05-15 01:44:19 +00:00
|
|
|
do {
|
2012-05-10 04:11:09 +00:00
|
|
|
node = currentFrame.node.children[currentFrame.index];
|
|
|
|
prevNode = currentFrame.node.children[currentFrame.index - 1];
|
|
|
|
nextNode = currentFrame.node.children[currentFrame.index + 1];
|
|
|
|
right = left + node.getLength();
|
|
|
|
// Is the start inside node?
|
|
|
|
startInside = start >= left && start <= right;
|
|
|
|
// Is the end inside node?
|
|
|
|
endInside = end >= left && end <= right;
|
2012-06-04 23:18:29 +00:00
|
|
|
// Does the node have wrapping elements around it
|
|
|
|
isWrapped = node.isWrapped();
|
2012-10-17 23:09:49 +00:00
|
|
|
// Is there an unwrapped node right before this node?
|
|
|
|
isPrevUnwrapped = prevNode ? !prevNode.isWrapped() : false;
|
|
|
|
// Is there an unwrapped node right after this node?
|
|
|
|
isNextUnwrapped = nextNode ? !nextNode.isWrapped() : false;
|
2013-06-14 01:19:39 +00:00
|
|
|
// Is this node an empty non-content branch node?
|
|
|
|
isEmptyBranch = node.getLength() === 0 && !node.isContent() && !node.canContainContent();
|
2012-10-17 23:09:49 +00:00
|
|
|
// Is the start between prevNode's closing and node or between the parent's opening and node?
|
|
|
|
startBetween = ( isWrapped ? start === left - 1 : start === left ) && !isPrevUnwrapped;
|
|
|
|
// Is the end between node and nextNode's opening or between node and the parent's closing?
|
|
|
|
endBetween = ( isWrapped ? end === right + 1 : end === right ) && !isNextUnwrapped;
|
2012-10-19 22:28:26 +00:00
|
|
|
parentRange = new ve.Range(
|
|
|
|
currentFrame.startOffset,
|
|
|
|
currentFrame.startOffset + currentFrame.node.getLength()
|
|
|
|
);
|
2012-05-10 04:11:09 +00:00
|
|
|
|
2012-07-07 18:13:31 +00:00
|
|
|
if ( isWrapped && end === left - 1 && currentFrame.index === 0 ) {
|
|
|
|
// The selection ends here with an empty range at the beginning of the node
|
|
|
|
// TODO duplicated code
|
|
|
|
isWrapped = currentFrame.node.isWrapped();
|
|
|
|
retval.push( {
|
|
|
|
'node': currentFrame.node,
|
|
|
|
'indexInNode': 0,
|
|
|
|
'range': new ve.Range( end, end ),
|
2012-10-19 22:28:26 +00:00
|
|
|
'nodeRange': parentRange,
|
2012-07-07 18:13:31 +00:00
|
|
|
'nodeOuterRange': new ve.Range(
|
2012-10-19 22:28:26 +00:00
|
|
|
parentRange.start - isWrapped, parentRange.end + isWrapped
|
2012-07-07 18:13:31 +00:00
|
|
|
)
|
|
|
|
} );
|
|
|
|
parentFrame = stack[stack.length - 2];
|
|
|
|
if ( parentFrame ) {
|
|
|
|
retval[retval.length - 1].index = parentFrame.index;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2012-10-17 23:09:49 +00:00
|
|
|
if ( start === end && ( startBetween || endBetween ) && isWrapped ) {
|
2012-05-10 04:11:09 +00:00
|
|
|
// Empty range in the parent, outside of any child
|
2012-06-04 23:18:29 +00:00
|
|
|
isWrapped = currentFrame.node.isWrapped();
|
2012-05-11 03:04:13 +00:00
|
|
|
retval = [ {
|
2012-05-10 04:11:09 +00:00
|
|
|
'node': currentFrame.node,
|
2012-05-11 03:08:12 +00:00
|
|
|
'indexInNode': currentFrame.index + ( endBetween ? 1 : 0 ),
|
2012-05-10 22:03:23 +00:00
|
|
|
'range': new ve.Range( start, end ),
|
2012-10-19 22:28:26 +00:00
|
|
|
'nodeRange': parentRange,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeOuterRange': new ve.Range(
|
2012-10-19 22:28:26 +00:00
|
|
|
parentRange.start - isWrapped, parentRange.end + isWrapped
|
2012-05-10 22:03:23 +00:00
|
|
|
)
|
2012-05-10 04:11:09 +00:00
|
|
|
} ];
|
2012-05-11 03:04:13 +00:00
|
|
|
parentFrame = stack[stack.length - 2];
|
|
|
|
if ( parentFrame ) {
|
|
|
|
retval[0].index = parentFrame.index;
|
|
|
|
}
|
2012-07-07 18:07:32 +00:00
|
|
|
return retval;
|
2012-05-10 04:11:09 +00:00
|
|
|
} else if ( startBetween ) {
|
|
|
|
// start is between the previous sibling and node
|
2012-06-06 18:30:16 +00:00
|
|
|
// so the selection covers all or part of node
|
2013-03-13 01:34:47 +00:00
|
|
|
|
2012-06-06 18:30:16 +00:00
|
|
|
// Descend if
|
2013-03-13 01:34:47 +00:00
|
|
|
// - we are in leaves mode, OR
|
|
|
|
// - we are in covered mode and the end is inside node OR
|
|
|
|
// - we are in branches mode and node is a branch (can have grandchildren)
|
2012-09-24 13:16:25 +00:00
|
|
|
if ( ( mode === 'leaves' ||
|
|
|
|
( mode === 'covered' && endInside ) ||
|
2013-03-13 23:25:33 +00:00
|
|
|
( mode === 'branches' && node.canHaveChildrenNotContent() ) ) &&
|
2012-06-06 18:30:16 +00:00
|
|
|
node.children && node.children.length
|
|
|
|
) {
|
2012-05-10 04:11:09 +00:00
|
|
|
// Descend into node
|
2012-05-10 22:03:23 +00:00
|
|
|
currentFrame = {
|
|
|
|
'node': node,
|
|
|
|
'index': 0,
|
|
|
|
'startOffset': left
|
|
|
|
};
|
2012-05-10 04:11:09 +00:00
|
|
|
stack.push( currentFrame );
|
|
|
|
startFound = true;
|
2012-06-20 00:12:36 +00:00
|
|
|
// If the first child of node has an opening, skip over it
|
|
|
|
if ( node.children[0].isWrapped() ) {
|
|
|
|
left++;
|
|
|
|
}
|
2012-05-10 04:11:09 +00:00
|
|
|
continue;
|
2012-05-10 23:08:15 +00:00
|
|
|
} else if ( !endInside ) {
|
2012-05-10 04:11:09 +00:00
|
|
|
// All of node is covered
|
2012-05-10 22:03:23 +00:00
|
|
|
retval.push( {
|
|
|
|
'node': node,
|
|
|
|
// no 'range' because the entire node is covered
|
|
|
|
'index': currentFrame.index,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( left, right ),
|
2012-10-19 22:28:26 +00:00
|
|
|
'nodeOuterRange': new ve.Range( left - isWrapped, right + isWrapped ),
|
|
|
|
'parentOuterRange': new ve.Range(
|
|
|
|
parentRange.start - currentFrame.node.isWrapped(),
|
|
|
|
parentRange.end + currentFrame.node.isWrapped()
|
|
|
|
)
|
2012-05-10 22:03:23 +00:00
|
|
|
} );
|
2012-05-10 04:11:09 +00:00
|
|
|
startFound = true;
|
2012-05-10 23:08:15 +00:00
|
|
|
} else {
|
|
|
|
// Part of node is covered
|
|
|
|
return [ {
|
|
|
|
'node': node,
|
|
|
|
'range': new ve.Range( start, end ),
|
|
|
|
'index': currentFrame.index,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( left, right ),
|
2012-10-19 22:28:26 +00:00
|
|
|
'nodeOuterRange': new ve.Range( left - isWrapped, right + isWrapped ),
|
|
|
|
'parentOuterRange': new ve.Range(
|
|
|
|
parentRange.start - currentFrame.node.isWrapped(),
|
|
|
|
parentRange.end + currentFrame.node.isWrapped()
|
|
|
|
)
|
2012-05-10 23:08:15 +00:00
|
|
|
} ];
|
2012-05-10 04:11:09 +00:00
|
|
|
}
|
|
|
|
} else if ( startInside && endInside ) {
|
2012-10-04 22:24:02 +00:00
|
|
|
if ( node.children && node.children.length &&
|
2013-03-13 23:25:33 +00:00
|
|
|
( mode !== 'branches' || node.canHaveChildrenNotContent() ) ) {
|
2012-05-10 04:11:09 +00:00
|
|
|
// Descend into node
|
2012-05-10 22:03:23 +00:00
|
|
|
currentFrame = {
|
|
|
|
'node': node,
|
|
|
|
'index': 0,
|
|
|
|
'startOffset': left
|
|
|
|
};
|
2012-05-10 04:11:09 +00:00
|
|
|
stack.push( currentFrame );
|
2012-06-20 00:12:36 +00:00
|
|
|
// If the first child of node has an opening, skip over it
|
|
|
|
if ( node.children[0].isWrapped() ) {
|
|
|
|
left++;
|
|
|
|
}
|
2012-05-10 04:11:09 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
// node is a leaf node and the range is entirely inside it
|
2013-06-14 01:19:39 +00:00
|
|
|
retval = [ {
|
2012-05-10 04:11:09 +00:00
|
|
|
'node': node,
|
2012-05-10 23:42:16 +00:00
|
|
|
'range': new ve.Range( start, end ),
|
2012-05-10 22:03:23 +00:00
|
|
|
'index': currentFrame.index,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( left, right ),
|
2012-10-19 22:28:26 +00:00
|
|
|
'nodeOuterRange': new ve.Range( left - isWrapped, right + isWrapped ),
|
|
|
|
'parentOuterRange': new ve.Range(
|
|
|
|
parentRange.start - currentFrame.node.isWrapped(),
|
|
|
|
parentRange.end + currentFrame.node.isWrapped()
|
|
|
|
)
|
2012-05-10 04:11:09 +00:00
|
|
|
} ];
|
2013-06-14 01:19:39 +00:00
|
|
|
if ( isEmptyBranch ) {
|
|
|
|
retval[0].indexInNode = 0;
|
|
|
|
}
|
|
|
|
return retval;
|
2012-05-10 04:11:09 +00:00
|
|
|
}
|
|
|
|
} else if ( startInside ) {
|
2012-09-24 13:16:25 +00:00
|
|
|
if ( ( mode === 'leaves' ||
|
|
|
|
mode === 'covered' ||
|
2013-03-13 23:25:33 +00:00
|
|
|
( mode === 'branches' && node.canHaveChildrenNotContent() ) ) &&
|
2012-09-24 13:16:25 +00:00
|
|
|
node.children && node.children.length
|
2012-06-06 18:30:16 +00:00
|
|
|
) {
|
2012-05-10 04:11:09 +00:00
|
|
|
// node is a branch node and the start is inside it
|
|
|
|
// Descend into it
|
2012-05-10 22:03:23 +00:00
|
|
|
currentFrame = {
|
|
|
|
'node': node,
|
|
|
|
'index': 0,
|
|
|
|
'startOffset': left
|
|
|
|
};
|
2012-05-10 04:11:09 +00:00
|
|
|
stack.push( currentFrame );
|
2012-06-20 00:12:36 +00:00
|
|
|
// If the first child of node has an opening, skip over it
|
|
|
|
if ( node.children[0].isWrapped() ) {
|
|
|
|
left++;
|
|
|
|
}
|
2012-05-10 04:11:09 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
// node is a leaf node and the start is inside it
|
|
|
|
// Add to retval and keep going
|
|
|
|
retval.push( {
|
|
|
|
'node': node,
|
2012-05-10 22:03:23 +00:00
|
|
|
'range': new ve.Range( start, right ),
|
|
|
|
'index': currentFrame.index,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( left, right ),
|
2012-10-19 22:28:26 +00:00
|
|
|
'nodeOuterRange': new ve.Range( left - isWrapped, right + isWrapped ),
|
|
|
|
'parentOuterRange': new ve.Range(
|
|
|
|
parentRange.start - currentFrame.node.isWrapped(),
|
|
|
|
parentRange.end + currentFrame.node.isWrapped()
|
|
|
|
)
|
2012-05-10 04:11:09 +00:00
|
|
|
} );
|
|
|
|
startFound = true;
|
|
|
|
}
|
|
|
|
} else if ( endBetween ) {
|
|
|
|
// end is between node and the next sibling
|
|
|
|
// start is not inside node, so the selection covers
|
|
|
|
// all of node, then ends
|
2013-03-13 01:34:47 +00:00
|
|
|
|
2012-09-24 13:16:25 +00:00
|
|
|
if (
|
2013-03-13 23:25:33 +00:00
|
|
|
( mode === 'leaves' || ( mode === 'branches' && node.canHaveChildrenNotContent() ) ) &&
|
2012-09-24 13:16:25 +00:00
|
|
|
node.children && node.children.length
|
|
|
|
) {
|
2012-05-10 04:11:09 +00:00
|
|
|
// Descend into node
|
2012-05-10 22:03:23 +00:00
|
|
|
currentFrame = {
|
|
|
|
'node': node,
|
|
|
|
'index': 0,
|
|
|
|
'startOffset': left
|
|
|
|
};
|
2012-05-10 04:11:09 +00:00
|
|
|
stack.push( currentFrame );
|
2012-06-20 00:12:36 +00:00
|
|
|
// If the first child of node has an opening, skip over it
|
|
|
|
if ( node.children[0].isWrapped() ) {
|
|
|
|
left++;
|
|
|
|
}
|
2012-05-10 04:11:09 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
// All of node is covered
|
2012-05-10 22:03:23 +00:00
|
|
|
retval.push( {
|
|
|
|
'node': node,
|
|
|
|
// no 'range' because the entire node is covered
|
|
|
|
'index': currentFrame.index,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( left, right ),
|
2012-10-19 22:28:26 +00:00
|
|
|
'nodeOuterRange': new ve.Range( left - isWrapped, right + isWrapped ),
|
|
|
|
'parentOuterRange': new ve.Range(
|
|
|
|
parentRange.start - currentFrame.node.isWrapped(),
|
|
|
|
parentRange.end + currentFrame.node.isWrapped()
|
|
|
|
)
|
2012-05-10 22:03:23 +00:00
|
|
|
} );
|
2012-05-10 04:11:09 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
} else if ( endInside ) {
|
2012-09-24 13:16:25 +00:00
|
|
|
if ( ( mode === 'leaves' ||
|
|
|
|
mode === 'covered' ||
|
2013-03-13 23:25:33 +00:00
|
|
|
( mode === 'branches' && node.canHaveChildrenNotContent() ) ) &&
|
2012-09-24 13:16:25 +00:00
|
|
|
node.children && node.children.length
|
2012-06-06 18:30:16 +00:00
|
|
|
) {
|
2012-05-10 04:11:09 +00:00
|
|
|
// node is a branch node and the end is inside it
|
|
|
|
// Descend into it
|
2012-05-10 22:03:23 +00:00
|
|
|
currentFrame = {
|
|
|
|
'node': node,
|
|
|
|
'index': 0,
|
|
|
|
'startOffset': left
|
|
|
|
};
|
2012-05-10 04:11:09 +00:00
|
|
|
stack.push( currentFrame );
|
2012-06-20 00:12:36 +00:00
|
|
|
// If the first child of node has an opening, skip over it
|
|
|
|
if ( node.children[0].isWrapped() ) {
|
|
|
|
left++;
|
|
|
|
}
|
2012-05-10 04:11:09 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
// node is a leaf node and the end is inside it
|
|
|
|
// Add to retval and return
|
|
|
|
retval.push( {
|
|
|
|
'node': node,
|
2012-05-10 22:03:23 +00:00
|
|
|
'range': new ve.Range( left, end ),
|
|
|
|
'index': currentFrame.index,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( left, right ),
|
2012-10-19 22:28:26 +00:00
|
|
|
'nodeOuterRange': new ve.Range( left - isWrapped, right + isWrapped ),
|
|
|
|
'parentOuterRange': new ve.Range(
|
|
|
|
parentRange.start - currentFrame.node.isWrapped(),
|
|
|
|
parentRange.end + currentFrame.node.isWrapped()
|
|
|
|
)
|
2012-05-10 04:11:09 +00:00
|
|
|
} );
|
|
|
|
return retval;
|
|
|
|
}
|
2012-06-20 18:39:20 +00:00
|
|
|
} else if ( startFound && end > right ) {
|
2012-05-10 04:11:09 +00:00
|
|
|
// Neither the start nor the end is inside node, but we found the start earlier,
|
|
|
|
// so node must be between the start and the end
|
|
|
|
// Add the entire node, so no range property
|
2012-09-24 13:16:25 +00:00
|
|
|
|
|
|
|
if (
|
2013-03-13 23:25:33 +00:00
|
|
|
( mode === 'leaves' || ( mode === 'branches' && node.canHaveChildrenNotContent() ) ) &&
|
2012-09-24 13:16:25 +00:00
|
|
|
node.children && node.children.length
|
|
|
|
) {
|
2012-05-10 04:11:09 +00:00
|
|
|
// Descend into node
|
2012-05-10 22:03:23 +00:00
|
|
|
currentFrame = {
|
|
|
|
'node': node,
|
|
|
|
'index': 0,
|
|
|
|
'startOffset': left
|
|
|
|
};
|
2012-05-10 04:11:09 +00:00
|
|
|
stack.push( currentFrame );
|
2012-06-20 00:12:36 +00:00
|
|
|
// If the first child of node has an opening, skip over it
|
|
|
|
if ( node.children[0].isWrapped() ) {
|
|
|
|
left++;
|
|
|
|
}
|
2012-05-10 04:11:09 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
// All of node is covered
|
2012-05-10 22:03:23 +00:00
|
|
|
retval.push( {
|
|
|
|
'node': node,
|
|
|
|
// no 'range' because the entire node is covered
|
|
|
|
'index': currentFrame.index,
|
2012-06-04 23:18:29 +00:00
|
|
|
'nodeRange': new ve.Range( left, right ),
|
2012-10-19 22:28:26 +00:00
|
|
|
'nodeOuterRange': new ve.Range( left - isWrapped, right + isWrapped ),
|
|
|
|
'parentOuterRange': new ve.Range(
|
|
|
|
parentRange.start - currentFrame.node.isWrapped(),
|
|
|
|
parentRange.end + currentFrame.node.isWrapped()
|
|
|
|
)
|
2012-05-10 22:03:23 +00:00
|
|
|
} );
|
2012-05-10 04:11:09 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-13 01:34:47 +00:00
|
|
|
|
2012-05-10 04:11:09 +00:00
|
|
|
// Move to the next node
|
|
|
|
if ( nextNode ) {
|
|
|
|
// The next node exists
|
|
|
|
// Advance the index; the start of the next iteration will essentially
|
|
|
|
// do node = nextNode;
|
|
|
|
currentFrame.index++;
|
|
|
|
// Advance to the first offset inside nextNode
|
|
|
|
left = right +
|
|
|
|
// Skip over node's closing, if present
|
|
|
|
( node.isWrapped() ? 1 : 0 ) +
|
|
|
|
// Skip over nextNode's opening, if present
|
|
|
|
( nextNode.isWrapped() ? 1 : 0 );
|
|
|
|
} else {
|
|
|
|
// There is no next node, move up the stack until there is one
|
2012-06-05 13:49:30 +00:00
|
|
|
left = right +
|
|
|
|
// Skip over node's closing, if present
|
|
|
|
( node.isWrapped() ? 1 : 0 );
|
2012-05-10 04:11:09 +00:00
|
|
|
while ( !nextNode ) {
|
2012-07-07 18:13:31 +00:00
|
|
|
// Check if the start is right past the end of this node, at the end of
|
|
|
|
// the parent
|
2012-08-02 18:46:13 +00:00
|
|
|
if ( node.isWrapped() && start === left ) {
|
2012-07-07 18:13:31 +00:00
|
|
|
// TODO duplicated code
|
2012-10-19 22:28:26 +00:00
|
|
|
parentRange = new ve.Range( currentFrame.startOffset,
|
2012-07-07 18:13:31 +00:00
|
|
|
currentFrame.startOffset + currentFrame.node.getLength()
|
|
|
|
);
|
|
|
|
isWrapped = currentFrame.node.isWrapped();
|
|
|
|
retval = [ {
|
|
|
|
'node': currentFrame.node,
|
|
|
|
'indexInNode': currentFrame.index + 1,
|
|
|
|
'range': new ve.Range( left, left ),
|
2012-10-19 22:28:26 +00:00
|
|
|
'nodeRange': parentRange,
|
2012-07-07 18:13:31 +00:00
|
|
|
'nodeOuterRange': new ve.Range(
|
2012-10-19 22:28:26 +00:00
|
|
|
parentRange.start - isWrapped, parentRange.end + isWrapped
|
2012-07-07 18:13:31 +00:00
|
|
|
)
|
|
|
|
} ];
|
|
|
|
parentFrame = stack[stack.length - 2];
|
|
|
|
if ( parentFrame ) {
|
|
|
|
retval[0].index = parentFrame.index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move up the stack
|
2012-05-10 04:11:09 +00:00
|
|
|
stack.pop();
|
|
|
|
if ( stack.length === 0 ) {
|
|
|
|
// This shouldn't be possible
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
currentFrame = stack[stack.length - 1];
|
|
|
|
currentFrame.index++;
|
|
|
|
nextNode = currentFrame.node.children[currentFrame.index];
|
|
|
|
// Skip over the parent node's closing
|
|
|
|
// (this is present for sure, because the parent has children)
|
|
|
|
left++;
|
|
|
|
}
|
2013-03-13 01:34:47 +00:00
|
|
|
|
2012-05-10 04:11:09 +00:00
|
|
|
// Skip over nextNode's opening if present
|
|
|
|
if ( nextNode.isWrapped() ) {
|
|
|
|
left++;
|
|
|
|
}
|
|
|
|
}
|
2012-06-20 00:12:36 +00:00
|
|
|
} while ( end >= left - 1 );
|
2012-08-08 22:17:45 +00:00
|
|
|
if ( retval.length === 0 ) {
|
|
|
|
throw new Error( 'selectNodes epic fail' );
|
|
|
|
}
|
2012-05-10 04:11:09 +00:00
|
|
|
return retval;
|
|
|
|
};
|
2012-06-20 22:04:15 +00:00
|
|
|
|
2012-07-07 17:57:27 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get groups of sibling nodes covered by the given range.
|
|
|
|
*
|
2012-07-07 17:57:27 +00:00
|
|
|
* @param {ve.Range} selection Range
|
2013-06-17 10:50:24 +00:00
|
|
|
* @returns {Array} Array of objects. Each object has the following keys:
|
2013-07-25 02:02:50 +00:00
|
|
|
*
|
|
|
|
* - nodes: Array of sibling nodes covered by a part of range
|
|
|
|
* - parent: Parent of all of these nodes
|
|
|
|
* - grandparent: parent's parent
|
2012-07-07 17:57:27 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.Document.prototype.getCoveredSiblingGroups = function ( selection ) {
|
2012-08-02 18:46:13 +00:00
|
|
|
var i, firstCoveredSibling, lastCoveredSibling, node, parentNode, siblingNode,
|
|
|
|
leaves = this.selectNodes( selection, 'leaves' ),
|
2012-07-07 17:57:27 +00:00
|
|
|
groups = [],
|
|
|
|
lastEndOffset = 0;
|
2012-08-02 18:46:13 +00:00
|
|
|
for ( i = 0; i < leaves.length; i++ ) {
|
2012-07-07 17:57:27 +00:00
|
|
|
if ( leaves[i].nodeOuterRange.end <= lastEndOffset ) {
|
|
|
|
// This range is contained within a range we've already processed
|
|
|
|
continue;
|
|
|
|
}
|
2012-06-20 22:04:15 +00:00
|
|
|
node = leaves[i].node;
|
|
|
|
// Traverse up to a content branch from content elements
|
|
|
|
if ( node.isContent() ) {
|
|
|
|
node = node.getParent();
|
|
|
|
}
|
|
|
|
parentNode = node.getParent();
|
|
|
|
// Group this with its covered siblings
|
|
|
|
groups.push( {
|
|
|
|
'parent': parentNode,
|
|
|
|
'grandparent': parentNode.getParent(),
|
|
|
|
'nodes': []
|
|
|
|
} );
|
|
|
|
firstCoveredSibling = node;
|
|
|
|
// Seek forward to the last covered sibling
|
|
|
|
siblingNode = firstCoveredSibling;
|
|
|
|
do {
|
|
|
|
// Add this to its sibling's group
|
|
|
|
groups[groups.length - 1].nodes.push( siblingNode );
|
|
|
|
lastCoveredSibling = siblingNode;
|
|
|
|
i++;
|
|
|
|
if ( leaves[i] === undefined ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Traverse up to a content branch from content elements
|
|
|
|
siblingNode = leaves[i].node;
|
|
|
|
if ( siblingNode.isContent() ) {
|
|
|
|
siblingNode = siblingNode.getParent();
|
|
|
|
}
|
|
|
|
} while ( siblingNode.getParent() === parentNode );
|
2012-07-25 21:22:22 +00:00
|
|
|
i--;
|
2012-07-07 17:57:27 +00:00
|
|
|
lastEndOffset = parentNode.getOuterRange().end;
|
2012-06-20 22:04:15 +00:00
|
|
|
}
|
|
|
|
return groups;
|
|
|
|
};
|