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 TransactionProcessor 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
|
|
|
|
*/
|
|
|
|
|
2011-11-14 23:04:36 +00:00
|
|
|
/**
|
2012-06-20 01:20:28 +00:00
|
|
|
* DataModel transaction processor.
|
|
|
|
*
|
|
|
|
* This class reads operations from a transaction and applies them one by one. It's not intended
|
|
|
|
* to be used directly; use the static functions ve.dm.TransactionProcessor.commit() and .rollback()
|
|
|
|
* instead.
|
|
|
|
*
|
|
|
|
* NOTE: Instances of this class are not recyclable: you can only call .process() on them once.
|
|
|
|
*
|
2011-11-14 23:04:36 +00:00
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
*/
|
2012-09-06 23:15:55 +00:00
|
|
|
ve.dm.TransactionProcessor = function VeDmTransactionProcessor( doc, transaction, reversed ) {
|
2012-06-20 01:20:28 +00:00
|
|
|
// Properties
|
|
|
|
this.document = doc;
|
2012-10-23 00:28:37 +00:00
|
|
|
this.transaction = transaction;
|
2012-06-20 01:20:28 +00:00
|
|
|
this.operations = transaction.getOperations();
|
|
|
|
this.synchronizer = new ve.dm.DocumentSynchronizer( doc );
|
|
|
|
this.reversed = reversed;
|
|
|
|
// Linear model offset that we're currently at. Operations in the transaction are ordered, so
|
|
|
|
// the cursor only ever moves forward.
|
2011-11-14 23:04:36 +00:00
|
|
|
this.cursor = 0;
|
2013-02-14 23:21:53 +00:00
|
|
|
this.metadataCursor = 0;
|
2012-06-20 01:20:28 +00:00
|
|
|
// Adjustment used to convert between linear model offsets in the original linear model and
|
|
|
|
// in the half-updated linear model.
|
|
|
|
this.adjustment = 0;
|
2012-08-24 02:06:36 +00:00
|
|
|
// Set and clear are sets of annotations which should be added or removed to content being
|
|
|
|
// inserted or retained.
|
|
|
|
this.set = new ve.AnnotationSet();
|
|
|
|
this.clear = new ve.AnnotationSet();
|
2011-11-14 23:04:36 +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
|
|
|
/* Static members */
|
2011-11-14 23:04:36 +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
|
|
|
/* See ve.dm.TransactionProcessor.processors */
|
2012-06-20 01:20:28 +00:00
|
|
|
ve.dm.TransactionProcessor.processors = {};
|
2011-11-14 23:04:36 +00:00
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
/* Static methods */
|
2011-11-14 23:04:36 +00:00
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
/**
|
|
|
|
* Commit a transaction to a document.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.Document} doc Document object to apply the transaction to
|
|
|
|
* @param {ve.dm.Transaction} transaction Transaction to apply
|
|
|
|
*/
|
2012-08-02 18:46:13 +00:00
|
|
|
ve.dm.TransactionProcessor.commit = function ( doc, transaction ) {
|
2012-10-23 00:28:37 +00:00
|
|
|
if ( transaction.hasBeenApplied() ) {
|
|
|
|
throw new Error( 'Cannot commit a transaction that has already been committed' );
|
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
new ve.dm.TransactionProcessor( doc, transaction, false ).process();
|
2011-11-14 23:04:36 +00:00
|
|
|
};
|
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Roll back a transaction.
|
|
|
|
*
|
|
|
|
* This applies the transaction to the document in reverse.
|
2012-06-20 01:20:28 +00:00
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.Document} doc Document object to apply the transaction to
|
|
|
|
* @param {ve.dm.Transaction} transaction Transaction to apply
|
|
|
|
*/
|
2012-08-02 18:46:13 +00:00
|
|
|
ve.dm.TransactionProcessor.rollback = function ( doc, transaction ) {
|
2012-10-23 00:28:37 +00:00
|
|
|
if ( !transaction.hasBeenApplied() ) {
|
|
|
|
throw new Error( 'Cannot roll back a transaction that has not been committed' );
|
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
new ve.dm.TransactionProcessor( doc, transaction, true ).process();
|
2011-11-14 23:04:36 +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
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the next operation.
|
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
|
|
|
|
*/
|
|
|
|
ve.dm.TransactionProcessor.prototype.nextOperation = function () {
|
|
|
|
return this.operations[this.operationIndex++] || false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Execute an operation.
|
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 {Object} op Operation object to execute
|
|
|
|
* @throws {Error} Operation type is not supported.
|
|
|
|
*/
|
|
|
|
ve.dm.TransactionProcessor.prototype.executeOperation = function ( op ) {
|
|
|
|
if ( op.type in ve.dm.TransactionProcessor.processors ) {
|
|
|
|
ve.dm.TransactionProcessor.processors[op.type].call( this, op );
|
|
|
|
} else {
|
|
|
|
throw new Error( 'Invalid operation error. Operation type is not supported: ' + op.type );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-14 23:21:53 +00:00
|
|
|
/**
|
|
|
|
* Advance the main data cursor.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {number} increment Number of positions to increment the cursor by
|
|
|
|
*/
|
|
|
|
ve.dm.TransactionProcessor.prototype.advanceCursor = function ( increment ) {
|
|
|
|
this.cursor += increment;
|
|
|
|
this.metadataCursor = 0;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
* Process all operations.
|
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
|
|
|
*
|
|
|
|
* When all operations are done being processed, the document will be synchronized.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.dm.TransactionProcessor.prototype.process = function () {
|
|
|
|
var op;
|
|
|
|
if ( this.reversed ) {
|
|
|
|
// Undo change markers before rolling back the transaction, because the offsets
|
|
|
|
// are relevant to the post-commit state
|
|
|
|
this.applyChangeMarkers();
|
|
|
|
// Unset the change markers we've just undone
|
|
|
|
this.transaction.clearChangeMarkers();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This loop is factored this way to allow operations to be skipped over or executed
|
|
|
|
// from within other operations
|
|
|
|
this.operationIndex = 0;
|
|
|
|
while ( ( op = this.nextOperation() ) ) {
|
|
|
|
this.executeOperation( op );
|
|
|
|
}
|
|
|
|
this.synchronizer.synchronize();
|
|
|
|
|
|
|
|
if ( !this.reversed ) {
|
|
|
|
// Apply the change markers we've accumulated while processing the transaction
|
|
|
|
this.applyChangeMarkers();
|
|
|
|
}
|
|
|
|
// Mark the transaction as committed or rolled back, as appropriate
|
|
|
|
this.transaction.toggleApplied();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Apply the current annotation stacks.
|
|
|
|
*
|
|
|
|
* This will set all annotations in this.set and clear all annotations in `this.clear` on the data
|
|
|
|
* between the offsets `this.cursor` and `this.cursor + to`.
|
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
|
2013-01-15 23:38:49 +00:00
|
|
|
* @param {number} to Offset to stop annotating at, annotating starts at this.cursor
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @throws {Error} Cannot annotate a branch element.
|
|
|
|
* @throws {Error} Annotation to be set is already set.
|
|
|
|
* @throws {Error} Annotation to be cleared is not set.
|
|
|
|
*/
|
|
|
|
ve.dm.TransactionProcessor.prototype.applyAnnotations = function ( to ) {
|
|
|
|
var item, element, type, annotated, annotations, i, range, selection, offset;
|
|
|
|
if ( this.set.isEmpty() && this.clear.isEmpty() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for ( i = this.cursor; i < to; i++ ) {
|
|
|
|
item = this.document.data[i];
|
|
|
|
element = item.type !== undefined;
|
|
|
|
if ( element ) {
|
|
|
|
type = item.type;
|
|
|
|
if ( item.type.charAt( 0 ) === '/' ) {
|
|
|
|
type = type.substr( 1 );
|
|
|
|
}
|
|
|
|
if ( !ve.dm.nodeFactory.isNodeContent( type ) ) {
|
|
|
|
throw new Error( 'Invalid transaction, cannot annotate a non-content element' );
|
|
|
|
}
|
|
|
|
if ( item.type.charAt( 0 ) === '/' ) {
|
|
|
|
// Closing content element, ignore
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
annotated = element ? 'annotations' in item : ve.isArray( item );
|
|
|
|
annotations = annotated ? ( element ? item.annotations : item[1] ) :
|
|
|
|
new ve.AnnotationSet();
|
|
|
|
// Set and clear annotations
|
|
|
|
if ( annotations.containsAnyOf( this.set ) ) {
|
|
|
|
throw new Error( 'Invalid transaction, annotation to be set is already set' );
|
|
|
|
} else {
|
|
|
|
annotations.addSet( this.set );
|
|
|
|
}
|
|
|
|
if ( !annotations.containsAllOf( this.clear ) ) {
|
|
|
|
throw new Error( 'Invalid transaction, annotation to be cleared is not set' );
|
|
|
|
} else {
|
|
|
|
annotations.removeSet( this.clear );
|
|
|
|
}
|
|
|
|
// Auto initialize/cleanup
|
|
|
|
if ( !annotations.isEmpty() && !annotated ) {
|
|
|
|
if ( element ) {
|
|
|
|
// Initialize new element annotation
|
|
|
|
item.annotations = new ve.AnnotationSet( annotations );
|
|
|
|
} else {
|
|
|
|
// Initialize new character annotation
|
|
|
|
this.document.data[i] = [item, new ve.AnnotationSet( annotations )];
|
|
|
|
}
|
|
|
|
} else if ( annotations.isEmpty() && annotated ) {
|
|
|
|
if ( element ) {
|
|
|
|
// Cleanup empty element annotation
|
|
|
|
delete item.annotations;
|
|
|
|
} else {
|
|
|
|
// Cleanup empty character annotation
|
|
|
|
this.document.data[i] = item[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( this.cursor < to ) {
|
|
|
|
range = new ve.Range( this.cursor, to );
|
|
|
|
selection = this.document.selectNodes(
|
|
|
|
new ve.Range(
|
|
|
|
this.cursor - this.adjustment,
|
|
|
|
to - this.adjustment
|
|
|
|
),
|
|
|
|
'leaves'
|
|
|
|
);
|
|
|
|
for ( i = 0; i < selection.length; i++ ) {
|
|
|
|
offset = !selection[i].node.isWrapped() && selection[i].parentOuterRange ?
|
|
|
|
selection[i].parentOuterRange.start :
|
|
|
|
selection[i].nodeOuterRange.start;
|
|
|
|
this.setChangeMarker( offset + this.adjustment, 'annotations' );
|
|
|
|
}
|
|
|
|
this.synchronizer.pushAnnotation( new ve.Range( this.cursor, to ) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Set a change marker on the transaction when in commit mode.
|
|
|
|
*
|
|
|
|
* This function is a no-op in rollback mode.
|
|
|
|
*
|
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.dm.Transaction#setChangeMarker
|
2013-01-15 23:38:49 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {number} offset
|
|
|
|
* @param {string} type
|
|
|
|
* @param {boolean} increment
|
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
|
|
|
*/
|
|
|
|
ve.dm.TransactionProcessor.prototype.setChangeMarker = function ( offset, type, increment ) {
|
|
|
|
// Refuse to set any new change markers while reversing transactions
|
|
|
|
if ( !this.reversed ) {
|
|
|
|
this.transaction.setChangeMarker( offset, type, increment );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Apply the change markers on this.transaction to this.document.
|
|
|
|
*
|
|
|
|
* Change markers are set (incremented) in commit mode, and unset (decremented) in rollback mode.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
*/
|
|
|
|
ve.dm.TransactionProcessor.prototype.applyChangeMarkers = function () {
|
|
|
|
var offset, type, previousValue, newValue, element,
|
|
|
|
markers = this.transaction.getChangeMarkers(),
|
|
|
|
m = this.reversed ? -1 : 1;
|
|
|
|
for ( offset in markers ) {
|
|
|
|
for ( type in markers[offset] ) {
|
|
|
|
offset = Number( offset );
|
|
|
|
element = this.document.data[offset];
|
|
|
|
previousValue = ve.getProp( element, 'internal', 'changed', type );
|
|
|
|
newValue = ( previousValue || 0 ) + m*markers[offset][type];
|
|
|
|
if ( newValue !== 0 ) {
|
|
|
|
ve.setProp( element, 'internal', 'changed', type, newValue );
|
|
|
|
} else if ( previousValue !== undefined ) {
|
|
|
|
// Value was set but becomes zero, delete the key
|
|
|
|
delete element.internal.changed[type];
|
|
|
|
// If that made .changed empty, delete it
|
|
|
|
if ( ve.isEmptyObject( element.internal.changed ) ) {
|
|
|
|
delete element.internal.changed;
|
|
|
|
}
|
|
|
|
// If that made .internal empty, delete it
|
|
|
|
if ( ve.isEmptyObject( element.internal ) ) {
|
|
|
|
delete element.internal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processing methods.
|
|
|
|
*
|
|
|
|
* Each method is specific to a type of action. Methods are called in the context of a transaction
|
|
|
|
* processor, so they work similar to normal methods on the object.
|
|
|
|
*
|
|
|
|
* @class ve.dm.TransactionProcessor.processors
|
|
|
|
* @singleton
|
|
|
|
*/
|
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
/**
|
|
|
|
* Execute a retain operation.
|
|
|
|
*
|
2013-02-14 23:21:53 +00:00
|
|
|
* This method is called within the context of a transaction processor instance.
|
2012-06-20 01:20:28 +00:00
|
|
|
*
|
|
|
|
* This moves the cursor by op.length and applies annotations to the characters that the cursor
|
|
|
|
* moved over.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} op Operation object:
|
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} op.length Number of elements to retain
|
2012-06-20 01:20:28 +00:00
|
|
|
*/
|
2012-08-02 18:46:13 +00:00
|
|
|
ve.dm.TransactionProcessor.processors.retain = function ( op ) {
|
2012-06-20 01:20:28 +00:00
|
|
|
this.applyAnnotations( this.cursor + op.length );
|
2013-02-14 23:21:53 +00:00
|
|
|
this.advanceCursor( op.length );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute a metadata retain operation.
|
|
|
|
*
|
|
|
|
* This method is called within the context of a transaction processor instance.
|
|
|
|
*
|
|
|
|
* This moves the metadata cursor by op.length.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} op Operation object:
|
|
|
|
* @param {number} op.length Number of elements to retain
|
|
|
|
*/
|
|
|
|
ve.dm.TransactionProcessor.processors.retainMetadata = function ( op ) {
|
|
|
|
this.metadataCursor += op.length;
|
2012-03-14 21:02:34 +00:00
|
|
|
};
|
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
/**
|
|
|
|
* Execute an annotate operation.
|
|
|
|
*
|
2013-02-14 23:21:53 +00:00
|
|
|
* This method is called within the context of a transaction processor instance.
|
2012-06-20 01:20:28 +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
|
|
|
* This will add an annotation to or remove an annotation from `this.set`or `this.clear`.
|
2012-06-20 01:20:28 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} op Operation object
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} op.method Annotation method, either 'set' to add or 'clear' to remove
|
|
|
|
* @param {string} op.bias End point of marker, either 'start' to begin or 'stop' to end
|
|
|
|
* @param {string} op.annotation Annotation object to set or clear from content
|
|
|
|
* @throws {Error} Invalid annotation method.
|
2012-06-20 01:20:28 +00:00
|
|
|
*/
|
2012-08-02 18:46:13 +00:00
|
|
|
ve.dm.TransactionProcessor.processors.annotate = function ( op ) {
|
2012-08-24 02:06:36 +00:00
|
|
|
var target;
|
2012-06-20 01:20:28 +00:00
|
|
|
if ( op.method === 'set' ) {
|
|
|
|
target = this.reversed ? this.clear : this.set;
|
|
|
|
} else if ( op.method === 'clear' ) {
|
|
|
|
target = this.reversed ? this.set : this.clear;
|
2012-03-14 21:02:34 +00:00
|
|
|
} else {
|
2012-08-08 17:48:53 +00:00
|
|
|
throw new Error( 'Invalid annotation method ' + op.method );
|
2012-03-14 21:02:34 +00:00
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
if ( op.bias === 'start' ) {
|
2012-08-24 02:06:36 +00:00
|
|
|
target.push( op.annotation );
|
2012-06-20 01:20:28 +00:00
|
|
|
} else {
|
2012-08-24 02:06:36 +00:00
|
|
|
target.remove( op.annotation );
|
2011-11-14 23:04:36 +00:00
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
// Tree sync is done by applyAnnotations()
|
2011-11-14 23:04:36 +00:00
|
|
|
};
|
|
|
|
|
2011-11-17 19:19:02 +00:00
|
|
|
/**
|
2012-06-20 01:20:28 +00:00
|
|
|
* Execute an attribute operation.
|
|
|
|
*
|
2013-02-14 23:21:53 +00:00
|
|
|
* This method is called within the context of a transaction processor instance.
|
2012-06-20 01:20:28 +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
|
|
|
* This sets the attribute named `op.key` on the element at `this.cursor` to `op.to`, or unsets it if
|
|
|
|
* `op.to === undefined`. `op.from `is not checked against the old value, but is used instead of `op.to`
|
|
|
|
* in reverse mode. So if `op.from` is incorrect, the transaction will commit fine, but won't roll
|
2012-06-20 01:20:28 +00:00
|
|
|
* back correctly.
|
|
|
|
*
|
2011-11-17 19:19:02 +00:00
|
|
|
* @method
|
2012-06-20 01:20:28 +00:00
|
|
|
* @param {Object} op Operation object
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} op.key Attribute name
|
|
|
|
* @param {Mixed} op.from Old attribute value, or undefined if not previously set
|
|
|
|
* @param {Mixed} op.to New attribute value, or undefined to unset
|
2011-11-17 19:19:02 +00:00
|
|
|
*/
|
2012-08-02 18:46:13 +00:00
|
|
|
ve.dm.TransactionProcessor.processors.attribute = function ( op ) {
|
|
|
|
var element = this.document.data[this.cursor],
|
|
|
|
to = this.reversed ? op.from : op.to,
|
|
|
|
from = this.reversed ? op.to : op.from;
|
2012-06-20 01:20:28 +00:00
|
|
|
if ( element.type === undefined ) {
|
2012-12-07 21:38:00 +00:00
|
|
|
throw new Error( 'Invalid element error, cannot set attributes on non-element data' );
|
2011-11-14 23:04:36 +00:00
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
if ( to === undefined ) {
|
|
|
|
// Clear
|
|
|
|
if ( element.attributes ) {
|
|
|
|
delete element.attributes[op.key];
|
2011-11-14 23:04:36 +00:00
|
|
|
}
|
2011-12-06 22:04:18 +00:00
|
|
|
} else {
|
2012-06-20 01:20:28 +00:00
|
|
|
// Automatically initialize attributes object
|
|
|
|
if ( !element.attributes ) {
|
|
|
|
element.attributes = {};
|
2011-12-07 02:13:43 +00:00
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
// Set
|
|
|
|
element.attributes[op.key] = to;
|
2011-11-14 23:04:36 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
this.synchronizer.pushAttributeChange(
|
|
|
|
this.document.getNodeFromOffset( this.cursor + 1 ),
|
|
|
|
op.key,
|
|
|
|
from, to
|
|
|
|
);
|
2012-10-23 00:53:58 +00:00
|
|
|
this.setChangeMarker( this.cursor, 'attributes' );
|
2011-11-14 23:04:36 +00:00
|
|
|
};
|
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
/**
|
|
|
|
* Execute a replace operation.
|
|
|
|
*
|
2013-02-14 23:21:53 +00:00
|
|
|
* This method is called within the context of a transaction processor instance.
|
2012-06-20 01:20:28 +00:00
|
|
|
*
|
|
|
|
* This replaces a range of linear model data with another at this.cursor, figures out how the model
|
|
|
|
* tree needs to be synchronized, and queues this in the DocumentSynchronizer.
|
|
|
|
*
|
|
|
|
* op.remove isn't checked against the actual data (instead op.remove.length things are removed
|
|
|
|
* starting at this.cursor), but it's used instead of op.insert in reverse mode. So if
|
|
|
|
* op.remove is incorrect but of the right length, the transaction will commit fine, but won't roll
|
|
|
|
* back correctly.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} op Operation object
|
|
|
|
* @param {Array} op.remove Linear model data to remove
|
|
|
|
* @param {Array} op.insert Linear model data to insert
|
|
|
|
*/
|
2012-08-02 18:46:13 +00:00
|
|
|
ve.dm.TransactionProcessor.processors.replace = function ( op ) {
|
2012-10-23 00:53:58 +00:00
|
|
|
var node, selection, range, parentOffset,
|
2012-08-02 18:46:13 +00:00
|
|
|
remove = this.reversed ? op.insert : op.remove,
|
2012-06-20 01:20:28 +00:00
|
|
|
insert = this.reversed ? op.remove : op.insert,
|
|
|
|
removeIsContent = ve.dm.Document.isContentData( remove ),
|
|
|
|
insertIsContent = ve.dm.Document.isContentData( insert ),
|
2012-08-02 18:46:13 +00:00
|
|
|
removeHasStructure = ve.dm.Document.containsElementData( remove ),
|
|
|
|
insertHasStructure = ve.dm.Document.containsElementData( insert ),
|
|
|
|
operation = op,
|
|
|
|
removeLevel = 0,
|
|
|
|
insertLevel = 0,
|
|
|
|
i,
|
|
|
|
type,
|
|
|
|
prevCursor,
|
|
|
|
affectedRanges = [],
|
|
|
|
scope,
|
|
|
|
minInsertLevel = 0,
|
|
|
|
coveringRange,
|
|
|
|
scopeStart,
|
|
|
|
scopeEnd,
|
|
|
|
opAdjustment = 0,
|
|
|
|
opRemove,
|
|
|
|
opInsert;
|
2012-06-20 01:20:28 +00:00
|
|
|
if ( removeIsContent && insertIsContent ) {
|
2012-03-12 03:55:32 +00:00
|
|
|
// Content replacement
|
|
|
|
// Update the linear model
|
2012-10-30 01:42:12 +00:00
|
|
|
this.document.spliceData( this.cursor, remove.length, insert );
|
2012-06-20 01:20:28 +00:00
|
|
|
this.applyAnnotations( this.cursor + insert.length );
|
2012-03-12 03:55:32 +00:00
|
|
|
// Get the node containing the replaced content
|
2012-06-20 01:20:28 +00:00
|
|
|
selection = this.document.selectNodes(
|
|
|
|
new ve.Range(
|
|
|
|
this.cursor - this.adjustment,
|
|
|
|
this.cursor - this.adjustment + remove.length
|
|
|
|
),
|
|
|
|
'leaves'
|
|
|
|
);
|
2012-10-23 00:41:00 +00:00
|
|
|
node = selection[0].node;
|
|
|
|
if (
|
|
|
|
!removeHasStructure && !insertHasStructure &&
|
|
|
|
selection.length === 1 &&
|
|
|
|
node && node.getType() === 'text'
|
|
|
|
) {
|
|
|
|
// Text-only replacement
|
|
|
|
// Queue a resize for the text node
|
|
|
|
this.synchronizer.pushResize( node, insert.length - remove.length );
|
|
|
|
} else {
|
2012-10-12 18:04:15 +00:00
|
|
|
// Replacement is not exclusively text
|
2012-06-20 01:20:28 +00:00
|
|
|
// Rebuild all covered nodes
|
2012-08-02 18:46:13 +00:00
|
|
|
range = new ve.Range(
|
2012-11-21 20:02:32 +00:00
|
|
|
selection[0].nodeOuterRange.start,
|
|
|
|
selection[selection.length - 1].nodeOuterRange.end
|
2012-08-02 18:46:13 +00:00
|
|
|
);
|
2012-06-20 01:20:28 +00:00
|
|
|
this.synchronizer.pushRebuild( range,
|
|
|
|
new ve.Range( range.start + this.adjustment,
|
|
|
|
range.end + this.adjustment + insert.length - remove.length )
|
|
|
|
);
|
|
|
|
}
|
2012-10-23 00:53:58 +00:00
|
|
|
// Set change markers on the parents of the affected nodes
|
|
|
|
for ( i = 0; i < selection.length; i++ ) {
|
2012-11-19 22:19:13 +00:00
|
|
|
parentOffset = ( selection[i].parentOuterRange || selection[i].nodeOuterRange ).start;
|
|
|
|
this.setChangeMarker( parentOffset + this.adjustment, 'content' );
|
2012-10-23 00:53:58 +00:00
|
|
|
}
|
2012-03-12 03:55:32 +00:00
|
|
|
// Advance the cursor
|
2013-02-14 23:21:53 +00:00
|
|
|
this.advanceCursor( insert.length );
|
2012-06-20 01:20:28 +00:00
|
|
|
this.adjustment += insert.length - remove.length;
|
2012-03-12 03:55:32 +00:00
|
|
|
} else {
|
|
|
|
// Structural replacement
|
|
|
|
// It's possible that multiple replace operations are needed before the
|
|
|
|
// model is back in a consistent state. This loop applies the current
|
|
|
|
// replace operation to the linear model, then keeps applying subsequent
|
|
|
|
// operations until the model is consistent. We keep track of the changes
|
|
|
|
// and queue a single rebuild after the loop finishes.
|
|
|
|
while ( true ) {
|
2012-07-19 03:40:49 +00:00
|
|
|
if ( operation.type === 'replace' ) {
|
2012-08-10 23:49:14 +00:00
|
|
|
opRemove = this.reversed ? operation.insert : operation.remove;
|
2012-08-02 18:46:13 +00:00
|
|
|
opInsert = this.reversed ? operation.remove : operation.insert;
|
2012-06-20 01:20:28 +00:00
|
|
|
// Update the linear model for this insert
|
2012-10-30 01:42:12 +00:00
|
|
|
this.document.spliceData( this.cursor, opRemove.length, opInsert );
|
2012-06-20 01:20:28 +00:00
|
|
|
affectedRanges.push( new ve.Range(
|
|
|
|
this.cursor - this.adjustment,
|
|
|
|
this.cursor - this.adjustment + opRemove.length
|
|
|
|
) );
|
|
|
|
prevCursor = this.cursor;
|
2013-02-14 23:21:53 +00:00
|
|
|
this.advanceCursor( opInsert.length );
|
2012-06-20 01:20:28 +00:00
|
|
|
// Paint the removed selection, figure out which nodes were
|
|
|
|
// covered, and add their ranges to the affected ranges list
|
|
|
|
if ( opRemove.length > 0 ) {
|
|
|
|
selection = this.document.selectNodes( new ve.Range(
|
|
|
|
prevCursor - this.adjustment,
|
|
|
|
prevCursor + opRemove.length - this.adjustment
|
|
|
|
), 'siblings' );
|
|
|
|
for ( i = 0; i < selection.length; i++ ) {
|
2012-10-23 00:48:22 +00:00
|
|
|
affectedRanges.push( selection[i].nodeOuterRange );
|
2012-10-23 00:53:58 +00:00
|
|
|
if (
|
|
|
|
selection[i].nodeOuterRange.start < prevCursor - this.adjustment &&
|
|
|
|
selection[i].node.canContainContent()
|
|
|
|
) {
|
|
|
|
// The opening element survives, so this
|
|
|
|
// node will have some of its content
|
|
|
|
// removed and/or have another node merged
|
|
|
|
// into it. Mark the node.
|
|
|
|
// TODO detect special case where closing is replaced
|
|
|
|
parentOffset = selection[i].nodeOuterRange.start + this.adjustment;
|
|
|
|
this.setChangeMarker( parentOffset, 'content' );
|
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Walk through the remove and insert data
|
2012-03-12 03:55:32 +00:00
|
|
|
// and keep track of the element depth change (level)
|
|
|
|
// for each of these two separately. The model is
|
|
|
|
// only consistent if both levels are zero.
|
|
|
|
for ( i = 0; i < opRemove.length; i++ ) {
|
|
|
|
type = opRemove[i].type;
|
2012-07-19 03:40:49 +00:00
|
|
|
if ( type !== undefined ) {
|
|
|
|
if ( type.charAt( 0 ) === '/' ) {
|
|
|
|
// Closing element
|
|
|
|
removeLevel--;
|
|
|
|
} else {
|
|
|
|
// Opening element
|
|
|
|
removeLevel++;
|
|
|
|
}
|
2012-03-12 03:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
// Keep track of the scope of the insertion
|
|
|
|
// Normally this is the node we're inserting into, except if the
|
|
|
|
// insertion closes elements it doesn't open (i.e. splits elements),
|
|
|
|
// in which case it's the affected ancestor
|
|
|
|
for ( i = 0; i < opInsert.length; i++ ) {
|
|
|
|
type = opInsert[i].type;
|
2012-07-19 03:40:49 +00:00
|
|
|
if ( type !== undefined ) {
|
|
|
|
if ( type.charAt( 0 ) === '/' ) {
|
|
|
|
// Closing element
|
|
|
|
insertLevel--;
|
|
|
|
if ( insertLevel < minInsertLevel ) {
|
|
|
|
// Closing an unopened element at a higher
|
|
|
|
// (more negative) level than before
|
|
|
|
// Lazy-initialize scope
|
|
|
|
scope = scope || this.document.getNodeFromOffset( prevCursor );
|
|
|
|
// Push the full range of the old scope as an affected range
|
2012-11-21 20:02:32 +00:00
|
|
|
scopeStart =
|
|
|
|
this.document.getDocumentNode().getOffsetFromNode( scope );
|
2012-07-19 03:40:49 +00:00
|
|
|
scopeEnd = scopeStart + scope.getOuterLength();
|
|
|
|
affectedRanges.push( new ve.Range( scopeStart, scopeEnd ) );
|
|
|
|
// Update scope
|
|
|
|
scope = scope.getParent() || scope;
|
2012-10-23 00:53:58 +00:00
|
|
|
// Set change marker
|
|
|
|
this.transaction.setChangeMarker(
|
|
|
|
scopeStart + this.adjustment,
|
|
|
|
'rebuilt'
|
|
|
|
);
|
2012-07-19 03:40:49 +00:00
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
|
2012-07-19 03:40:49 +00:00
|
|
|
} else {
|
|
|
|
// Opening element
|
|
|
|
insertLevel++;
|
2012-10-23 00:53:58 +00:00
|
|
|
// Mark as 'created'
|
|
|
|
this.setChangeMarker( prevCursor + i, 'created' );
|
2012-07-19 03:40:49 +00:00
|
|
|
}
|
2012-03-12 03:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
// Update adjustment
|
|
|
|
this.adjustment += opInsert.length - opRemove.length;
|
2012-06-21 06:30:25 +00:00
|
|
|
opAdjustment += opInsert.length - opRemove.length;
|
2012-03-12 03:55:32 +00:00
|
|
|
} else {
|
2012-06-20 01:20:28 +00:00
|
|
|
// We know that other operations won't cause adjustments, so we
|
|
|
|
// don't have to update adjustment
|
2012-03-12 03:55:32 +00:00
|
|
|
this.executeOperation( operation );
|
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
if ( removeLevel === 0 && insertLevel === 0 ) {
|
2012-03-12 03:55:32 +00:00
|
|
|
// The model is back in a consistent state, so we're done
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Get the next operation
|
|
|
|
operation = this.nextOperation();
|
|
|
|
if ( !operation ) {
|
2012-08-08 17:48:53 +00:00
|
|
|
throw new Error( 'Unbalanced set of replace operations found' );
|
2012-03-12 03:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
// From all the affected ranges we have gathered, compute a range that covers all
|
|
|
|
// of them, and rebuild that
|
|
|
|
coveringRange = ve.Range.newCoveringRange( affectedRanges );
|
2012-06-21 06:30:25 +00:00
|
|
|
this.synchronizer.pushRebuild(
|
|
|
|
coveringRange,
|
|
|
|
new ve.Range(
|
|
|
|
coveringRange.start + this.adjustment - opAdjustment,
|
|
|
|
coveringRange.end + this.adjustment
|
|
|
|
)
|
2012-06-20 01:20:28 +00:00
|
|
|
);
|
2012-03-12 03:55:32 +00:00
|
|
|
}
|
2012-03-08 23:21:17 +00:00
|
|
|
};
|
2013-02-14 23:21:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute a metadata replace operation.
|
|
|
|
*
|
|
|
|
* This method is called within the context of a transaction processor instance.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} op Operation object
|
|
|
|
* @param {Array} op.remove Metadata to remove
|
|
|
|
* @param {Array} op.insert Metadata to insert
|
|
|
|
*/
|
|
|
|
ve.dm.TransactionProcessor.processors.replaceMetadata = function ( op ) {
|
|
|
|
var remove = this.reversed ? op.insert : op.remove,
|
|
|
|
insert = this.reversed ? op.remove : op.insert;
|
|
|
|
|
|
|
|
this.document.spliceMetadata( this.cursor, this.metadataCursor, remove.length, insert );
|
|
|
|
};
|