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
|
|
|
/*!
|
2013-01-15 23:38:49 +00:00
|
|
|
* VisualEditor DataModel 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-04-27 02:44:44 +00:00
|
|
|
/**
|
2012-04-30 23:58:41 +00:00
|
|
|
* DataModel document.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-10-22 23:26:39 +00:00
|
|
|
* WARNING: The data parameter is passed by reference. Do not modify a data array after passing
|
|
|
|
* it to this constructor, and do not construct multiple Documents with the same data array. If you
|
|
|
|
* need to do these things, make a deep copy (ve.copyArray()) of the data array and operate on the
|
|
|
|
* copy.
|
2012-08-16 21:18:50 +00:00
|
|
|
*
|
2012-04-27 02:44:44 +00:00
|
|
|
* @class
|
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
|
|
|
* @extends ve.Document
|
2012-04-27 02:44:44 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {Array} data Linear model data to start with
|
2012-05-17 18:23:56 +00:00
|
|
|
* @param {ve.dm.Document} [parentDocument] Document to use as root for created nodes
|
2012-04-27 02:44:44 +00:00
|
|
|
*/
|
2012-09-06 23:15:55 +00:00
|
|
|
ve.dm.Document = function VeDmDocument( data, parentDocument ) {
|
Object management: Object create/inherit/clone utilities
* For the most common case:
- replace ve.extendClass with ve.inheritClass (chose slightly
different names to detect usage of the old/new one, and I
like 'inherit' better).
- move it up to below the constructor, see doc block for why.
* Cases where more than 2 arguments were passed to
ve.extendClass are handled differently depending on the case.
In case of a longer inheritance tree, the other arguments
could be omitted (like in "ve.ce.FooBar, ve.FooBar,
ve.Bar". ve.ce.FooBar only needs to inherit from ve.FooBar,
because ve.ce.FooBar inherits from ve.Bar).
In the case of where it previously had two mixins with
ve.extendClass(), either one becomes inheritClass and one
a mixin, both to mixinClass().
No visible changes should come from this commit as the
instances still all have the same visible properties in the
end. No more or less than before.
* Misc.:
- Be consistent in calling parent constructors in the
same order as the inheritance.
- Add missing @extends and @param documentation.
- Replace invalid {Integer} type hint with {Number}.
- Consistent doc comments order:
@class, @abstract, @constructor, @extends, @params.
- Fix indentation errors
A fairly common mistake was a superfluous space before the
identifier on the assignment line directly below the
documentation comment.
$ ack "^ [^*]" --js modules/ve
- Typo "Inhertiance" -> "Inheritance".
- Replacing the other confusing comment "Inheritance" (inside
the constructor) with "Parent constructor".
- Add missing @abstract for ve.ui.Tool.
- Corrected ve.FormatDropdownTool to ve.ui.FormatDropdownTool.js
- Add function names to all @constructor functions. Now that we
have inheritance it is important and useful to have these
functions not be anonymous.
Example of debug shot: http://cl.ly/image/1j3c160w3D45
Makes the difference between
< documentNode;
> ve_dm_DocumentNode
...
: ve_dm_BranchNode
...
: ve_dm_Node
...
: ve_dm_Node
...
: Object
...
without names (current situation):
< documentNode;
> Object
...
: Object
...
: Object
...
: Object
...
: Object
...
though before this commit, it really looks like this
(flattened since ve.extendClass really did a mixin):
< documentNode;
> Object
...
...
...
Pattern in Sublime (case-sensitive) to find nameless
constructor functions:
"^ve\..*\.([A-Z])([^\.]+) = function \("
Change-Id: Iab763954fb8cf375900d7a9a92dec1c755d5407e
2012-09-05 06:07:47 +00:00
|
|
|
// Parent constructor
|
2012-05-17 18:23:56 +00:00
|
|
|
ve.Document.call( this, new ve.dm.DocumentNode() );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.parentDocument = parentDocument;
|
2012-10-22 23:26:39 +00:00
|
|
|
this.data = ve.isArray( data ) ? data : [];
|
2012-10-30 01:42:12 +00:00
|
|
|
// Sparse array containing the metadata for each offset
|
|
|
|
// Each element is either undefined, or an array of metadata elements
|
|
|
|
// Because the indexes in the metadata array represent offsets in the data array, the
|
|
|
|
// metadata array has one element more than the data array.
|
|
|
|
this.metadata = new Array( this.data.length + 1 );
|
2012-05-17 18:23:56 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
/*
|
|
|
|
* Build a tree of nodes and nodes that will be added to them after a full scan is complete,
|
|
|
|
* then from the bottom up add nodes to their potential parents. This avoids massive length
|
2012-06-13 23:16:07 +00:00
|
|
|
* updates being broadcast upstream constantly while building is underway.
|
2012-05-17 18:23:56 +00:00
|
|
|
*/
|
2012-10-30 01:42:12 +00:00
|
|
|
var i, node, children, meta,
|
2012-08-02 18:46:13 +00:00
|
|
|
doc = parentDocument || this,
|
|
|
|
root = doc.getDocumentNode(),
|
2012-05-17 18:23:56 +00:00
|
|
|
textLength = 0,
|
|
|
|
inTextNode = false,
|
|
|
|
// Stack of stacks, each containing a
|
|
|
|
stack = [[this.documentNode], []],
|
|
|
|
currentStack = stack[1],
|
|
|
|
parentStack = stack[0],
|
|
|
|
currentNode = this.documentNode;
|
2012-08-02 18:46:13 +00:00
|
|
|
this.documentNode.setDocument( doc );
|
|
|
|
this.documentNode.setRoot( root );
|
2012-10-30 01:42:12 +00:00
|
|
|
for ( i = 0; i < this.data.length; i++ ) {
|
2012-05-17 18:23:56 +00:00
|
|
|
// Infer that if an item in the linear model has a type attribute than it must be an element
|
|
|
|
if ( this.data[i].type === undefined ) {
|
|
|
|
// Text node opening
|
|
|
|
if ( !inTextNode ) {
|
|
|
|
// Create a lengthless text node
|
|
|
|
node = new ve.dm.TextNode();
|
|
|
|
// Set the root pointer now, to prevent cascading updates
|
|
|
|
node.setRoot( root );
|
|
|
|
// Put the node on the current inner stack
|
|
|
|
currentStack.push( node );
|
|
|
|
currentNode = node;
|
|
|
|
// Set a flag saying we're inside a text node
|
|
|
|
inTextNode = true;
|
|
|
|
}
|
|
|
|
// Track the length
|
|
|
|
textLength++;
|
|
|
|
} else {
|
2013-02-08 01:15:02 +00:00
|
|
|
if (
|
|
|
|
this.data[i].type.charAt( 0 ) !== '/' &&
|
|
|
|
ve.dm.nodeFactory.isNodeMeta( this.data[i].type )
|
|
|
|
) {
|
2012-10-30 01:42:12 +00:00
|
|
|
// Metadata
|
|
|
|
// Splice the meta element and its closing out of the linmod
|
|
|
|
meta = this.data[i];
|
|
|
|
this.spliceData( i, 2 );
|
|
|
|
// Put the metadata in the meta-linmod
|
|
|
|
if ( !this.metadata[i] ) {
|
|
|
|
this.metadata[i] = [];
|
|
|
|
}
|
|
|
|
this.metadata[i].push( meta );
|
|
|
|
// Make sure the loop doesn't skip the next element
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-05-17 18:23:56 +00:00
|
|
|
// Text node closing
|
|
|
|
if ( inTextNode ) {
|
|
|
|
// Finish the text node by setting the length
|
|
|
|
currentNode.setLength( textLength );
|
|
|
|
// Put the state variables back as they were
|
|
|
|
currentNode = parentStack[parentStack.length - 1];
|
|
|
|
inTextNode = false;
|
|
|
|
textLength = 0;
|
|
|
|
}
|
|
|
|
// Element open/close
|
2012-07-19 03:40:49 +00:00
|
|
|
if ( this.data[i].type.charAt( 0 ) !== '/' ) {
|
2012-05-17 18:23:56 +00:00
|
|
|
// Branch or leaf node opening
|
|
|
|
// Create a childless node
|
2012-08-16 17:53:33 +00:00
|
|
|
node = ve.dm.nodeFactory.create( this.data[i].type, [],
|
2012-11-23 23:16:08 +00:00
|
|
|
this.data[i]
|
2012-08-16 17:53:33 +00:00
|
|
|
);
|
2012-05-17 18:23:56 +00:00
|
|
|
// Set the root pointer now, to prevent cascading updates
|
|
|
|
node.setRoot( root );
|
|
|
|
// Put the childless node on the current inner stack
|
|
|
|
currentStack.push( node );
|
2012-05-31 22:20:58 +00:00
|
|
|
if ( ve.dm.nodeFactory.canNodeHaveChildren( node.getType() ) ) {
|
2012-05-17 18:23:56 +00:00
|
|
|
// Create a new inner stack for this node
|
|
|
|
parentStack = currentStack;
|
|
|
|
currentStack = [];
|
|
|
|
stack.push( currentStack );
|
|
|
|
}
|
|
|
|
currentNode = node;
|
|
|
|
} else {
|
|
|
|
// Branch or leaf node closing
|
2012-05-31 22:20:58 +00:00
|
|
|
if ( ve.dm.nodeFactory.canNodeHaveChildren( currentNode.getType() ) ) {
|
2012-05-17 18:27:25 +00:00
|
|
|
// Pop this node's inner stack from the outer stack. It'll have all of the
|
|
|
|
// node's child nodes fully constructed
|
2012-05-17 18:23:56 +00:00
|
|
|
children = stack.pop();
|
|
|
|
currentStack = parentStack;
|
|
|
|
parentStack = stack[stack.length - 2];
|
|
|
|
if ( !parentStack ) {
|
|
|
|
// This can only happen if we got unbalanced data
|
2012-08-08 17:48:53 +00:00
|
|
|
throw new Error( 'Unbalanced input passed to document' );
|
2012-05-17 18:23:56 +00:00
|
|
|
}
|
|
|
|
// Attach the children to the node
|
|
|
|
ve.batchSplice( currentNode, 0, 0, children );
|
|
|
|
}
|
|
|
|
currentNode = parentStack[parentStack.length - 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-31 13:17:23 +00:00
|
|
|
|
|
|
|
if ( inTextNode ) {
|
|
|
|
// Text node ended by end-of-input rather than by an element
|
|
|
|
currentNode.setLength( textLength );
|
|
|
|
// Don't bother updating currentNode et al, we don't use them below
|
|
|
|
}
|
2012-05-17 18:23:56 +00:00
|
|
|
// The end state is stack = [ [this.documentNode] [ array, of, its, children ] ]
|
|
|
|
// so attach all nodes in stack[1] to the root node
|
|
|
|
ve.batchSplice( this.documentNode, 0, 0, stack[1] );
|
2012-04-27 02:44:44 +00:00
|
|
|
};
|
|
|
|
|
Object management: Object create/inherit/clone utilities
* For the most common case:
- replace ve.extendClass with ve.inheritClass (chose slightly
different names to detect usage of the old/new one, and I
like 'inherit' better).
- move it up to below the constructor, see doc block for why.
* Cases where more than 2 arguments were passed to
ve.extendClass are handled differently depending on the case.
In case of a longer inheritance tree, the other arguments
could be omitted (like in "ve.ce.FooBar, ve.FooBar,
ve.Bar". ve.ce.FooBar only needs to inherit from ve.FooBar,
because ve.ce.FooBar inherits from ve.Bar).
In the case of where it previously had two mixins with
ve.extendClass(), either one becomes inheritClass and one
a mixin, both to mixinClass().
No visible changes should come from this commit as the
instances still all have the same visible properties in the
end. No more or less than before.
* Misc.:
- Be consistent in calling parent constructors in the
same order as the inheritance.
- Add missing @extends and @param documentation.
- Replace invalid {Integer} type hint with {Number}.
- Consistent doc comments order:
@class, @abstract, @constructor, @extends, @params.
- Fix indentation errors
A fairly common mistake was a superfluous space before the
identifier on the assignment line directly below the
documentation comment.
$ ack "^ [^*]" --js modules/ve
- Typo "Inhertiance" -> "Inheritance".
- Replacing the other confusing comment "Inheritance" (inside
the constructor) with "Parent constructor".
- Add missing @abstract for ve.ui.Tool.
- Corrected ve.FormatDropdownTool to ve.ui.FormatDropdownTool.js
- Add function names to all @constructor functions. Now that we
have inheritance it is important and useful to have these
functions not be anonymous.
Example of debug shot: http://cl.ly/image/1j3c160w3D45
Makes the difference between
< documentNode;
> ve_dm_DocumentNode
...
: ve_dm_BranchNode
...
: ve_dm_Node
...
: ve_dm_Node
...
: Object
...
without names (current situation):
< documentNode;
> Object
...
: Object
...
: Object
...
: Object
...
: Object
...
though before this commit, it really looks like this
(flattened since ve.extendClass really did a mixin):
< documentNode;
> Object
...
...
...
Pattern in Sublime (case-sensitive) to find nameless
constructor functions:
"^ve\..*\.([A-Z])([^\.]+) = function \("
Change-Id: Iab763954fb8cf375900d7a9a92dec1c755d5407e
2012-09-05 06:07:47 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.dm.Document, ve.Document );
|
|
|
|
|
2012-05-11 00:20:57 +00:00
|
|
|
/* Static methods */
|
|
|
|
|
2012-11-21 21:22:29 +00:00
|
|
|
/**
|
|
|
|
* Pattern that matches anything that's not considered part of a word.
|
|
|
|
*
|
|
|
|
* This is a very loose definition, it includes some punctuation that can occur around or inside of
|
|
|
|
* a word. This may need to be added to for some locales and perhaps made to be extendable for
|
|
|
|
* better internationalization support.
|
|
|
|
*
|
|
|
|
* Allowed characters:
|
|
|
|
* * Numbers and letters: a-z, A-Z, 0-9
|
|
|
|
* * Underscores and dashes: _, -
|
|
|
|
* * Brackets and parenthesis: (), []
|
|
|
|
* * Apostrophes and double quotes: ', "
|
|
|
|
*
|
|
|
|
* This pattern is tested against one character at a time.
|
|
|
|
*/
|
|
|
|
ve.dm.SurfaceFragment.wordBoundaryPattern = /[^\w'"-\(\)\[\]]+/;
|
|
|
|
|
2012-06-11 22:31:55 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Apply annotations to content data.
|
2012-06-13 23:06:21 +00:00
|
|
|
*
|
2012-06-11 22:31:55 +00:00
|
|
|
* This method modifies data in place.
|
2012-06-13 23:06:21 +00:00
|
|
|
*
|
2012-06-11 22:31:55 +00:00
|
|
|
* @method
|
|
|
|
* @param {Array} data Data to remove annotations from
|
2012-08-24 02:06:36 +00:00
|
|
|
* @param {ve.AnnotationSet} annotationSet Annotations to apply
|
2012-06-11 22:31:55 +00:00
|
|
|
*/
|
2012-08-24 02:06:36 +00:00
|
|
|
ve.dm.Document.addAnnotationsToData = function ( data, annotationSet ) {
|
2012-11-22 01:05:10 +00:00
|
|
|
if ( annotationSet.isEmpty() ) {
|
|
|
|
// Nothing to do
|
|
|
|
return;
|
|
|
|
}
|
2012-06-11 22:31:55 +00:00
|
|
|
// Apply annotations to data
|
2012-07-19 03:40:49 +00:00
|
|
|
for ( var i = 0; i < data.length; i++ ) {
|
2012-06-11 22:31:55 +00:00
|
|
|
if ( !ve.isArray( data[i] ) ) {
|
2012-08-24 02:06:36 +00:00
|
|
|
data[i] = [data[i], new ve.AnnotationSet()];
|
2012-06-11 22:31:55 +00:00
|
|
|
}
|
2012-08-24 02:06:36 +00:00
|
|
|
data[i][1].addSet( annotationSet );
|
2012-06-11 22:31:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-11 00:20:57 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Check if content can be inserted at an offset in document data.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-11 00:20:57 +00:00
|
|
|
* This method assumes that any value that has a type property that's a string is an element object.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
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
|
|
|
* Content offsets:
|
2012-05-11 00:20:57 +00:00
|
|
|
* <heading> a </heading> <paragraph> b c <img> </img> </paragraph>
|
|
|
|
* . ^ ^ . ^ ^ ^ . ^ .
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
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
|
|
|
* Content offsets:
|
2012-05-11 00:20:57 +00:00
|
|
|
* <list> <listItem> </listItem> <list>
|
|
|
|
* . . . . .
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-11 00:20:57 +00:00
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {Array} data Document data
|
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 {number} offset Document offset
|
|
|
|
* @returns {boolean} Content can be inserted at offset
|
2012-05-11 00:20:57 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.isContentOffset = function ( data, offset ) {
|
2012-05-11 00:20:57 +00:00
|
|
|
// Edges are never content
|
|
|
|
if ( offset === 0 || offset === data.length ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var left = data[offset - 1],
|
|
|
|
right = data[offset],
|
2012-05-31 22:20:58 +00:00
|
|
|
factory = ve.dm.nodeFactory;
|
2012-05-11 00:20:57 +00:00
|
|
|
return (
|
|
|
|
// Data exists at offsets
|
|
|
|
( left !== undefined && right !== undefined ) &&
|
|
|
|
(
|
|
|
|
// If there's content on the left or the right of the offset than we are good
|
|
|
|
// <paragraph>|a|</paragraph>
|
|
|
|
( typeof left === 'string' || typeof right === 'string' ) ||
|
|
|
|
// Same checks but for annotated characters - isArray is slower, try it next
|
|
|
|
( ve.isArray( left ) || ve.isArray( right ) ) ||
|
|
|
|
// The most expensive test are last, these deal with elements
|
|
|
|
(
|
|
|
|
// Right of a leaf
|
|
|
|
// <paragraph><image></image>|</paragraph>
|
|
|
|
(
|
|
|
|
// Is an element
|
|
|
|
typeof left.type === 'string' &&
|
|
|
|
// Is a closing
|
|
|
|
left.type.charAt( 0 ) === '/' &&
|
|
|
|
// Is a leaf
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.isNodeContent( left.type.substr( 1 ) )
|
2012-05-17 03:25:43 +00:00
|
|
|
) ||
|
2012-05-11 00:20:57 +00:00
|
|
|
// Left of a leaf
|
|
|
|
// <paragraph>|<image></image></paragraph>
|
|
|
|
(
|
|
|
|
// Is an element
|
|
|
|
typeof right.type === 'string' &&
|
|
|
|
// Is not a closing
|
|
|
|
right.type.charAt( 0 ) !== '/' &&
|
|
|
|
// Is a leaf
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.isNodeContent( right.type )
|
2012-05-11 00:20:57 +00:00
|
|
|
) ||
|
|
|
|
// Inside empty content branch
|
|
|
|
// <paragraph>|</paragraph>
|
|
|
|
(
|
|
|
|
// Inside empty element
|
|
|
|
'/' + left.type === right.type &&
|
|
|
|
// Both are content branches (right is the same type)
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.canNodeContainContent( left.type )
|
2012-05-11 00:20:57 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Check if structure can be inserted at an offset in document data.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-23 21:56:33 +00:00
|
|
|
* If the {unrestricted} param is true than only offsets where any kind of element can be inserted
|
|
|
|
* will return true. This can be used to detect the difference between a location that a paragraph
|
|
|
|
* can be inserted, such as between two tables but not direclty inside a table.
|
|
|
|
*
|
2012-05-11 00:20:57 +00:00
|
|
|
* This method assumes that any value that has a type property that's a string is an element object.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
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
|
|
|
* Structural offsets (unrestricted = false):
|
2012-05-23 21:56:33 +00:00
|
|
|
* <heading> a </heading> <paragraph> b c <img> </img> </paragraph>
|
|
|
|
* ^ . . ^ . . . . . ^
|
|
|
|
*
|
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
|
|
|
* Structural offsets (unrestricted = true):
|
2012-05-11 00:20:57 +00:00
|
|
|
* <heading> a </heading> <paragraph> b c <img> </img> </paragraph>
|
|
|
|
* ^ . . ^ . . . . . ^
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
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
|
|
|
* Structural offsets (unrestricted = false):
|
2012-05-23 21:56:33 +00:00
|
|
|
* <list> <listItem> </listItem> <list>
|
|
|
|
* ^ ^ ^ ^ ^
|
|
|
|
*
|
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
|
|
|
* Content branch offsets (unrestricted = true):
|
2012-05-23 21:56:33 +00:00
|
|
|
* <list> <listItem> </listItem> <list>
|
|
|
|
* ^ . ^ . ^
|
|
|
|
*
|
2012-05-11 00:20:57 +00:00
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {Array} data Document data
|
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 {number} offset Document offset
|
|
|
|
* @param {boolean} [unrestricted] Only return true if any kind of element can be inserted at offset
|
|
|
|
* @returns {boolean} Structure can be inserted at offset
|
2012-05-11 00:20:57 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.isStructuralOffset = function ( data, offset, unrestricted ) {
|
2012-05-11 00:20:57 +00:00
|
|
|
// Edges are always structural
|
|
|
|
if ( offset === 0 || offset === data.length ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Offsets must be within range and both sides must be elements
|
|
|
|
var left = data[offset - 1],
|
|
|
|
right = data[offset],
|
2012-05-31 22:20:58 +00:00
|
|
|
factory = ve.dm.nodeFactory;
|
2012-05-11 00:20:57 +00:00
|
|
|
return (
|
|
|
|
(
|
|
|
|
left !== undefined &&
|
|
|
|
right !== undefined &&
|
|
|
|
typeof left.type === 'string' &&
|
|
|
|
typeof right.type === 'string'
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
// Right of a branch
|
|
|
|
// <list><listItem><paragraph>a</paragraph>|</listItem>|</list>|
|
|
|
|
(
|
|
|
|
// Is a closing
|
|
|
|
left.type.charAt( 0 ) === '/' &&
|
2012-05-25 20:19:56 +00:00
|
|
|
// Is a branch or non-content leaf
|
|
|
|
(
|
|
|
|
factory.canNodeHaveChildren( left.type.substr( 1 ) ) ||
|
|
|
|
!factory.isNodeContent( left.type.substr( 1 ) )
|
|
|
|
) &&
|
2012-05-23 21:56:33 +00:00
|
|
|
(
|
|
|
|
// Only apply this rule in unrestricted mode
|
|
|
|
!unrestricted ||
|
|
|
|
// Right of an unrestricted branch
|
|
|
|
// <list><listItem><paragraph>a</paragraph>|</listItem></list>|
|
|
|
|
// Both are non-content branches that can have any kind of child
|
|
|
|
factory.getParentNodeTypes( left.type.substr( 1 ) ) === null
|
|
|
|
)
|
2012-05-11 00:20:57 +00:00
|
|
|
) ||
|
2012-05-23 21:56:33 +00:00
|
|
|
// Left of a branch
|
2012-05-11 00:20:57 +00:00
|
|
|
// |<list>|<listItem>|<paragraph>a</paragraph></listItem></list>
|
|
|
|
(
|
|
|
|
// Is not a closing
|
|
|
|
right.type.charAt( 0 ) !== '/' &&
|
2012-05-25 20:19:56 +00:00
|
|
|
// Is a branch or non-content leaf
|
|
|
|
(
|
|
|
|
factory.canNodeHaveChildren( right.type ) ||
|
|
|
|
!factory.isNodeContent( right.type )
|
|
|
|
) &&
|
2012-05-23 21:56:33 +00:00
|
|
|
(
|
|
|
|
// Only apply this rule in unrestricted mode
|
|
|
|
!unrestricted ||
|
|
|
|
// Left of an unrestricted branch
|
|
|
|
// |<list><listItem>|<paragraph>a</paragraph></listItem></list>
|
|
|
|
// Both are non-content branches that can have any kind of child
|
|
|
|
factory.getParentNodeTypes( right.type ) === null
|
|
|
|
)
|
2012-05-11 00:20:57 +00:00
|
|
|
) ||
|
|
|
|
// Inside empty non-content branch
|
|
|
|
// <list>|</list> or <list><listItem>|</listItem></list>
|
|
|
|
(
|
|
|
|
// Inside empty element
|
|
|
|
'/' + left.type === right.type &&
|
|
|
|
// Both are non-content branches (right is the same type)
|
2012-05-23 21:56:33 +00:00
|
|
|
factory.canNodeHaveGrandchildren( left.type ) &&
|
|
|
|
(
|
|
|
|
// Only apply this rule in unrestricted mode
|
|
|
|
!unrestricted ||
|
|
|
|
// Both are non-content branches that can have any kind of child
|
|
|
|
factory.getChildNodeTypes( left.type ) === null
|
|
|
|
)
|
2012-05-11 00:20:57 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Check if data at a given offset is an element.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-11 00:20:57 +00:00
|
|
|
* This method assumes that any value that has a type property that's a string is an element object.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
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
|
|
|
* Element data:
|
2012-05-11 00:20:57 +00:00
|
|
|
* <heading> a </heading> <paragraph> b c <img></img> </paragraph>
|
|
|
|
* ^ . ^ ^ . . ^ ^ ^ .
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-11 00:20:57 +00:00
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {Array} data Document data
|
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 {number} offset Document offset
|
|
|
|
* @returns {boolean} Data at offset is an element
|
2012-05-11 00:20:57 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.isElementData = function ( data, offset ) {
|
2012-05-11 00:20:57 +00:00
|
|
|
// Data exists at offset and appears to be an element
|
|
|
|
return data[offset] !== undefined && typeof data[offset].type === 'string';
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Check for elements in document data.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-11 00:20:57 +00:00
|
|
|
* This method assumes that any value that has a type property that's a string is an element object.
|
|
|
|
* Elements are discovered by iterating through the entire data array (backwards).
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-11 00:20:57 +00:00
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {Array} data Document data
|
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
|
|
|
* @returns {boolean} At least one elements exists in data
|
2012-05-11 00:20:57 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.containsElementData = function ( data ) {
|
2012-05-11 00:20:57 +00:00
|
|
|
var i = data.length;
|
|
|
|
while ( i-- ) {
|
|
|
|
if ( data[i].type !== undefined ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2012-05-31 13:19:34 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Check for non-content elements in document data.
|
2012-05-31 13:19:34 +00:00
|
|
|
*
|
|
|
|
* This method assumes that any value that has a type property that's a string is an element object.
|
|
|
|
* Elements are discovered by iterating through the entire data array.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {Array} data Document data
|
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
|
|
|
* @returns {boolean} True if all elements in data are content elements
|
2012-05-31 13:19:34 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.isContentData = function ( data ) {
|
2012-05-31 13:19:34 +00:00
|
|
|
for ( var i = 0, len = data.length; i < len; i++ ) {
|
|
|
|
if ( data[i].type !== undefined &&
|
|
|
|
data[i].type.charAt( 0 ) !== '/' &&
|
2012-05-31 22:20:58 +00:00
|
|
|
!ve.dm.nodeFactory.isNodeContent( data[i].type )
|
2012-05-31 13:19:34 +00:00
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2013-02-14 23:21:53 +00:00
|
|
|
/**
|
|
|
|
* Get a slice or copy of the provided data.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {Array} sourceData Source data to slice up
|
|
|
|
* @param {ve.Range} [range] Range of data to get, all data will be given by default
|
|
|
|
* @param {boolean} [deep=false] Whether to return a deep copy (WARNING! This may be very slow)
|
|
|
|
* @returns {Array} Slice or copy of document data
|
|
|
|
*/
|
|
|
|
ve.dm.Document.getDataSlice = function ( sourceData, range, deep ) {
|
|
|
|
var end, data,
|
|
|
|
start = 0;
|
|
|
|
if ( range !== undefined ) {
|
|
|
|
start = Math.max( 0, Math.min( sourceData.length, range.start ) );
|
|
|
|
end = Math.max( 0, Math.min( sourceData.length, range.end ) );
|
|
|
|
}
|
|
|
|
// IE work-around: arr.slice( 0, undefined ) returns [] while arr.slice( 0 ) behaves correctly
|
|
|
|
data = end === undefined ? sourceData.slice( start ) : sourceData.slice( start, end );
|
|
|
|
// Return either the slice or a deep copy of the slice
|
|
|
|
return deep ? ve.copyArray( data ) : data;
|
|
|
|
};
|
|
|
|
|
2012-04-27 02:44:44 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2012-06-07 03:28:06 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Reverse a transaction's effects on the content data.
|
2012-06-13 23:06:21 +00:00
|
|
|
*
|
2012-06-07 03:28:06 +00:00
|
|
|
* @method
|
|
|
|
* @param {ve.dm.Transaction}
|
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.rollback = function ( transaction ) {
|
2012-06-07 03:28:06 +00:00
|
|
|
ve.dm.TransactionProcessor.rollback( this, transaction );
|
|
|
|
};
|
|
|
|
|
2012-06-08 23:21:47 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Apply a transaction's effects on the content data.
|
2012-06-13 23:06:21 +00:00
|
|
|
*
|
2012-06-08 23:21:47 +00:00
|
|
|
* @method
|
|
|
|
* @param {ve.dm.Transaction}
|
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.commit = function ( transaction ) {
|
2012-06-08 23:21:47 +00:00
|
|
|
ve.dm.TransactionProcessor.commit( this, transaction );
|
|
|
|
};
|
|
|
|
|
2012-05-17 18:23:56 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get a slice or copy of the document data.
|
2012-05-17 18:23:56 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.Range} [range] Range of data to get, all data will be given by default
|
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 {boolean} [deep=false] Whether to return a deep copy (WARNING! This may be very slow)
|
2012-05-17 18:23:56 +00:00
|
|
|
* @returns {Array} Slice or copy of document data
|
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.getData = function ( range, deep ) {
|
2013-02-14 23:21:53 +00:00
|
|
|
return this.constructor.getDataSlice( this.data, range, deep );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a slice or copy of the document metadata.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.Range} [range] Range of metadata to get, all metadata will be given by default
|
|
|
|
* @param {boolean} [deep=false] Whether to return a deep copy (WARNING! This may be very slow)
|
|
|
|
* @returns {Array} Slice or copy of document metadata
|
|
|
|
*/
|
|
|
|
ve.dm.Document.prototype.getMetadata = function ( range, deep ) {
|
|
|
|
return this.constructor.getDataSlice( this.metadata, range, deep );
|
2012-05-17 18:23:56 +00:00
|
|
|
};
|
|
|
|
|
2012-08-02 00:59:38 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the length of the document.
|
2012-08-02 00:59:38 +00:00
|
|
|
*
|
|
|
|
* @method
|
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
|
|
|
* @returns {number} Document data length
|
2012-08-02 00:59:38 +00:00
|
|
|
*/
|
|
|
|
ve.dm.Document.prototype.getLength = function () {
|
|
|
|
return this.data.length;
|
|
|
|
};
|
|
|
|
|
2012-10-30 01:42:12 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Splice data into and/or out of the linear model.
|
|
|
|
*
|
2013-01-22 22:41:22 +00:00
|
|
|
* `this.metadata` will be updated accordingly.
|
2012-10-30 01:42:12 +00:00
|
|
|
*
|
2013-01-22 22:41:22 +00:00
|
|
|
* Always use this function, never use `this.data.splice()` directly, otherwise the linear model
|
|
|
|
* (`this.data`) and the meta-linmod (`this.metadata`) can get out of sync. The semantics of the
|
|
|
|
* parameters are identical to those of ve#batchSplice
|
2012-10-30 01:42:12 +00:00
|
|
|
*
|
|
|
|
* @method
|
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
|
|
|
* @see ve#batchSplice
|
|
|
|
* @param offset
|
|
|
|
* @param remove
|
|
|
|
* @param insert
|
2012-10-30 01:42:12 +00:00
|
|
|
*/
|
|
|
|
ve.dm.Document.prototype.spliceData = function ( offset, remove, insert ) {
|
|
|
|
var spliced, reaped, reapedFlat, i;
|
|
|
|
insert = insert || [];
|
|
|
|
spliced = ve.batchSplice( this.data, offset, remove, insert );
|
|
|
|
reaped = ve.batchSplice( this.metadata, offset, remove, new Array( insert.length ) );
|
|
|
|
// reaped will be an array of arrays, flatten it
|
|
|
|
reapedFlat = [];
|
|
|
|
for ( i = 0; i < reaped.length; i++ ) {
|
|
|
|
if ( reaped[i] !== undefined ) {
|
|
|
|
reapedFlat = reapedFlat.concat( reaped[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Add reaped metadata to the metadata that is now at offset (and used to be immediately
|
|
|
|
// after the removed data). Add it to the front, because it came from something that was
|
|
|
|
// before it.
|
|
|
|
if ( reapedFlat.length > 0 ) {
|
|
|
|
this.metadata[offset] = reapedFlat.concat( this.metadata[offset] || [] );
|
|
|
|
}
|
|
|
|
return spliced;
|
|
|
|
};
|
|
|
|
|
2013-02-14 23:21:53 +00:00
|
|
|
/**
|
|
|
|
* Splice metadata into and/or out of the linear model.
|
|
|
|
*
|
|
|
|
* `this.metadata` will be updated accordingly.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @see ve#batchSplice
|
|
|
|
* @param offset
|
|
|
|
* @param index
|
|
|
|
* @param remove
|
|
|
|
* @param insert
|
|
|
|
*/
|
|
|
|
ve.dm.Document.prototype.spliceMetadata = function ( offset, index, remove, insert ) {
|
|
|
|
var elements = this.metadata[offset];
|
|
|
|
if ( !elements ) {
|
|
|
|
this.metadata[offset] = elements = [];
|
|
|
|
}
|
|
|
|
insert = insert || [];
|
|
|
|
return ve.batchSplice( elements, index, remove, insert );
|
|
|
|
};
|
|
|
|
|
2012-10-30 01:42:12 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the full document data including metadata.
|
|
|
|
*
|
|
|
|
* Metadata will be into the document data to produce the "full data" result.
|
|
|
|
*
|
2012-10-30 01:42:12 +00:00
|
|
|
* @returns {Array} Data with metadata interleaved
|
|
|
|
*/
|
|
|
|
ve.dm.Document.prototype.getFullData = function () {
|
|
|
|
var result = [], i, j, len = this.data.length;
|
|
|
|
for ( i = 0; i <= len; i++ ) {
|
|
|
|
if ( this.metadata[i] ) {
|
|
|
|
for ( j = 0; j < this.metadata[i].length; j++ ) {
|
|
|
|
result.push( this.metadata[i][j] );
|
|
|
|
result.push( { 'type': '/' + this.metadata[i][j].type } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( i < len ) {
|
|
|
|
result.push( this.data[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get a node from an offset.
|
|
|
|
*
|
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
|
|
|
* @method
|
|
|
|
* @param offset
|
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.getNodeFromOffset = function ( offset ) {
|
2012-06-13 23:16:07 +00:00
|
|
|
// FIXME duplicated from ve.ce.Document
|
2012-10-01 18:23:39 +00:00
|
|
|
if ( offset < 0 || offset > this.data.length ) {
|
|
|
|
throw new Error( 've.dm.Document.getNodeFromOffset(): offset ' + offset + ' is out of bounds' );
|
|
|
|
}
|
2012-06-13 23:16:07 +00:00
|
|
|
var node = this.documentNode.getNodeFromOffset( offset );
|
|
|
|
if ( !node.canHaveChildren() ) {
|
|
|
|
node = node.getParent();
|
|
|
|
}
|
|
|
|
return node;
|
2012-05-17 18:23:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the content data of a node.
|
2012-05-17 18:23:56 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.Node} node Node to get content data for
|
|
|
|
* @returns {Array|null} List of content and elements inside node or null if node is not found
|
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.getDataFromNode = function ( node ) {
|
2012-05-17 18:23:56 +00:00
|
|
|
var length = node.getLength(),
|
|
|
|
offset = this.documentNode.getOffsetFromNode( node );
|
|
|
|
if ( offset >= 0 ) {
|
|
|
|
// XXX: If the node is wrapped in an element than we should increment the offset by one so
|
|
|
|
// we only return the content inside the element.
|
|
|
|
if ( node.isWrapped() ) {
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
return this.data.slice( offset, offset + length );
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2012-09-07 01:04:51 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get plain text of a range.
|
2012-09-07 01:04:51 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.Range} [range] Range of data to get the text of.
|
2013-01-08 21:02:12 +00:00
|
|
|
* @returns {string|''} Selected text or an empty string.
|
2012-09-07 01:04:51 +00:00
|
|
|
*/
|
|
|
|
ve.dm.Document.prototype.getText = function ( range ) {
|
|
|
|
var data = this.getData( range ),
|
|
|
|
str = '',
|
|
|
|
i;
|
|
|
|
for ( i = 0; i < data.length; i++ ) {
|
|
|
|
if ( typeof data[i] === 'string' ) {
|
|
|
|
str += data[i];
|
|
|
|
} else if ( ve.isArray( data[i] ) ) {
|
|
|
|
str += data[i][0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
};
|
|
|
|
|
2012-05-17 18:23:56 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get annotations covered by an offset.
|
2012-05-17 18:23:56 +00:00
|
|
|
*
|
2013-01-15 23:38:49 +00:00
|
|
|
* The returned AnnotationSet is a clone of the one in the document data.
|
2012-08-24 02:06:36 +00:00
|
|
|
*
|
2012-05-17 18:23:56 +00:00
|
|
|
* @method
|
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 {number} offset Offset to get annotations for
|
2012-08-24 02:06:36 +00:00
|
|
|
* @returns {ve.AnnotationSet} A set of all annotation objects offset is covered by
|
2012-05-17 18:23:56 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.getAnnotationsFromOffset = function ( offset ) {
|
2012-10-01 18:29:46 +00:00
|
|
|
if ( offset < 0 || offset > this.data.length ) {
|
|
|
|
throw new Error( 've.dm.Document.getAnnotationsFromOffset: offset ' + offset + ' out of bounds' );
|
|
|
|
}
|
2012-05-21 19:02:04 +00:00
|
|
|
// Since annotations are not stored on a closing leaf node,
|
|
|
|
// rewind offset by 1 to return annotations for that structure
|
The great inspector and context rewrite of 2012
ve.AnnotationAction
* Added filter to the clearAll method to allow clearing all matching annotations only
ve.dm.Document
* Some variable renaming for consistency
ve.dm.SurfaceFragment
* Added truncateRange method
* Added annotation scope to expandRange method
* Added support for passing an annotation object into annotateContent method
* Switched to using name instead of type in annotateContent method to match the ve.dm.Annotation class
* Fixed logic in annotation mode of expandSelection so that expansion only takes place if the annotation is found
ve.ui.LinkInspector
* Moved most of the functionality elsewhere
* General reorganization
* Changed setOverlayPosition to accept 2 arguments instead of an object with 2 properties and renamed it to positionOverlayBelow
* Check for annotation object before extracting target information from it
* Initialize default target as empty string to avoid undefined being cast to a string and the default target becoming 'undefined'
icons.ai, inspector.png, inspector.svg
* Added generic inspector icon which will be used when a custom icon is not specified in future inspector subclasses
ve.ui.Inspector.Icons
* Added inspector icon
* Renamed clear icon to remove to match it's actual image
ve.ui.Context
* Greatly simplified the interface, reducing the number of methods by inlining a few things and combining others
* Now always listening to resize events on the window rather than only while document is focused
* Not listening to scroll events anymore, they used to affect the top/bottom positioning of the menu which we don't do anymore
* Lots of cleanup and reorganization
* No need to fallback to empty array since getInspectorsForAnnotations does so already
* Only consider fully-covered annotations for inspectors
ve.ui.Frame
* Simplified the constructor by introducing the createFrame method
* General cleanup
* Typo fixes
ve.ui.Inspector
* Generalized lots of functionality previously located in the link inspector class which will be useful to all inspectors (such as title, clear button, saving changes, etc.)
* Added setDisabled and isDisabled methods to manage CSS changes and avoid needing to check the CSS to determine the state of the inspector (storing state in the view is evil)
* Added getMatchingAnnotations method for convenience
* Added prepareSelection stub
* Lots of cleanup and documentation
* Type pattern is now defined in base class
* Added stubs for onOpen and onClose with documentation so that subclass authors know what these methods do
* Removed checks for onOpen or onClose methods since they are now noop stubs and are always there
* Added stub and removed checks for onRemove
* Made esc key close and accept - the illusion is supposed to be that the link changes are applied instantly, even though they are only updated when you close, so all closing except for when removing should apply changes - i.e. esc is now equal to back rather than being a special function that doesn't have an associated affordance
* Only consider fully-covered annotations when getting matching annotations
ve.ui.InspectorFactory
* Depending on type pattern now since it's always there
* Added getInspectorsForAnnotations method
* Return empty array if annotation set is empty
VisualEditor, VisualEditor.i18n
* Added default inspector message
Change-Id: I1cc008445bcbc8cba6754ca4b6ac0397575980d5
2012-11-16 20:40:05 +00:00
|
|
|
var annotations;
|
2012-05-21 19:02:04 +00:00
|
|
|
if (
|
|
|
|
ve.isPlainObject( this.data[offset] ) && // structural offset
|
2012-08-24 02:06:36 +00:00
|
|
|
this.data[offset].hasOwnProperty( 'type' ) && // just in case
|
2012-05-21 19:02:04 +00:00
|
|
|
this.data[offset].type.charAt( 0 ) === '/' && // closing offset
|
2012-05-31 22:20:58 +00:00
|
|
|
ve.dm.nodeFactory.canNodeHaveChildren(
|
2012-05-21 19:02:04 +00:00
|
|
|
this.data[offset].type.substr( 1 )
|
|
|
|
) === false // leaf node
|
2012-08-07 01:50:44 +00:00
|
|
|
) {
|
2012-05-21 19:02:04 +00:00
|
|
|
offset = this.getRelativeContentOffset( offset, -1 );
|
|
|
|
}
|
|
|
|
|
The great inspector and context rewrite of 2012
ve.AnnotationAction
* Added filter to the clearAll method to allow clearing all matching annotations only
ve.dm.Document
* Some variable renaming for consistency
ve.dm.SurfaceFragment
* Added truncateRange method
* Added annotation scope to expandRange method
* Added support for passing an annotation object into annotateContent method
* Switched to using name instead of type in annotateContent method to match the ve.dm.Annotation class
* Fixed logic in annotation mode of expandSelection so that expansion only takes place if the annotation is found
ve.ui.LinkInspector
* Moved most of the functionality elsewhere
* General reorganization
* Changed setOverlayPosition to accept 2 arguments instead of an object with 2 properties and renamed it to positionOverlayBelow
* Check for annotation object before extracting target information from it
* Initialize default target as empty string to avoid undefined being cast to a string and the default target becoming 'undefined'
icons.ai, inspector.png, inspector.svg
* Added generic inspector icon which will be used when a custom icon is not specified in future inspector subclasses
ve.ui.Inspector.Icons
* Added inspector icon
* Renamed clear icon to remove to match it's actual image
ve.ui.Context
* Greatly simplified the interface, reducing the number of methods by inlining a few things and combining others
* Now always listening to resize events on the window rather than only while document is focused
* Not listening to scroll events anymore, they used to affect the top/bottom positioning of the menu which we don't do anymore
* Lots of cleanup and reorganization
* No need to fallback to empty array since getInspectorsForAnnotations does so already
* Only consider fully-covered annotations for inspectors
ve.ui.Frame
* Simplified the constructor by introducing the createFrame method
* General cleanup
* Typo fixes
ve.ui.Inspector
* Generalized lots of functionality previously located in the link inspector class which will be useful to all inspectors (such as title, clear button, saving changes, etc.)
* Added setDisabled and isDisabled methods to manage CSS changes and avoid needing to check the CSS to determine the state of the inspector (storing state in the view is evil)
* Added getMatchingAnnotations method for convenience
* Added prepareSelection stub
* Lots of cleanup and documentation
* Type pattern is now defined in base class
* Added stubs for onOpen and onClose with documentation so that subclass authors know what these methods do
* Removed checks for onOpen or onClose methods since they are now noop stubs and are always there
* Added stub and removed checks for onRemove
* Made esc key close and accept - the illusion is supposed to be that the link changes are applied instantly, even though they are only updated when you close, so all closing except for when removing should apply changes - i.e. esc is now equal to back rather than being a special function that doesn't have an associated affordance
* Only consider fully-covered annotations when getting matching annotations
ve.ui.InspectorFactory
* Depending on type pattern now since it's always there
* Added getInspectorsForAnnotations method
* Return empty array if annotation set is empty
VisualEditor, VisualEditor.i18n
* Added default inspector message
Change-Id: I1cc008445bcbc8cba6754ca4b6ac0397575980d5
2012-11-16 20:40:05 +00:00
|
|
|
annotations = this.data[offset].annotations || this.data[offset][1];
|
|
|
|
return annotations ? annotations.clone() : new ve.AnnotationSet();
|
2012-05-17 18:23:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-16 20:37:52 +00:00
|
|
|
* Gets the range of content surrounding a given offset that's covered by a given annotation.
|
2012-05-17 18:23:56 +00:00
|
|
|
*
|
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 {number} offset Offset to begin looking forward and backward from
|
2012-05-17 18:23:56 +00:00
|
|
|
* @param {Object} annotation Annotation to test for coverage with
|
|
|
|
* @returns {ve.Range|null} Range of content covered by annotation, or null if offset is not covered
|
|
|
|
*/
|
|
|
|
ve.dm.Document.prototype.getAnnotatedRangeFromOffset = function ( offset, annotation ) {
|
|
|
|
var start = offset,
|
|
|
|
end = offset;
|
2013-01-16 20:37:52 +00:00
|
|
|
if ( this.getAnnotationsFromOffset( offset ).contains( annotation ) === false ) {
|
2012-05-17 18:23:56 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
while ( start > 0 ) {
|
|
|
|
start--;
|
2013-01-16 20:37:52 +00:00
|
|
|
if ( this.getAnnotationsFromOffset( start ).contains( annotation ) === false ) {
|
2012-05-17 18:23:56 +00:00
|
|
|
start++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while ( end < this.data.length ) {
|
2013-01-16 20:37:52 +00:00
|
|
|
if ( this.getAnnotationsFromOffset( end ).contains( annotation ) === false ) {
|
2012-07-24 17:42:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
return new ve.Range( start, end );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the range of an annotation found within a range.
|
2012-07-24 17:42:29 +00:00
|
|
|
*
|
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 {number} offset Offset to begin looking forward and backward from
|
2012-07-24 17:42:29 +00:00
|
|
|
* @param {Object} annotation Annotation to test for coverage with
|
|
|
|
* @returns {ve.Range|null} Range of content covered by annotation, or a copy of the range.
|
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.getAnnotatedRangeFromSelection = function ( range, annotation ) {
|
2012-07-24 17:42:29 +00:00
|
|
|
var start = range.start,
|
|
|
|
end = range.end;
|
|
|
|
while ( start > 0 ) {
|
|
|
|
start--;
|
2013-01-16 20:37:52 +00:00
|
|
|
if ( this.getAnnotationsFromOffset( start ).contains( annotation ) === false ) {
|
2012-07-24 17:42:29 +00:00
|
|
|
start++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while ( end < this.data.length ) {
|
2013-01-16 20:37:52 +00:00
|
|
|
if ( this.getAnnotationsFromOffset( end ).contains( annotation ) === false ) {
|
2012-05-17 18:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-05-17 20:17:18 +00:00
|
|
|
end++;
|
2012-05-17 18:23:56 +00:00
|
|
|
}
|
|
|
|
return new ve.Range( start, end );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get annotations common to all content in a range.
|
2012-05-17 18:23:56 +00:00
|
|
|
*
|
|
|
|
* @method
|
2012-10-24 22:22:27 +00:00
|
|
|
* @param {ve.Range} range Range to get annotations for
|
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 {boolean} [all] Get all annotations found within the range, not just those that cover it
|
2012-10-24 22:22:27 +00:00
|
|
|
* @returns {ve.AnnotationSet} All annotation objects range is covered by
|
2012-05-17 18:23:56 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.getAnnotationsFromRange = function ( range, all ) {
|
2012-08-02 18:46:13 +00:00
|
|
|
var i,
|
2012-06-13 21:31:33 +00:00
|
|
|
left,
|
2012-09-10 21:31:18 +00:00
|
|
|
right;
|
2012-10-31 22:17:20 +00:00
|
|
|
// Look at left side of range for annotations
|
2012-06-13 21:31:33 +00:00
|
|
|
left = this.getAnnotationsFromOffset( range.start );
|
2012-10-31 22:17:20 +00:00
|
|
|
// Shortcut for single character and zero-length ranges
|
|
|
|
if ( range.getLength() === 0 || range.getLength() === 1 ) {
|
2012-06-13 21:31:33 +00:00
|
|
|
return left;
|
|
|
|
}
|
|
|
|
// Iterator over the range, looking for annotations, starting at the 2nd character
|
2012-08-02 18:46:13 +00:00
|
|
|
for ( i = range.start + 1; i < range.end; i++ ) {
|
2012-06-13 21:31:33 +00:00
|
|
|
// Skip non character data
|
2012-05-17 18:23:56 +00:00
|
|
|
if ( ve.dm.Document.isElementData( this.data, i ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-06-13 21:31:33 +00:00
|
|
|
// Current character annotations
|
|
|
|
right = this.getAnnotationsFromOffset( i );
|
2012-08-24 02:06:36 +00:00
|
|
|
if ( all && !right.isEmpty() ) {
|
|
|
|
left.addSet( right );
|
2012-06-13 21:31:33 +00:00
|
|
|
} else if ( !all ) {
|
|
|
|
// A non annotated character indicates there's no full coverage
|
2012-08-24 02:06:36 +00:00
|
|
|
if ( right.isEmpty() ) {
|
|
|
|
return new ve.AnnotationSet();
|
2012-06-13 21:31:33 +00:00
|
|
|
}
|
|
|
|
// Exclude annotations that are in left but not right
|
2012-08-24 02:06:36 +00:00
|
|
|
left.removeNotInSet( right );
|
2012-06-13 21:31:33 +00:00
|
|
|
// If we've reduced left down to nothing, just stop looking
|
2012-08-24 02:06:36 +00:00
|
|
|
if ( left.isEmpty() ) {
|
2012-06-13 21:31:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-05-17 18:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-13 21:31:33 +00:00
|
|
|
return left;
|
2012-05-17 18:23:56 +00:00
|
|
|
};
|
|
|
|
|
2012-07-03 20:28:10 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get a range without any whitespace content at the beginning and end.
|
2012-07-03 20:28:10 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.Range} [range] Range of data to get, all data will be given by default
|
|
|
|
* @returns {Object} A new range if modified, otherwise returns passed range.
|
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.trimOuterSpaceFromRange = function ( range ) {
|
2012-10-15 18:45:50 +00:00
|
|
|
var start = range.start,
|
2012-07-03 20:28:10 +00:00
|
|
|
end = range.end;
|
(bug 42925) Inspector doesn't open properly
ve.Range
* Rewrote truncate so that it works as expected, truncation should always reduce the length using the start/end values, not the from/to values
ve.ui.Inspector
* Added a comment about where the name argument to onBeforeInspectorOpen comes from, since it's a little bit confusing on first read (and I wrote it!)
* Calling onInitialize, onOpen and onClose methods directly, since we need to control the before or after-ness of listeners getting in there and doing their stuff - plus it's more direct
* Removed onRemove stub, which is never actually called
* Added before/after versions of initialize, open and close events
* Got rid of recursion guard since we don't need it anymore thanks to changes made in ve.dm.Surface (see below)
ve.ui.Context
* Updated event names to deal with new before/after naming of initialize, open and close events
* Removed fade-in logic since fading in doesn't even work anymore - since now we now annotate first, then open the inspector, the menu will actually exist and be open when we open the inspector even though you don't see it because it's quickly obscured
ve.ui.LinkInspector
* Made fragments non-auto selecting, in the case of onInitialize we actually call select(), which is silly since we were using an auto-selecting fragment - it's clear that this was a mistake
ve.dm.Surface
* Moved locking (polling stop and start) to the far outside edges of the change method
* I need a lot of eyes and testing on this change, it seems OK to me, but I'm suspicious that it may have side effects
* What was happening is that selection changes were being applied and then the poll was picking them up, and then the selection was coming in again as a change, but it wasn't a change at all, it was just feedback - this change event was then closing the inspector the instant it was opened - the odd part was that this only occurred when you selected backwards, which seems to be caused by the range being normalized, so it looked like a new selection even though it wasn't
ve.dm.Document
* trimOuterSpace from Range didn't consider annotated spaces to be spaces, by using the [0] trick (first character of a plain text character string or first element in an annotated character's array both are the character's value - but elements don't have a property named '0' so it skips those safely as well) we can always get the right value for comparison
Change-Id: I0873d906c058203b83b8d4bbe5a4b274f05a26fd
2012-12-10 21:36:28 +00:00
|
|
|
while ( this.data[start][0] === ' ' ) {
|
2012-07-03 20:28:10 +00:00
|
|
|
start++;
|
|
|
|
}
|
(bug 42925) Inspector doesn't open properly
ve.Range
* Rewrote truncate so that it works as expected, truncation should always reduce the length using the start/end values, not the from/to values
ve.ui.Inspector
* Added a comment about where the name argument to onBeforeInspectorOpen comes from, since it's a little bit confusing on first read (and I wrote it!)
* Calling onInitialize, onOpen and onClose methods directly, since we need to control the before or after-ness of listeners getting in there and doing their stuff - plus it's more direct
* Removed onRemove stub, which is never actually called
* Added before/after versions of initialize, open and close events
* Got rid of recursion guard since we don't need it anymore thanks to changes made in ve.dm.Surface (see below)
ve.ui.Context
* Updated event names to deal with new before/after naming of initialize, open and close events
* Removed fade-in logic since fading in doesn't even work anymore - since now we now annotate first, then open the inspector, the menu will actually exist and be open when we open the inspector even though you don't see it because it's quickly obscured
ve.ui.LinkInspector
* Made fragments non-auto selecting, in the case of onInitialize we actually call select(), which is silly since we were using an auto-selecting fragment - it's clear that this was a mistake
ve.dm.Surface
* Moved locking (polling stop and start) to the far outside edges of the change method
* I need a lot of eyes and testing on this change, it seems OK to me, but I'm suspicious that it may have side effects
* What was happening is that selection changes were being applied and then the poll was picking them up, and then the selection was coming in again as a change, but it wasn't a change at all, it was just feedback - this change event was then closing the inspector the instant it was opened - the odd part was that this only occurred when you selected backwards, which seems to be caused by the range being normalized, so it looked like a new selection even though it wasn't
ve.dm.Document
* trimOuterSpace from Range didn't consider annotated spaces to be spaces, by using the [0] trick (first character of a plain text character string or first element in an annotated character's array both are the character's value - but elements don't have a property named '0' so it skips those safely as well) we can always get the right value for comparison
Change-Id: I0873d906c058203b83b8d4bbe5a4b274f05a26fd
2012-12-10 21:36:28 +00:00
|
|
|
while ( this.data[end - 1][0] === ' ' ) {
|
2012-07-03 20:28:10 +00:00
|
|
|
end--;
|
|
|
|
}
|
|
|
|
return range.to < range.end ? new ve.Range( end, start ) : new ve.Range( start, end );
|
|
|
|
};
|
|
|
|
|
2012-04-27 02:44:44 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Rebuild one or more nodes following a change in document data.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-04-27 02:44:44 +00:00
|
|
|
* The data provided to this method may contain either one node or multiple sibling nodes, but it
|
|
|
|
* must be balanced and valid. Data provided to this method also may not contain any content at the
|
2012-06-13 23:16:07 +00:00
|
|
|
* top level. The tree is updated during this operation.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-04-27 02:44:44 +00:00
|
|
|
* Process:
|
|
|
|
* 1. Nodes between {index} and {index} + {numNodes} in {parent} will be removed
|
|
|
|
* 2. Data will be retrieved from this.data using {offset} and {newLength}
|
|
|
|
* 3. A document fragment will be generated from the retrieved data
|
2012-06-13 23:16:07 +00:00
|
|
|
* 4. The document fragment's nodes will be inserted into {parent} at {index}
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-04-27 02:44:44 +00:00
|
|
|
* Use cases:
|
|
|
|
* 1. Rebuild old nodes and offset data after a change to the linear model.
|
|
|
|
* 2. Insert new nodes and offset data after a insertion in the linear model.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-04-27 02:44:44 +00:00
|
|
|
* @param {ve.dm.Node} parent Parent of the node(s) being rebuilt
|
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 {number} index Index within parent to rebuild or insert nodes
|
2012-09-17 13:30:50 +00:00
|
|
|
* - If {numNodes} == 0: Index to insert nodes at
|
|
|
|
* - If {numNodes} >= 1: Index of first node to rebuild
|
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 {number} numNodes Total number of nodes to rebuild
|
2012-09-17 13:30:50 +00:00
|
|
|
* - If {numNodes} == 0: Nothing will be rebuilt, but the node(s) built from data will be
|
|
|
|
* inserted before {index}. To insert nodes at the end, use number of children in 'parent'
|
|
|
|
* - If {numNodes} == 1: Only the node at {index} will be rebuilt
|
|
|
|
* - If {numNodes} > 1: The node at {index} and the next {numNodes-1} nodes will be rebuilt
|
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 {number} offset Linear model offset to rebuild from
|
|
|
|
* @param {number} newLength Length of data in linear model to rebuild or insert nodes for
|
2012-04-27 02:44:44 +00:00
|
|
|
* @returns {ve.dm.Node[]} Array containing the rebuilt/inserted nodes
|
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.rebuildNodes = function ( parent, index, numNodes, offset, newLength ) {
|
2012-08-02 18:46:13 +00:00
|
|
|
var // Get a slice of the document where it's been changed
|
|
|
|
data = this.data.slice( offset, offset + newLength ),
|
|
|
|
// Build document fragment from data
|
|
|
|
fragment = new ve.dm.Document( data, this ),
|
|
|
|
// Get generated child nodes from the document fragment
|
|
|
|
nodes = fragment.getDocumentNode().getChildren();
|
2012-04-27 02:44:44 +00:00
|
|
|
// Replace nodes in the model tree
|
2012-04-27 22:09:10 +00:00
|
|
|
ve.batchSplice( parent, index, numNodes, nodes );
|
2012-04-27 02:44:44 +00:00
|
|
|
// Return inserted nodes
|
|
|
|
return nodes;
|
|
|
|
};
|
|
|
|
|
2012-05-04 18:07:55 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get an offset at a distance to an offset that passes a validity test.
|
2012-05-24 00:43:10 +00:00
|
|
|
*
|
|
|
|
* - If {offset} is not already valid, one step will be used to move it to an valid one.
|
2012-12-07 21:38:00 +00:00
|
|
|
* - If {offset} is already valid and cannot be moved in the direction of {distance} and still be
|
2012-11-28 01:29:09 +00:00
|
|
|
* valid, it will be left where it is
|
2012-05-24 00:43:10 +00:00
|
|
|
* - If {distance} is zero the result will either be {offset} if it's already valid or the
|
|
|
|
* nearest valid offset to the right if possible and to the left otherwise.
|
|
|
|
* - If {offset} is after the last valid offset and {distance} is >= 1, or if {offset} if
|
|
|
|
* before the first valid offset and {distance} <= 1 than the result will be the nearest
|
|
|
|
* valid offset in the opposite direction.
|
2012-05-24 18:43:25 +00:00
|
|
|
* - If the document does not contain a single valid offset the result will be -1
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-04 18:07:55 +00:00
|
|
|
* @method
|
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 {number} offset Offset to start from
|
|
|
|
* @param {number} distance Number of valid offsets to move
|
2012-05-24 00:43:10 +00:00
|
|
|
* @param {Function} callback Function to call to check if an offset is valid which will be
|
|
|
|
* given two intital arguments of data and offset
|
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 {Mixed...} [args] Additional arguments to pass to the callback
|
|
|
|
* @returns {number} Relative valid offset or -1 if there are no valid offsets in document
|
2012-05-04 18:07:55 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.getRelativeOffset = function ( offset, distance, callback ) {
|
2012-08-02 18:46:13 +00:00
|
|
|
var i, direction,
|
|
|
|
args = Array.prototype.slice.call( arguments, 3 ),
|
|
|
|
start = offset,
|
|
|
|
steps = 0,
|
|
|
|
turnedAround = false;
|
2012-05-24 00:43:10 +00:00
|
|
|
// If offset is already a structural offset and distance is zero than no further work is needed,
|
|
|
|
// otherwise distance should be 1 so that we can get out of the invalid starting offset
|
2012-05-11 00:20:57 +00:00
|
|
|
if ( distance === 0 ) {
|
2012-05-24 00:43:10 +00:00
|
|
|
if ( callback.apply( window, [this.data, offset].concat( args ) ) ) {
|
|
|
|
return offset;
|
|
|
|
} else {
|
|
|
|
distance = 1;
|
|
|
|
}
|
2012-05-11 00:20:57 +00:00
|
|
|
}
|
2012-08-02 18:46:13 +00:00
|
|
|
// Initial values
|
|
|
|
direction = (
|
|
|
|
offset <= 0 ? 1 : (
|
|
|
|
offset >= this.data.length ? -1 : (
|
|
|
|
distance > 0 ? 1 : -1
|
2012-05-24 00:43:10 +00:00
|
|
|
)
|
2012-08-02 18:46:13 +00:00
|
|
|
)
|
|
|
|
);
|
2012-05-11 00:20:57 +00:00
|
|
|
distance = Math.abs( distance );
|
2012-08-02 18:46:13 +00:00
|
|
|
i = start + direction;
|
2012-05-24 18:43:25 +00:00
|
|
|
offset = -1;
|
2012-08-02 18:46:13 +00:00
|
|
|
// Iteration
|
2012-05-24 00:43:10 +00:00
|
|
|
while ( i >= 0 && i <= this.data.length ) {
|
|
|
|
if ( callback.apply( window, [this.data, i].concat( args ) ) ) {
|
2012-05-11 00:20:57 +00:00
|
|
|
steps++;
|
|
|
|
offset = i;
|
|
|
|
if ( distance === steps ) {
|
|
|
|
return offset;
|
|
|
|
}
|
2012-05-24 00:43:10 +00:00
|
|
|
} else if (
|
|
|
|
// Don't keep turning around over and over
|
|
|
|
!turnedAround &&
|
|
|
|
// Only turn around if not a single step could be taken
|
|
|
|
steps === 0 &&
|
|
|
|
// Only turn around if we're about to reach the edge
|
|
|
|
( ( direction < 0 && i === 0 ) || ( direction > 0 && i === this.data.length ) )
|
|
|
|
) {
|
2012-11-28 01:29:09 +00:00
|
|
|
// Before we turn around, let's see if we are at a valid position
|
|
|
|
if ( callback.apply( window, [this.data, start].concat( args ) ) ) {
|
|
|
|
// Stay where we are
|
|
|
|
return start;
|
|
|
|
}
|
2012-05-24 00:43:10 +00:00
|
|
|
// Start over going in the opposite direction
|
|
|
|
direction *= -1;
|
|
|
|
i = start;
|
|
|
|
distance = 1;
|
|
|
|
turnedAround = true;
|
2012-05-04 18:07:55 +00:00
|
|
|
}
|
2012-05-11 00:20:57 +00:00
|
|
|
i += direction;
|
2012-05-04 18:07:55 +00:00
|
|
|
}
|
2012-05-11 00:20:57 +00:00
|
|
|
return offset;
|
2012-05-04 18:07:55 +00:00
|
|
|
};
|
|
|
|
|
2012-05-24 00:43:10 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get a content offset at a distance from an offset.
|
2012-05-24 00:43:10 +00:00
|
|
|
*
|
|
|
|
* This method is a wrapper around {getRelativeOffset}, using {ve.dm.Document.isContentOffset} as
|
|
|
|
* the offset validation callback.
|
|
|
|
*
|
|
|
|
* @method
|
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 {number} offset Offset to start from
|
|
|
|
* @param {number} distance Number of content offsets to move
|
|
|
|
* @returns {number} Relative content offset or -1 if there are no valid offsets in document
|
2012-05-24 00:43:10 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.getRelativeContentOffset = function ( offset, distance ) {
|
2012-05-24 00:43:10 +00:00
|
|
|
return this.getRelativeOffset( offset, distance, ve.dm.Document.isContentOffset );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the nearest content offset to an offset.
|
2012-05-24 00:43:10 +00:00
|
|
|
*
|
|
|
|
* If the offset is already a valid offset, it will be returned unchanged. This method differs from
|
|
|
|
* calling {getRelativeContentOffset} with a zero length differece because the direction can be
|
|
|
|
* controlled without nessecarily moving the offset if it's already valid. Also, if the direction
|
|
|
|
* is 0 or undefined than nearest offsets will be found to the left and right and the one with the
|
|
|
|
* shortest distance will be used.
|
|
|
|
*
|
|
|
|
* This method is a wrapper around {getRelativeOffset}, using {ve.dm.Document.isContentOffset} as
|
|
|
|
* the offset validation callback.
|
|
|
|
*
|
|
|
|
* @method
|
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 {number} offset Offset to start from
|
|
|
|
* @param {number} [direction] Direction to prefer matching offset in, -1 for left and 1 for right
|
|
|
|
* @returns {number} Nearest content offset or -1 if there are no valid offsets in document
|
2012-05-24 00:43:10 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.getNearestContentOffset = function ( offset, direction ) {
|
2012-05-25 03:53:50 +00:00
|
|
|
if ( ve.dm.Document.isContentOffset( this.data, offset ) ) {
|
|
|
|
return offset;
|
|
|
|
}
|
2012-05-24 00:43:10 +00:00
|
|
|
if ( direction === undefined ) {
|
|
|
|
var left = this.getRelativeOffset( offset, -1, ve.dm.Document.isContentOffset ),
|
|
|
|
right = this.getRelativeOffset( offset, 1, ve.dm.Document.isContentOffset );
|
|
|
|
return offset - left < right - offset ? left : right;
|
|
|
|
} else {
|
|
|
|
return this.getRelativeOffset(
|
|
|
|
offset, direction > 0 ? 1 : -1, ve.dm.Document.isContentOffset
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get a structural offset at a distance from an offset.
|
2012-05-24 00:43:10 +00:00
|
|
|
*
|
|
|
|
* This method is a wrapper around {getRelativeOffset}, using {ve.dm.Document.isStructuralOffset} as
|
|
|
|
* the offset validation callback.
|
|
|
|
*
|
|
|
|
* @method
|
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 {number} offset Offset to start from
|
|
|
|
* @param {number} distance Number of structural offsets to move
|
|
|
|
* @param {boolean} [unrestricted] Only return true if any kind of element can be inserted at offset
|
|
|
|
* @returns {number} Relative structural offset
|
2012-05-24 00:43:10 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.getRelativeStructuralOffset = function ( offset, distance, unrestricted ) {
|
2012-05-24 00:43:10 +00:00
|
|
|
// Optimization: start and end are always unrestricted structural offsets
|
|
|
|
if ( distance === 0 && ( offset === 0 || offset === this.data.length ) ) {
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
return this.getRelativeOffset(
|
|
|
|
offset, distance, ve.dm.Document.isStructuralOffset, unrestricted
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the nearest structural offset to an offset.
|
2012-05-24 00:43:10 +00:00
|
|
|
*
|
|
|
|
* If the offset is already a valid offset, it will be returned unchanged. This method differs from
|
|
|
|
* calling {getRelativeStructuralOffset} with a zero length differece because the direction can be
|
|
|
|
* controlled without nessecarily moving the offset if it's already valid. Also, if the direction
|
|
|
|
* is 0 or undefined than nearest offsets will be found to the left and right and the one with the
|
|
|
|
* shortest distance will be used.
|
|
|
|
*
|
|
|
|
* This method is a wrapper around {getRelativeOffset}, using {ve.dm.Document.isStructuralOffset} as
|
|
|
|
* the offset validation callback.
|
|
|
|
*
|
|
|
|
* @method
|
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 {number} offset Offset to start from
|
|
|
|
* @param {number} [direction] Direction to prefer matching offset in, -1 for left and 1 for right
|
|
|
|
* @param {boolean} [unrestricted] Only return true if any kind of element can be inserted at offset
|
|
|
|
* @returns {number} Nearest structural offset
|
2012-05-24 00:43:10 +00:00
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.getNearestStructuralOffset = function ( offset, direction, unrestricted ) {
|
2012-05-25 03:53:50 +00:00
|
|
|
if ( ve.dm.Document.isStructuralOffset( this.data, offset, unrestricted ) ) {
|
|
|
|
return offset;
|
|
|
|
}
|
2012-05-24 00:43:10 +00:00
|
|
|
if ( !direction ) {
|
|
|
|
var left = this.getRelativeOffset(
|
|
|
|
offset, -1, ve.dm.Document.isStructuralOffset, unrestricted
|
|
|
|
),
|
|
|
|
right = this.getRelativeOffset(
|
|
|
|
offset, 1, ve.dm.Document.isStructuralOffset, unrestricted
|
|
|
|
);
|
|
|
|
return offset - left < right - offset ? left : right;
|
|
|
|
} else {
|
|
|
|
return this.getRelativeOffset(
|
|
|
|
offset, direction > 0 ? 1 : -1, ve.dm.Document.isStructuralOffset, unrestricted
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-11-21 21:22:29 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the nearest word boundary.
|
2012-11-21 21:22:29 +00:00
|
|
|
*
|
|
|
|
* The offset will first be moved to the nearest content offset if it's not at one already. If a
|
|
|
|
* direction was given, the boundary will be found in that direction, otherwise both directions will
|
|
|
|
* be calculated and the one with the lowest distance from offset will be returned. Elements are
|
|
|
|
* always word boundaries. For more information about what is considered to be a word character,
|
|
|
|
* see {ve.dm.SurfaceFragment.wordPattern}.
|
|
|
|
*
|
|
|
|
* @method
|
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 {number} offset Offset to start from
|
|
|
|
* @param {number} [direction] Direction to prefer matching offset in, -1 for left and 1 for right
|
|
|
|
* @returns {number} Nearest word boundary
|
2012-11-21 21:22:29 +00:00
|
|
|
*/
|
|
|
|
ve.dm.Document.prototype.getNearestWordBoundary = function ( offset, direction ) {
|
|
|
|
var left, right, i, inc,
|
|
|
|
pattern = ve.dm.SurfaceFragment.wordBoundaryPattern,
|
|
|
|
data = this.data;
|
|
|
|
offset = this.getNearestContentOffset( offset );
|
|
|
|
if ( !direction ) {
|
|
|
|
left = this.getNearestWordBoundary( offset, -1 );
|
|
|
|
right = this.getNearestWordBoundary( offset, +1 );
|
|
|
|
return offset - left < right - offset ? left : right;
|
|
|
|
} else {
|
|
|
|
inc = direction > 0 ? 1 : -1;
|
|
|
|
i = offset + ( inc > 0 ? 0 : -1 );
|
|
|
|
do {
|
|
|
|
if ( data[i].type === undefined ) {
|
|
|
|
// Plain text extraction
|
|
|
|
if ( pattern.test( typeof data[i] === 'string' ? data[i] : data[i][0] ) ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while ( data[i += inc] );
|
|
|
|
return i + ( inc > 0 ? 0 : 1 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-22 20:14:21 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Fix up data so it can safely be inserted into the document data at an offset.
|
|
|
|
*
|
|
|
|
* TODO: this function needs more work but it seems to work, mostly
|
|
|
|
*
|
|
|
|
* @method
|
2012-09-17 13:30:50 +00:00
|
|
|
* @param {Array} data Snippet of linear model data to insert
|
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 {number} offset Offset in the linear model where the caller wants to insert data
|
2012-05-22 20:14:21 +00:00
|
|
|
* @returns {Array} A (possibly modified) copy of data
|
|
|
|
*/
|
2012-08-07 01:50:44 +00:00
|
|
|
ve.dm.Document.prototype.fixupInsertion = function ( data, offset ) {
|
2012-06-04 15:37:05 +00:00
|
|
|
var
|
|
|
|
// Array where we build the return value
|
|
|
|
newData = [],
|
|
|
|
|
|
|
|
// *** Stacks ***
|
|
|
|
// Array of element openings (object). Openings in data are pushed onto this stack
|
|
|
|
// when they are encountered and popped off when they are closed
|
|
|
|
openingStack = [],
|
2012-07-05 19:55:52 +00:00
|
|
|
// Array of node objects. Closings in data that close nodes that were
|
2012-06-04 15:37:05 +00:00
|
|
|
// not opened in data (i.e. were already in the document) are pushed onto this stack
|
|
|
|
// and popped off when balanced out by an opening in data
|
|
|
|
closingStack = [],
|
|
|
|
// Array of objects describing wrappers that need to be fixed up when a given
|
|
|
|
// element is closed.
|
|
|
|
// 'expectedType': closing type that triggers this fixup. Includes initial '/'
|
|
|
|
// 'openings': array of opening elements that should be closed (in reverse order)
|
|
|
|
// 'reopenElements': array of opening elements to insert (in reverse order)
|
|
|
|
fixupStack = [],
|
|
|
|
|
|
|
|
// *** State persisting across iterations of the outer loop ***
|
|
|
|
// The node (from the document) we're currently in. When in a node that was opened
|
|
|
|
// in data, this is set to its first ancestor that is already in the document
|
|
|
|
parentNode,
|
|
|
|
// The type of the node we're currently in, even if that node was opened within data
|
|
|
|
parentType,
|
2012-06-08 19:17:40 +00:00
|
|
|
// Whether we are currently in a text node
|
|
|
|
inTextNode,
|
2012-06-04 15:37:05 +00:00
|
|
|
|
|
|
|
// *** Temporary variables that do not persist across iterations ***
|
|
|
|
// The type of the node we're currently inserting. When the to-be-inserted node
|
|
|
|
// is wrapped, this is set to the type of the outer wrapper.
|
|
|
|
childType,
|
|
|
|
// Stores the return value of getParentNodeTypes( childType )
|
|
|
|
allowedParents,
|
|
|
|
// Stores the return value of getChildNodeTypes( parentType )
|
|
|
|
allowedChildren,
|
|
|
|
// Whether parentType matches allowedParents
|
|
|
|
parentsOK,
|
|
|
|
// Whether childType matches allowedChildren
|
|
|
|
childrenOK,
|
|
|
|
// Array of opening elements to insert (for wrapping the to-be-inserted element)
|
|
|
|
openings,
|
|
|
|
// Array of closing elements to insert (for splitting nodes)
|
|
|
|
closings,
|
|
|
|
// Array of opening elements matching the elements in closings (in the same order)
|
|
|
|
reopenElements,
|
|
|
|
|
|
|
|
// *** Other variables ***
|
|
|
|
// Used to store values popped from various stacks
|
|
|
|
popped,
|
|
|
|
// Loop variables
|
|
|
|
i, j;
|
2012-05-22 20:14:21 +00:00
|
|
|
|
2012-06-04 12:56:09 +00:00
|
|
|
/**
|
2012-06-04 15:37:05 +00:00
|
|
|
* Append a linear model element to newData and update the state.
|
|
|
|
*
|
|
|
|
* This function updates parentNode, parentType, openingStack and closingStack.
|
|
|
|
*
|
2013-01-15 23:38:49 +00:00
|
|
|
* @private
|
2013-01-22 22:41:22 +00:00
|
|
|
* @method
|
2013-01-08 21:02:12 +00:00
|
|
|
* @param {Object|Array|string} element Linear model element
|
2013-01-15 23:38:49 +00:00
|
|
|
* @param {number} index Index in data that the element came from (for error reporting only)
|
2012-06-04 12:56:09 +00:00
|
|
|
*/
|
2012-05-22 20:14:21 +00:00
|
|
|
function writeElement( element, index ) {
|
2012-06-04 15:37:05 +00:00
|
|
|
var expectedType;
|
2012-07-05 19:55:52 +00:00
|
|
|
|
2012-07-19 03:40:49 +00:00
|
|
|
if ( element.type !== undefined ) {
|
2012-07-05 19:55:52 +00:00
|
|
|
// Content, do nothing
|
2012-07-19 03:40:49 +00:00
|
|
|
if ( element.type.charAt( 0 ) !== '/' ) {
|
|
|
|
// Opening
|
2012-07-05 19:55:52 +00:00
|
|
|
// Check if this opening balances an earlier closing of a node that was already in
|
|
|
|
// the document. This is only the case if openingStack is empty (otherwise we still
|
|
|
|
// have unclosed nodes from within data) and if this opening matches the top of
|
|
|
|
// closingStack
|
2012-07-19 03:40:49 +00:00
|
|
|
if ( openingStack.length === 0 && closingStack.length > 0 &&
|
2012-07-05 19:55:52 +00:00
|
|
|
closingStack[closingStack.length - 1].getType() === element.type
|
2012-07-19 03:40:49 +00:00
|
|
|
) {
|
|
|
|
// The top of closingStack is now balanced out, so remove it
|
2012-07-05 19:55:52 +00:00
|
|
|
// Also restore parentNode from closingStack. While this is technically not
|
|
|
|
// entirely accurate (the current node is a new node that's a sibling of this
|
|
|
|
// node), it's good enough for the purposes of this algorithm
|
|
|
|
parentNode = closingStack.pop();
|
2012-07-19 03:40:49 +00:00
|
|
|
} else {
|
|
|
|
// This opens something new, put it on openingStack
|
|
|
|
openingStack.push( element );
|
|
|
|
}
|
|
|
|
parentType = element.type;
|
2012-05-22 20:14:21 +00:00
|
|
|
} else {
|
2012-07-19 03:40:49 +00:00
|
|
|
// Closing
|
|
|
|
// Make sure that this closing matches the currently opened node
|
|
|
|
if ( openingStack.length > 0 ) {
|
2012-07-05 19:55:52 +00:00
|
|
|
// The opening was on openingStack, so we're closing a node that was opened
|
|
|
|
// within data. Don't track that on closingStack
|
2012-07-19 03:40:49 +00:00
|
|
|
expectedType = openingStack.pop().type;
|
|
|
|
} else {
|
2012-07-05 19:55:52 +00:00
|
|
|
// openingStack is empty, so we're closing a node that was already in the
|
|
|
|
// document. This means we have to reopen it later, so track this on
|
|
|
|
// closingStack
|
2012-07-19 03:40:49 +00:00
|
|
|
expectedType = parentNode.getType();
|
2012-07-05 19:55:52 +00:00
|
|
|
closingStack.push( parentNode );
|
2012-07-19 03:40:49 +00:00
|
|
|
parentNode = parentNode.getParent();
|
|
|
|
if ( !parentNode ) {
|
2012-08-08 17:48:53 +00:00
|
|
|
throw new Error( 'Inserted data is trying to close the root node ' +
|
2012-08-06 20:38:00 +00:00
|
|
|
'(at index ' + index + ')' );
|
2012-07-19 03:40:49 +00:00
|
|
|
}
|
2012-07-05 19:55:52 +00:00
|
|
|
parentType = expectedType;
|
2012-06-04 15:37:05 +00:00
|
|
|
|
2012-07-05 19:55:52 +00:00
|
|
|
// Validate
|
|
|
|
// FIXME this breaks certain input, should fix it up, not scream and die
|
2012-12-07 01:23:03 +00:00
|
|
|
// For now we fall back to inserting balanced data, but then we miss out on
|
|
|
|
// a lot of the nice content adoption abilities of just fixing up the data in
|
|
|
|
// the context of the insertion point - an example of how this will fail is if
|
|
|
|
// you try to insert "b</p></li></ul><p>c" into "<p>a[cursor]d</p>"
|
|
|
|
if (
|
|
|
|
element.type !== '/' + expectedType &&
|
|
|
|
(
|
|
|
|
// Only throw an error if the content can't be adopted from one content
|
|
|
|
// branch to another
|
|
|
|
!ve.dm.nodeFactory.canNodeContainContent( element.type.substr( 1 ) ) ||
|
|
|
|
!ve.dm.nodeFactory.canNodeContainContent( expectedType )
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
throw new Error( 'Cannot adopt content from ' + element.type +
|
|
|
|
' nodes into ' + expectedType + ' nodes (at index ' + index + ')' );
|
2012-07-05 19:55:52 +00:00
|
|
|
}
|
2012-07-19 03:40:49 +00:00
|
|
|
}
|
2012-05-22 20:14:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
newData.push( element );
|
|
|
|
}
|
|
|
|
|
2012-06-04 15:37:05 +00:00
|
|
|
parentNode = this.getNodeFromOffset( offset );
|
2012-05-22 20:14:21 +00:00
|
|
|
parentType = parentNode.getType();
|
2012-06-08 19:17:40 +00:00
|
|
|
inTextNode = false;
|
2012-05-22 20:14:21 +00:00
|
|
|
for ( i = 0; i < data.length; i++ ) {
|
2012-06-08 19:17:40 +00:00
|
|
|
if ( inTextNode && data[i].type !== undefined ) {
|
|
|
|
// We're leaving a text node, process fixupStack if needed
|
|
|
|
// TODO duplicated code
|
2012-07-19 03:40:49 +00:00
|
|
|
if (
|
|
|
|
fixupStack.length > 0 &&
|
|
|
|
fixupStack[fixupStack.length - 1].expectedType === '/text'
|
|
|
|
) {
|
2012-06-08 19:17:40 +00:00
|
|
|
popped = fixupStack.pop();
|
|
|
|
// Go through these in reverse!
|
|
|
|
for ( j = popped.openings.length - 1; j >= 0; j-- ) {
|
|
|
|
writeElement( { 'type': '/' + popped.openings[j].type }, i );
|
|
|
|
}
|
|
|
|
for ( j = popped.reopenElements.length - 1; j >= 0; j-- ) {
|
|
|
|
writeElement( popped.reopenElements[j], i );
|
|
|
|
}
|
|
|
|
}
|
2012-07-19 03:40:49 +00:00
|
|
|
parentType = openingStack.length > 0 ?
|
2012-12-07 01:23:03 +00:00
|
|
|
openingStack[openingStack.length - 1].type : parentNode.getType();
|
2012-06-08 19:17:40 +00:00
|
|
|
}
|
Remainder JSHint fixes on modules/ve/*
[jshint]
ce/ve.ce.Surface.js: line 670, col 9, Too many var statements.
ce/ve.ce.Surface.js: line 695, col 6, Missing semicolon.
ce/ve.ce.Surface.js: line 726, col 22, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 726, col 41, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 733, col 13, Too many var statements.
ce/ve.ce.Surface.js: line 734, col 24, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 1013, col 13, Too many var statements.
ce/ve.ce.Surface.js: line 1019, col 17, Too many var statements.
ce/ve.ce.Surface.js: line 1023, col 18, Too many ar statements.
ce/ve.ce.Surface.js: line 1027, col 13, Too many var statements.
dm/annotations/ve.dm.LinkAnnotation.js: line 70, col 52, Insecure '.'.
dm/ve.dm.Converter.js: line 383, col 29, Empty block.
dm/ve.dm.Converter.js: line 423, col 33, Empty block.
Commands:
* jshint .
* ack '(if|else|function|switch|for|while)\('
* Sublime Text 2:
Find(*): (if|else|function|switch|for|while)\(
Replace: $1 (
* ack ' ' -Q # double spaces, except in certain comments
Change-Id: I8e34bf2924bc8688fdf8acef08bbc4f6707e93be
2012-09-02 21:45:01 +00:00
|
|
|
if ( data[i].type === undefined || data[i].type.charAt( 0 ) !== '/' ) {
|
2012-06-04 12:56:09 +00:00
|
|
|
childType = data[i].type || 'text';
|
2012-05-22 20:14:21 +00:00
|
|
|
openings = [];
|
2012-06-04 12:56:09 +00:00
|
|
|
closings = [];
|
2012-06-04 15:37:05 +00:00
|
|
|
reopenElements = [];
|
2012-06-04 12:56:09 +00:00
|
|
|
// Opening or content
|
2012-07-05 19:55:52 +00:00
|
|
|
// Make sure that opening this element here does not violate the parent/children/content
|
|
|
|
// rules. If it does, insert stuff to fix it
|
2012-06-04 12:56:09 +00:00
|
|
|
|
2012-07-05 19:55:52 +00:00
|
|
|
// If this node is content, check that the containing node can contain content. If not,
|
|
|
|
// wrap in a paragraph
|
2012-06-04 12:56:09 +00:00
|
|
|
if ( ve.dm.nodeFactory.isNodeContent( childType ) &&
|
2012-06-04 15:37:05 +00:00
|
|
|
!ve.dm.nodeFactory.canNodeContainContent( parentType )
|
2012-06-04 12:56:09 +00:00
|
|
|
) {
|
|
|
|
childType = 'paragraph';
|
2012-12-07 01:23:03 +00:00
|
|
|
openings.unshift( ve.dm.nodeFactory.getDataElement( childType ) );
|
2012-06-04 12:56:09 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 19:55:52 +00:00
|
|
|
// Check that this node is allowed to have the containing node as its parent. If not,
|
|
|
|
// wrap it until it's fixed
|
2012-05-22 20:14:21 +00:00
|
|
|
do {
|
2012-05-31 22:20:58 +00:00
|
|
|
allowedParents = ve.dm.nodeFactory.getParentNodeTypes( childType );
|
2012-05-22 20:14:21 +00:00
|
|
|
parentsOK = allowedParents === null ||
|
2012-08-11 08:14:56 +00:00
|
|
|
ve.indexOf( parentType, allowedParents ) !== -1;
|
2012-05-22 20:14:21 +00:00
|
|
|
if ( !parentsOK ) {
|
|
|
|
// We can't have this as the parent
|
|
|
|
if ( allowedParents.length === 0 ) {
|
2012-08-08 17:48:53 +00:00
|
|
|
throw new Error( 'Cannot insert ' + childType + ' because it ' +
|
2012-08-06 20:38:00 +00:00
|
|
|
' cannot have a parent (at index ' + i + ')' );
|
2012-05-22 20:14:21 +00:00
|
|
|
}
|
|
|
|
// Open an allowed node around this node
|
|
|
|
childType = allowedParents[0];
|
2012-12-07 01:23:03 +00:00
|
|
|
openings.unshift( ve.dm.nodeFactory.getDataElement( childType ) );
|
2012-05-22 20:14:21 +00:00
|
|
|
}
|
|
|
|
} while ( !parentsOK );
|
2012-06-04 12:56:09 +00:00
|
|
|
|
2012-07-05 19:55:52 +00:00
|
|
|
// Check that the containing node can have this node as its child. If not, close nodes
|
|
|
|
// until it's fixed
|
2012-05-22 20:14:21 +00:00
|
|
|
do {
|
2012-05-31 22:20:58 +00:00
|
|
|
allowedChildren = ve.dm.nodeFactory.getChildNodeTypes( parentType );
|
2012-05-22 20:14:21 +00:00
|
|
|
childrenOK = allowedChildren === null ||
|
2012-08-11 08:14:56 +00:00
|
|
|
ve.indexOf( childType, allowedChildren ) !== -1;
|
2012-07-05 19:55:52 +00:00
|
|
|
// Also check if we're trying to insert structure into a node that has to contain
|
|
|
|
// content
|
2012-06-04 12:56:09 +00:00
|
|
|
childrenOK = childrenOK && !(
|
|
|
|
!ve.dm.nodeFactory.isNodeContent( childType ) &&
|
|
|
|
ve.dm.nodeFactory.canNodeContainContent( parentType )
|
|
|
|
);
|
2012-05-22 20:14:21 +00:00
|
|
|
if ( !childrenOK ) {
|
|
|
|
// We can't insert this into this parent
|
|
|
|
// Close the parent and try one level up
|
|
|
|
closings.push( { 'type': '/' + parentType } );
|
|
|
|
if ( openingStack.length > 0 ) {
|
2012-06-04 14:55:31 +00:00
|
|
|
popped = openingStack.pop();
|
|
|
|
parentType = popped.type;
|
2012-06-04 15:37:05 +00:00
|
|
|
reopenElements.push( ve.copyObject( popped ) );
|
2012-07-05 19:55:52 +00:00
|
|
|
// The opening was on openingStack, so we're closing a node that was opened
|
|
|
|
// within data. Don't track that on closingStack
|
2012-05-22 20:14:21 +00:00
|
|
|
} else {
|
2012-07-05 19:55:52 +00:00
|
|
|
// openingStack is empty, so we're closing a node that was already in the
|
|
|
|
// document. This means we have to reopen it later, so track this on
|
|
|
|
// closingStack
|
|
|
|
closingStack.push( parentNode );
|
2012-06-07 19:31:02 +00:00
|
|
|
reopenElements.push( parentNode.getClonedElement() );
|
2012-05-22 20:14:21 +00:00
|
|
|
parentNode = parentNode.getParent();
|
|
|
|
if ( !parentNode ) {
|
2012-08-08 17:48:53 +00:00
|
|
|
throw new Error( 'Cannot insert ' + childType + ' even ' +
|
2012-05-22 20:14:21 +00:00
|
|
|
' after closing all containing nodes ' +
|
2012-08-06 20:38:00 +00:00
|
|
|
'(at index ' + i + ')' );
|
2012-05-22 20:14:21 +00:00
|
|
|
}
|
|
|
|
parentType = parentNode.getType();
|
|
|
|
}
|
|
|
|
}
|
Remainder JSHint fixes on modules/ve/*
[jshint]
ce/ve.ce.Surface.js: line 670, col 9, Too many var statements.
ce/ve.ce.Surface.js: line 695, col 6, Missing semicolon.
ce/ve.ce.Surface.js: line 726, col 22, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 726, col 41, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 733, col 13, Too many var statements.
ce/ve.ce.Surface.js: line 734, col 24, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 1013, col 13, Too many var statements.
ce/ve.ce.Surface.js: line 1019, col 17, Too many var statements.
ce/ve.ce.Surface.js: line 1023, col 18, Too many ar statements.
ce/ve.ce.Surface.js: line 1027, col 13, Too many var statements.
dm/annotations/ve.dm.LinkAnnotation.js: line 70, col 52, Insecure '.'.
dm/ve.dm.Converter.js: line 383, col 29, Empty block.
dm/ve.dm.Converter.js: line 423, col 33, Empty block.
Commands:
* jshint .
* ack '(if|else|function|switch|for|while)\('
* Sublime Text 2:
Find(*): (if|else|function|switch|for|while)\(
Replace: $1 (
* ack ' ' -Q # double spaces, except in certain comments
Change-Id: I8e34bf2924bc8688fdf8acef08bbc4f6707e93be
2012-09-02 21:45:01 +00:00
|
|
|
} while ( !childrenOK );
|
2012-05-22 20:14:21 +00:00
|
|
|
|
|
|
|
for ( j = 0; j < closings.length; j++ ) {
|
2012-07-05 19:55:52 +00:00
|
|
|
// writeElement() would update openingStack/closingStack, but we've already done
|
|
|
|
// that for closings
|
2012-06-04 12:56:09 +00:00
|
|
|
newData.push( closings[j] );
|
2012-05-22 20:14:21 +00:00
|
|
|
}
|
|
|
|
for ( j = 0; j < openings.length; j++ ) {
|
|
|
|
writeElement( openings[j], i );
|
|
|
|
}
|
|
|
|
writeElement( data[i], i );
|
2012-06-04 12:56:09 +00:00
|
|
|
if ( data[i].type === undefined ) {
|
|
|
|
// Special treatment for text nodes
|
2012-06-08 19:17:40 +00:00
|
|
|
inTextNode = true;
|
2012-06-04 12:56:09 +00:00
|
|
|
if ( openings.length > 0 ) {
|
|
|
|
// We wrapped the text node, update parentType
|
|
|
|
parentType = childType;
|
2012-07-19 03:40:49 +00:00
|
|
|
fixupStack.push( {
|
|
|
|
'expectedType': '/text',
|
|
|
|
'openings': openings,
|
|
|
|
'reopenElements': reopenElements
|
|
|
|
} );
|
2012-06-04 12:56:09 +00:00
|
|
|
}
|
2012-07-05 19:55:52 +00:00
|
|
|
// If we didn't wrap the text node, then the node we're inserting into can have
|
|
|
|
// content, so we couldn't have closed anything
|
2012-06-04 12:56:09 +00:00
|
|
|
} else {
|
2012-07-19 03:40:49 +00:00
|
|
|
fixupStack.push( {
|
|
|
|
'expectedType': '/' + data[i].type,
|
|
|
|
'openings': openings,
|
|
|
|
'reopenElements': reopenElements
|
|
|
|
} );
|
2012-06-04 12:56:09 +00:00
|
|
|
parentType = data[i].type;
|
|
|
|
}
|
2012-05-22 20:14:21 +00:00
|
|
|
} else {
|
|
|
|
// Closing
|
|
|
|
writeElement( data[i], i );
|
2012-07-19 03:40:49 +00:00
|
|
|
// TODO don't close fixup stuff if the next thing immediately needs to be fixed up as
|
|
|
|
// well; instead, merge the two wrappers
|
|
|
|
if (
|
|
|
|
fixupStack.length > 0 &&
|
|
|
|
fixupStack[fixupStack.length - 1].expectedType === data[i].type
|
|
|
|
) {
|
2012-05-22 20:14:21 +00:00
|
|
|
popped = fixupStack.pop();
|
|
|
|
// Go through these in reverse!
|
|
|
|
for ( j = popped.openings.length - 1; j >= 0; j-- ) {
|
|
|
|
writeElement( { 'type': '/' + popped.openings[j].type }, i );
|
|
|
|
}
|
2012-06-04 15:37:05 +00:00
|
|
|
for ( j = popped.reopenElements.length - 1; j >= 0; j-- ) {
|
|
|
|
writeElement( popped.reopenElements[j], i );
|
2012-05-22 20:14:21 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-19 03:40:49 +00:00
|
|
|
parentType = openingStack.length > 0 ?
|
2012-12-07 01:23:03 +00:00
|
|
|
openingStack[openingStack.length - 1].type : parentNode.getType();
|
2012-05-22 20:14:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 19:17:40 +00:00
|
|
|
if ( inTextNode ) {
|
|
|
|
// We're leaving a text node, process fixupStack if needed
|
|
|
|
// TODO duplicated code
|
2012-07-19 03:40:49 +00:00
|
|
|
if (
|
|
|
|
fixupStack.length > 0 &&
|
|
|
|
fixupStack[fixupStack.length - 1].expectedType === '/text'
|
|
|
|
) {
|
2012-06-08 19:17:40 +00:00
|
|
|
popped = fixupStack.pop();
|
|
|
|
// Go through these in reverse!
|
|
|
|
for ( j = popped.openings.length - 1; j >= 0; j-- ) {
|
|
|
|
writeElement( { 'type': '/' + popped.openings[j].type }, i );
|
|
|
|
}
|
|
|
|
for ( j = popped.reopenElements.length - 1; j >= 0; j-- ) {
|
|
|
|
writeElement( popped.reopenElements[j], i );
|
|
|
|
}
|
|
|
|
}
|
2012-07-19 03:40:49 +00:00
|
|
|
parentType = openingStack.length > 0 ?
|
2012-12-07 01:23:03 +00:00
|
|
|
openingStack[openingStack.length - 1].type : parentNode.getType();
|
2012-06-08 19:17:40 +00:00
|
|
|
}
|
|
|
|
|
2012-05-22 20:14:21 +00:00
|
|
|
// Close unclosed openings
|
|
|
|
while ( openingStack.length > 0 ) {
|
|
|
|
popped = openingStack[openingStack.length - 1];
|
|
|
|
// writeElement() will perform the actual pop() that removes
|
|
|
|
// popped from openingStack
|
2012-06-04 14:55:31 +00:00
|
|
|
writeElement( { 'type': '/' + popped.type }, i );
|
2012-05-22 20:14:21 +00:00
|
|
|
}
|
|
|
|
// Re-open closed nodes
|
|
|
|
while ( closingStack.length > 0 ) {
|
|
|
|
popped = closingStack[closingStack.length - 1];
|
|
|
|
// writeElement() will perform the actual pop() that removes
|
|
|
|
// popped from closingStack
|
2012-12-07 01:23:03 +00:00
|
|
|
writeElement( popped.getClonedElement(), i );
|
2012-05-22 20:14:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return newData;
|
|
|
|
};
|
|
|
|
|
2012-06-07 20:17:46 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the document data for a range.
|
|
|
|
*
|
|
|
|
* Data will be fixed up so that unopened closings and unclosed openings in the document data slice
|
|
|
|
* are balanced.
|
2012-06-07 20:17:46 +00:00
|
|
|
*
|
2013-01-15 23:38:49 +00:00
|
|
|
* @returns {ve.dm.DocumentSlice} Balanced slice of linear model data
|
2012-06-07 20:17:46 +00:00
|
|
|
*/
|
2012-12-07 01:23:03 +00:00
|
|
|
ve.dm.Document.prototype.getSlice = function ( range ) {
|
2012-08-02 18:46:13 +00:00
|
|
|
var first, last, firstNode, lastNode,
|
|
|
|
node = this.getNodeFromOffset( range.start ),
|
2012-06-07 20:17:46 +00:00
|
|
|
selection = this.selectNodes( range, 'siblings' ),
|
|
|
|
addOpenings = [],
|
|
|
|
addClosings = [];
|
|
|
|
if ( selection.length === 0 ) {
|
2012-12-07 22:49:11 +00:00
|
|
|
return new ve.dm.DocumentSlice( [] );
|
2012-06-07 20:17:46 +00:00
|
|
|
}
|
|
|
|
if ( selection.length === 1 && selection[0].range.equals( range ) ) {
|
|
|
|
// Nothing to fix up
|
2012-12-07 22:49:11 +00:00
|
|
|
return new ve.dm.DocumentSlice( this.data.slice( range.start, range.end ) );
|
2012-06-07 20:17:46 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 18:46:13 +00:00
|
|
|
first = selection[0];
|
|
|
|
last = selection[selection.length - 1];
|
|
|
|
firstNode = first.node;
|
|
|
|
lastNode = last.node;
|
2012-06-07 20:17:46 +00:00
|
|
|
while ( !firstNode.isWrapped() ) {
|
|
|
|
firstNode = firstNode.getParent();
|
|
|
|
}
|
|
|
|
while ( !lastNode.isWrapped() ) {
|
|
|
|
lastNode = lastNode.getParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( first.range ) {
|
Remainder JSHint fixes on modules/ve/*
[jshint]
ce/ve.ce.Surface.js: line 670, col 9, Too many var statements.
ce/ve.ce.Surface.js: line 695, col 6, Missing semicolon.
ce/ve.ce.Surface.js: line 726, col 22, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 726, col 41, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 733, col 13, Too many var statements.
ce/ve.ce.Surface.js: line 734, col 24, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 1013, col 13, Too many var statements.
ce/ve.ce.Surface.js: line 1019, col 17, Too many var statements.
ce/ve.ce.Surface.js: line 1023, col 18, Too many ar statements.
ce/ve.ce.Surface.js: line 1027, col 13, Too many var statements.
dm/annotations/ve.dm.LinkAnnotation.js: line 70, col 52, Insecure '.'.
dm/ve.dm.Converter.js: line 383, col 29, Empty block.
dm/ve.dm.Converter.js: line 423, col 33, Empty block.
Commands:
* jshint .
* ack '(if|else|function|switch|for|while)\('
* Sublime Text 2:
Find(*): (if|else|function|switch|for|while)\(
Replace: $1 (
* ack ' ' -Q # double spaces, except in certain comments
Change-Id: I8e34bf2924bc8688fdf8acef08bbc4f6707e93be
2012-09-02 21:45:01 +00:00
|
|
|
while ( true ) {
|
2012-06-07 20:17:46 +00:00
|
|
|
while ( !node.isWrapped() ) {
|
|
|
|
node = node.getParent();
|
|
|
|
}
|
|
|
|
addOpenings.push( node.getClonedElement() );
|
|
|
|
if ( node === firstNode ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
node = node.getParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node = this.getNodeFromOffset( range.end );
|
|
|
|
if ( last !== first && last.range ) {
|
|
|
|
while ( true ) {
|
|
|
|
while ( !node.isWrapped() ) {
|
|
|
|
node = node.getParent();
|
|
|
|
}
|
|
|
|
addClosings.push( { 'type': '/' + node.getType() } );
|
|
|
|
if ( node === lastNode ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
node = node.getParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:23:03 +00:00
|
|
|
return new ve.dm.DocumentSlice(
|
|
|
|
addOpenings.reverse()
|
|
|
|
.concat( this.data.slice( range.start, range.end ) )
|
|
|
|
.concat( addClosings ),
|
|
|
|
new ve.Range( addOpenings.length, addOpenings.length + range.getLength() )
|
|
|
|
);
|
2012-06-07 20:17:46 +00:00
|
|
|
};
|