Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
scofalik committed Nov 7, 2018
1 parent 18bab70 commit 0746195
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/conversion/downcast-converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,10 @@ export function remove() {
*/
export function insertUIElement( elementCreator ) {
return ( evt, data, conversionApi ) => {
if ( !data.markerRange ) {
return;
}

// Create two view elements. One will be inserted at the beginning of marker, one at the end.
// If marker is collapsed, only "opening" element will be inserted.
data.isOpening = true;
Expand Down Expand Up @@ -814,7 +818,7 @@ export function wrap( elementCreator ) {
*/
export function highlightText( highlightDescriptor ) {
return ( evt, data, conversionApi ) => {
if ( data.markerRange.isCollapsed ) {
if ( !data.item ) {
return;
}

Expand Down Expand Up @@ -877,7 +881,7 @@ export function highlightText( highlightDescriptor ) {
*/
export function highlightElement( highlightDescriptor ) {
return ( evt, data, conversionApi ) => {
if ( data.markerRange.isCollapsed ) {
if ( !data.item ) {
return;
}

Expand Down
21 changes: 10 additions & 11 deletions src/conversion/downcastdispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,22 +321,21 @@ export default class DowncastDispatcher {
// In markers' case, event name == consumable name.
const eventName = 'addMarker:' + markerName;

// When range is collapsed - fire single event with collapsed range in consumable.
if ( markerRange.isCollapsed ) {
const consumable = new Consumable();
consumable.add( markerRange, eventName );

this.conversionApi.consumable = consumable;
//
// First, fire an event for the whole marker.
//
const consumable = new Consumable();
consumable.add( markerRange, eventName );

this.fire( eventName, { markerName, markerRange }, this.conversionApi );
this.conversionApi.consumable = consumable;

return;
}
this.fire( eventName, { markerName, markerRange }, this.conversionApi );

// Create consumable for each item in range.
//
// Then, fire an event for each item inside the marker range.
//
this.conversionApi.consumable = this._createConsumableForRange( markerRange, eventName );

// Create separate event for each node in the range.
for ( const item of markerRange.getItems() ) {
// Do not fire event for already consumed items.
if ( !this.conversionApi.consumable.test( item, eventName ) ) {
Expand Down
4 changes: 4 additions & 0 deletions src/model/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ export default class Node {
return root;
}

get isRoot() {
return this == this.root;
}

/**
* {@link module:engine/model/document~Document Document} that owns this node or `null` if the node has no parent or is inside
* a {@link module:engine/model/documentfragment~DocumentFragment DocumentFragment}.
Expand Down

0 comments on commit 0746195

Please sign in to comment.