Commit graph

421 commits

Author SHA1 Message Date
jenkins-bot e7fb5d9cce Merge "AnnotationSet optimisations." 2013-04-22 21:20:15 +00:00
jenkins-bot 196123e7a5 Merge "MWTemplateNode should serialise original HTML if unchanged" 2013-04-22 21:15:41 +00:00
Ed Sanders 2bd6f8576a MWTemplateNode should serialise original HTML if unchanged
To help the selective serialiser we can return the original
HTML for generated content if it is unmodified.

As the output of toDomElements now depends on changes
to the dataElement we now have a 'modify' function in
the some test cases.

We also now have 'storeItems' to assert that the index-value
store is correctly populated and for loading values back
into the store for toDomElements tests.

Also make 'mw' an attribute and remove 'about' property.

Bug: 47394
Change-Id: I2bbb5d2d6a90c4eb87fa129671112c92a9b931e7
2013-04-22 20:44:21 +00:00
Catrope 3848c3f220 Factor the <pre> newline hack out of the converter into ve.properInnerHTML()
Also add detection for whether the browser is actually broken (most are,
but some, like Opera, aren't), treat <textarea> and <listing> in addition
to <pre>, and fix a bug where the function would crash if the <pre> was
empty (because .firstChild was undefined/null).

Change-Id: I541b57e9fd5c9c42d19d0a59f6e29fb43d35c9b6
2013-04-22 20:09:52 +01:00
Ed Sanders 1998496e49 AnnotationSet optimisations.
addSet:
* Instead of indexing items in the store, just union the indexStore arrays

removeSet/removeNotInSet:
* difference or intersect the indexStore arrays

filter:
* push indices into the result set instead of values

simpleArrayUnion/Intersect/Difference have been created as utilities
in ve. They are prefixed 'simple' because they use object keys to
do fast in-array comparisons. This means they are limited to string
values or values which will compare as strings (e.g. numbers).

Change-Id: I079cbdfece4f6d80ec0afd61959913f13217fcb3
2013-04-22 19:37:19 +01:00
Ed Sanders 8b09dd7650 The resurrection
By removing the transaction listeners from surface fragments we
no longer have to make sure they are always manually destroyed.

In order to retain the functionality of having fragments update
with transactions elsewhere we keep a pointer to a place in the
new complete history stack in the surface. The complete history
stack records all transactions, even undone ones.

Whenever getRange is called we replay all transactions in the
complete history (in the correct order) since the fragment was
last updated.

Also in this commit:
* Updated Format/IndentationAction to test undo(). This increases
  coverage of surface fragment behaviour.
* .range is always accessed by .getRange now, although as an
  optimisation we can use the noCopy mode when we a sure the
  returned range will not be modified.
* Added undo test to .update (previously .onTransact)

Bug: 47343
Change-Id: I9e9818da1baa8319a3002f6d74fd1aad6732a8f5
2013-04-22 12:50:23 +01:00
Catrope 83a592f312 Fix whitespace preservation around meta items
This was broken, especially in wrappers.

Changed the wrapping algorithm so that meta items are placed outside
wrappers if possible. On the left-hand side, this is already the case:
we don't open wrappers for meta items. On the right-hand side, this is
accomplished by buffering the meta items and only inserting them when
we encounter either real text (not whitespace) or the end of the wrapper.
If we're interrupted by real text, we insert the meta items with the
unmodified whitespace. If we're interrupted by the end of the wrapper,
we insert the meta items outside of the wrapper with whitespace stripped.

Internally, this is done by stripping the whitespace into the whitespace[0]
of the meta item to its right. Then when we output the meta items, we
either decide to 'restore' the whitespace, or to 'fixup' by also setting
whitespace[3] on the element before the whitespace.

Change-Id: Ibeea2a9906c4aae9fe6d284613edd6ec853ca5e7
2013-04-18 16:06:58 -07:00
Trevor Parscal bf254f44da UI "Views" refactor
Objective:

Make it possible for inspectors to inspect nodes or annotations, rather
than only annotations. Meanwhile, also make it possible for dialogs to
edit an annotation.

Strategy:

Switch from using type patterns to associate inspectors with annotations
to using arrays of classes, similar to how dialogs already work.
Introduce a view registry which provides lookups for relationships
between models and views. This is more centralized and less repetitive
than implement matching functions for both annotations and nodes in both
the dialog and inspector factories.

Changes:

*.php
* Added links to new file

ve.AnnotationAction.js
* Removed unused parameter to filter annotations using a string or regexp

ve.dm.AnnotationSet.js
* Switched from property/value arguments to callbacks

ve.ui.*(Dialog|Inspector).js
* Replaced type patterns with class lists
* Added class to view registry

ve.ui.*Tool.js, ve.ui.Context.js
* Updated model/view relationship lookup

ve.ui.*Factory.js
* Removed overly-specific lookup functions

ve.ui.Inspector.js
* Removed typePattern property
* Updated model/view relationship lookup

ve.ui.ViewRegistry.js
* New class!
* Migrated node and annotation lookup functions from factories

Change-Id: Ic2bbcf072fdd87e5ce8a03fe1ae3e6d8d50e2593
2013-04-18 15:53:50 -07:00
jenkins-bot 889e62a0ff Merge "Remove html/* attributes in getClonedElement()" 2013-04-18 22:32:24 +00:00
jenkins-bot d28c5548d5 Merge "Make the AnnotationSet constructor take an array of indexes" 2013-04-18 21:50:25 +00:00
jenkins-bot 22622c922b Merge "Death and/or destruction" 2013-04-18 20:58:19 +00:00
Trevor Parscal 2419f7638c Death and/or destruction
So. It turns out that the design of SurfaceFragment is a little -
shall we say - wonky.

One of the best things about ve.dm.SurfaceFragment is its magical
ability to retain the intention of its range, even as transactions
are being processed. This ability is granted by each fragment
listening to the surface's change event, and responding by using
translateRange for each transaction that gets processed. Surface
fragments also have these clever methods that allow you to get a
fragment based on another, which makes adjusting the range easy to do
inline without having to manually store multiple fragments or
modifying the original.

This sounded good, and we seemed to all be convinced it was well
designed. But if you add a console.log( 'hello' ); to the first line
of ve.dm.SurfaceFragment.prototype.onTransact, and then start using
the bold tool on various selections of text, you will find that there
may indeed be a flaw. What you will probably realize is that the
number of times that particular line of code is being called is
disturbingly large, and increases each time you do just about anything
in the editor. What's going on? How did we get here? Read on…

It turns out that fragments are immortal. We create them, they listen
to the surface's transact event, we are done with them, but the
surface keeps on emitting events to the now long forgotten about
fragments. They continue to build up over time, never go out of scope,
and bloat the hell out of our program.

The same ended up being true of toolbars - and each time the context
menu fired up a new one the old one was left in limbo, still
responding to events, still taking up memory, but not being visible to
the user.

All of this immortality was causing strange and difficult to track
down problems. This patch fixes this by introducing a destroy method.
This method unbinds events, allowing the object to finally fall out of
scope and die - and more importantly stop receiving notifications of
changes.

This is a hack, but Ed will no doubt get this situation sorted out
properly by making fragments lazy-evaluate their selections by only
storing an identifier of the most recent transaction they were based
on, see bug 47343.

Change-Id: I18bb986001a44732a7871b9d79dc3015eedfb168
2013-04-18 13:56:20 -07:00
jenkins-bot d54cf4c131 Merge "Transactions to store metadata merge info when present" 2013-04-18 20:04:51 +00:00
jenkins-bot 1bfc9594b3 Merge "Avoid rendering content of ve.ce.ContentBranchNode multiple times when only one transaction is applied" 2013-04-18 18:58:42 +00:00
Catrope eac44c39f4 Make the AnnotationSet constructor take an array of indexes
Before, it took an array of objects and translated those to indexes
using the store. Literally every caller outside of the test suite got
an array of indexes from the linear model, translated those to objects,
then passed them into the AnnotationSet constructor which translated
them right back to indexes.

The previous behavior was kind of ridiculous on its face, but the
reason we found it is because Inez was investigating the performance
degradation when bolding a line and found that half of it was due
to the hundreds of ve.getHash() calls caused by this behavior.

Change-Id: I38df8ae9f6392849dacf477ea2f804283c964417
2013-04-18 10:56:03 -07:00
Catrope 533e43ea80 Remove html/* attributes in getClonedElement()
Subbu said that cloning of attributes like data-parsoid or typeof would
cause problems for Parsoid.

Also remove the attributes object if it becomes empty, and do the same
for the internal object.

Bug: 47297
Change-Id: I428becf95c70d0ed8af5b0c408e3966dc47fd8c3
2013-04-18 09:27:28 -07:00
jenkins-bot 17a93e96ec Merge "Serialize alienated context-sensitive nodes correctly" 2013-04-18 11:10:37 +00:00
Catrope 42c1aa10cd Serialize alienated context-sensitive nodes correctly
Context-sensitive nodes are HTML elements like <caption> that can only
appear in certain contexts (<table> in this case). This means that
serializing them by throwing them in a <div> and calling .innerHTML
fails, because the browser knows a <caption> can't be in a <div> and
unwraps it. jQuery's .html() function is clever though and knows to wrap
<caption> in a <table> (and has similar rules for other elements).
So use jQuery's .html() rather than manual .innerHTML stuff.

Change-Id: Id7d3eff968b3a2ba345680772f7cc32e3dcdb529
2013-04-17 18:26:54 -07:00
Catrope 2f1ee49213 Fix a weird whitespace stripping bug
In HTML like <td>Foo <b>Bar</b></td>, the space would be stripped and
registered as trailing whitespace in the <td>, so it wouldn't be visible
in the editor and would be inserted after the </b> on the way out.

Thanks to Subbu for reporting this. This case was kind of ridiculous and
we're lucky the JRuby article contained it. To trigger the bug, you had
to have:
* a table cell
* containing unwrapped content
* consisting of
** some text
** whitespace
** open annotation (bold in my example, link in Subbu's case)
** text
** close annotation
** and nothing else

Change-Id: I2b83f02764b311a32a50956d4c8930a9394e91a4
2013-04-17 17:08:47 -07:00
Inez Korczyński e786c5c2f0 Avoid rendering content of ve.ce.ContentBranchNode multiple times when only one transaction is applied
Change-Id: I940bb96b670afb7ab3de524919b56912d027a2ef
2013-04-17 12:16:04 -07:00
Catrope 04516bb02e Whitespace preservation was broken after the first run
The first run of getDomFromData() would preserve whitespace just fine,
but it blanked out the .veInternal.whitespace[1] element in certain
cases, contaminating the linear model and making the whitespace data
inconsistent. Subsequent runs of getDomFromData() would then refuse to
serialize that whitespace because the information about it was
inconsistent.

In getDomFromData(), we sometimes unset .veInternal.whitespace[1] (i.e.
set it to undefined) to prevent double processing. Because we're
potentially going to modify .veInternal, don't assign it by reference,
but copy the object.

Added tests asserting that the linear model is unchanged after calling
getDomFromData(), because that function should never modify
linear model data. This test failed in 4 cases (all whitespace-related)
before I added the copyObject() call.

Bug: 43543
Change-Id: Ic4c93510518163894201a693ab50331413715967
2013-04-17 11:28:05 +00:00
Ed Sanders ff7b8a2591 Transactions to store metadata merge info when present
ve.dm.Transaction
* Replace operations are now built directly from the
  linear model and automatically determine what metadata
  replace information they need to include:
** retainMetadata
** replaceMetadata
** insertMetadata

ve.dm.Document
* Metadata array created empty and padded out after data parsing
  as we are no longer using Document.spliceData to build it (a new
  test checks for correct metadata length)
* spliceData replaced with getMetadataReplace, which instead returns
  transactional steps of spliceData (retain, replace, insert)

ve.dm.MetaLinearData
* Add function for merging metadata items together. Only used
  once in the code (Document.getMetadataReplace) but useful
  for generating test data.

ve.dm.MetaList
* Replace operations with metadata need to calculate new offset
  and indices directly, but can't be applied immediately lest they
  put a metaItem out of place and affect findItem.

ve.dm.MetaItem
* Add methods to support queued moves as required by MetaList

Test files
* Updated to match new pushReplace API
* Remove any instances of Document.spliceData
* Extra check on sparse metadata array length
* Rewrite spliceData tests as getMetadataReplace tests
* Count expected cases in Transaction(Processor) tests

Bug: 46954
Change-Id: I4edad1c2dd37c723bff2792bab7d694ef17a86dc
2013-04-16 22:26:56 +01:00
Catrope 383a669f7c Fix annotation breakage
Inez reported that unitalicizing from the toolbar was broken, because
the toolbar was somehow generating annotations that had .attributes={}
as opposed to .attributes=undefined. Turned out the cause was in the
default value for element in the ve.dm.Model constructor.

Change-Id: I64ea9ef56cd15d1131c1aa23484d7420c95a8225
2013-04-15 17:04:50 -07:00
jenkins-bot 5764026d00 Merge "TransactionProcessor: Fix offset bug" 2013-04-14 02:51:12 +00:00
Ed Sanders 6dacc54954 Hybridise MWTemplateNode
* Create MWTemplateBlockNode & MWTemplateInlineNode (in ce and dm)
* Move Alien's 'isInline' code to ve.dm.Node.static.isHybridInline
* Move definition of ce.AlienBlock/InlineNode inside ce.Aline.js file
  to match dm.AlienBlock/InlineNode and MWTemplate
* Duplicate AlienBlock/Inline styles for templates
* Create test case for inline templates
* Count test cases in ve.dm.Converter.test.js automatically

Change-Id: Id9bc7f049ea974dd5e7f8b7a66080939e0948bbd
2013-04-14 02:34:18 +00:00
jenkins-bot 1b5f4704ff Merge "Have ce's ctrl+arrow functionality use UnicodeJS library" 2013-04-13 08:06:20 +00:00
Inez Korczyński 77d9606bde TransactionProcessor: Fix offset bug
Use ve.BranchNode.getNodeFromOffset instead of
ve.dm.Document.getNodeFromOffset so correct nodes will be retrieved to
emit update events to.


Change-Id: Iaf559f0424584a3dde065e548e403c4a53207312
2013-04-12 23:16:51 +00:00
Ed Sanders 7f6beb9d39 Have ce's ctrl+arrow functionality use UnicodeJS library
Change 57076 implemented the functionality required to skip
words in UnicodeJS. This change simply removes all the existing
code we had and replaces it with this implementation.

Bug: 46794
Change-Id: I6b2700d65476c4d34ba4a01a88382d7af8e736fb
2013-04-12 12:12:53 +01:00
Ed Sanders 01eda7f36a Create MWTemplateNode
This node stores the rendered in the index-value store, hashed on
a custom hash of the dm (type + mw) which makes it unique it its
parameters.

Bug: 46571
Change-Id: I0ab4c9f7bca207121d5b42e83c821771b6139da8
2013-04-11 23:58:48 +01:00
Catrope 54a232a92b Allow nodes to handle their own children
For data->DOM, this is easy: .toDataElements() can optionally return an
array instead of an object, and that will be treated as the data to
insert. If this happens, the converter won't descend. The node handler
can recursively invoke the converter if it needs to (although I suspect
the current implementation is broken when converting block content in an
inline context).

For DOM->data, this is a bit more complex. The node sets
.static.handlesOwnChildren = true; , which triggers the converter to
pass a data slice rather than a single data element, and not to
descend. The node handler can invoke the converter to recursively
convert DOM subtrees to data.

ve.dm.Converter (data->DOM):
* Renamed createDataElement() to createDataElements()
** .toDataElement() may return element or array, handle this
* Renamed childDataElement to childDataElements, is now an array
* Actually alienate if .toDataElement() returns null
** Shockingly, this claimed to be supported before but wasn't
* Rather than pushing to data, concat to it
** Add closing if needed
* Don't descend if .toDataElement() returned an array of length >1, or
  if the node has .handlesOwnChildren = true

ve.dm.Converter (DOM->data):
* Split getDomSubtreeFromData() and getDomFromData()
* When converting a node that handles its own children, pass in a data
  slice and skip over that data

Change-Id: I196cb4c0895cbf0b428a189adb61b56565573ab3
2013-04-11 22:41:18 +00:00
jenkins-bot 6123f6e952 Merge "Fixes to DM metaList stuff under Roan's guidance." 2013-04-11 22:32:38 +00:00
Rob Moen 1c6522d9e9 Fixes to DM metaList stuff under Roan's guidance.
Splitting this out of https://gerrit.wikimedia.org/r/#/c/58274

Change-Id: Ic90b9714959e1cfb0c18997e2f2b593ed9909990
2013-04-11 14:49:17 -07:00
Catrope 1b5a376c28 Allow hybrids across Model subclasses
A node could already implement a toDataElements() function that
returns a data element of another node type, but it couldn't return
an annotation or a meta item. This is fixed now, and any dm.Model
subclass can now morph into any other dm.Model subclass.

I didn't originally plan to do this today at all, but doing this now
makes my upcoming converter changes easier. Surprise feature!

Change-Id: Ief6ac302094df084221a5a97c32a522b929c2960
2013-04-11 11:12:44 -07:00
Catrope 76b080dce1 Pass the converter object to the node handler in toDataElement()
This will allow node handlers to recursively invoke getDataFromDomRecursion()

Change-Id: I12cd4b31614a549bfbe8fbdc7d0607ece32aa98a
2013-04-11 11:12:44 -07:00
Catrope daaf255f13 Make getDataFromDomRecursion() use a context stack to pass context info
This will allow toDataElement() functions to just call this function
with a DOM element, rather than having to have all the recursion context
data to pass in.

Also expose this information using getters.

Change-Id: I89574c42385267e08704f018c0892d63014376a6
2013-04-11 11:12:39 -07:00
Trevor Parscal 9510440640 Image node refactor
ve.ce.ImageNode.js
* Moved in generic stuff from MWImageNode
* Added drag end handler (empty, will be used soon)

ve.ce.MWImageNode.js
* Changed to inherit ImageNode
* Moved generic stuff out

ve.dm.ImageNode.js
* Added attribute extraction/preservation for src, width and height

ve.dm.MWImageNode.js
* Changed to inherit ImageNode
* Re-using ImageNode's attribute handling to extract/preserve attributes on both the image and wrapper level

Change-Id: Ied4e1ece24e6804220eac35330790f7084df55de
2013-04-10 14:56:08 -07:00
Ed Sanders 62c06d0253 Create GeneratedContentNode which can store rendered HTML in IV store
AlienNode is now a subclass of GCNode, but doesn't use the IV store yet.

Bug: 46571
Change-Id: If0717afdf557a2aa681d1bae3a6e98299631091a
2013-04-10 19:34:19 +01:00
Catrope 316fdab450 Actually use the doc parameter in toDomElements()
It's been passed in for a while, but nothing ever used it. As we know
some browsers don't like it when we create elements in the wrong
document, and this ensures we always use the correct document for
createElement().

Change-Id: Ia3d2fabe0516956105ad2b5625ed2f76c015c26e
2013-04-09 23:48:03 +00:00
Catrope 27875c8220 Reduce code duplication for annotation rendering
ve.dm.Converter and ve.ce.ContentBranchNode were duplicating a fair bit
of logic for annotation rendering. Moved the annotation opening and
closing logic into ve.dm.Converter.openAndCloseAnnotations, and
implemented both annotation rendering code paths in terms of that
function with callbacks for caller-specific behavior.

Change-Id: I7cba7d2fda7002287b07949a1b8120ba80bfe854
2013-04-09 23:38:03 +00:00
jenkins-bot 05f4579a53 Merge "Convert AnnotationFactory and MetaItemFactory to NamedClassFactories" 2013-04-09 23:20:20 +00:00
jenkins-bot 9cc2d69a27 Merge "Rename ve.NodeFactory to ve.NamedClassFactory" 2013-04-09 23:03:55 +00:00
jenkins-bot 1f0cca41a1 Merge "Add ve.ce.View as a common base class for ce.Node and ce.Annotation" 2013-04-09 22:50:29 +00:00
jenkins-bot 206a2c673c Merge "Implement next/prevBreakOffset and word skipping" 2013-04-09 22:24:41 +00:00
Ed Sanders f36e68c333 Implement next/prevBreakOffset and word skipping
This provides the functionality for keyboard word skipping
(i.e. pressing ctrl/alt + arrow key).

Bug: 46794
Change-Id: Ib0861fa075df805410717a148b8a6e166d947849
2013-04-09 21:55:57 +00:00
Catrope 162f1b4119 Convert AnnotationFactory and MetaItemFactory to NamedClassFactories
Change-Id: Ic6e3a336050a335c88ef41735c0f4e470c5b75b6
2013-04-09 12:05:05 -07:00
Catrope 9c967267e6 Rename ve.NodeFactory to ve.NamedClassFactory
We weren't really using it exclusively for nodes any more, and the only
functionality in there was for using .static.name

Change-Id: Ie26928cd01faee95a10912201663b45f1f20fb19
2013-04-09 12:05:05 -07:00
Catrope 2eb77c1298 Add ve.ce.View as a common base class for ce.Node and ce.Annotation
Just like ve.dm.Model is a common base class for dm.Node, dm.Annotation
and dm.MetaItem.

ce.View abstracts the this.model and this.$ behavior, including liveness,
whitelisted HTML attribute rendering and adding a back reference in
.data(). The back reference has been renamed from .data( 'node' ) to
the more generic .data( 'view' ).

At this point this means ce.Annotation is just a shell around ce.View
(except where it defaults to a span rather than a div), but that could
change in the future.

Change-Id: I0eef5b80718e0b0fcd3f8bba096b452f0bb680d0
2013-04-09 12:05:05 -07:00
Catrope 0b55bb8cdc Move common Node/Annotation/MetaItem code into ve.dm.Model
ve.dm.Model is now the common base class for these three. ve.dm.Node
inherited from ve.Node before, so it now uses it as a mixin instead.
This required changing ve.Node's usage of ve.EventEmitter from
inhertiance to a mixin as well, because inherited methods apparently
don't get mixed in correctly.

* Change annotation terminology from linmodAnnotation to element for
  consistency with Node, MetaItem and Model
* Reimplement getClonedElement() in Node for .internal treatment

Change-Id: Ifd3922af23557c0b0f8984d36b31c8a1e2ec497e
2013-04-09 12:05:05 -07:00
jenkins-bot 237dbe7fde Merge "Fix a bug where trimOuterSpaceFromRange() didn't trim an all-whitespace range" 2013-04-09 11:58:50 +00:00
jenkins-bot 3d0ce68893 Merge "Fix ModelRegistry bugs" 2013-04-09 11:56:14 +00:00