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

Commit

Permalink
Changed: Reorganized code in wrap model-to-view converter.
Browse files Browse the repository at this point in the history
Docs: Fixed outdated docs.
  • Loading branch information
scofalik committed Jan 19, 2018
1 parent 4bfd6e3 commit a300c1f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
21 changes: 11 additions & 10 deletions src/conversion/model-to-view-converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,19 @@ export function wrap( elementCreator ) {
return;
}

let viewRange = conversionApi.mapper.toViewRange( data.range );
if ( data.item instanceof ModelSelection ) {
// Selection attribute conversion.
viewWriter.wrap( conversionApi.viewSelection.getFirstRange(), newViewElement, conversionApi.viewSelection );
} else {
// Node attribute conversion.
let viewRange = conversionApi.mapper.toViewRange( data.range );

// First, unwrap the range from current wrapper.
if ( data.attributeOldValue !== null ) {
viewRange = viewWriter.unwrap( viewRange, oldViewElement );
}
// First, unwrap the range from current wrapper.
if ( data.attributeOldValue !== null ) {
viewRange = viewWriter.unwrap( viewRange, oldViewElement );
}

// Then wrap with the new wrapper.
if ( data.attributeNewValue !== null ) {
if ( data.item instanceof ModelSelection ) {
viewWriter.wrap( conversionApi.viewSelection.getFirstRange(), newViewElement, conversionApi.viewSelection );
} else {
if ( data.attributeNewValue !== null ) {
viewWriter.wrap( viewRange, newViewElement );
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/conversion/modelconversiondispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,15 +503,18 @@ export default class ModelConversionDispatcher {
* `addMarker:foo:bar` events.
*
* If the marker range is not collapsed:
*
* * the event is fired for each item in the marker range one by one,
* * consumables object includes each item of the marker range and the consumable value is same as event name.
*
* If the marker range is collapsed:
*
* * there is only one event,
* * consumables object includes marker range with event name.
*
* If selection inside a marker is converted:
* * the is only one event,
*
* * there is only one event,
* * consumables object includes selection instance with event name.
*
* @event addMarker
Expand Down
7 changes: 3 additions & 4 deletions src/view/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ export function move( sourceRange, targetPosition ) {

/**
* Wraps elements within range with provided {@link module:engine/view/attributeelement~AttributeElement AttributeElement}.
* If a collapsed range is provided, it will be wrapped only if it is equal to view selection.
*
* If `viewSelection` was set and a collapsed range was passed, if the range is same as selection, the selection
* will be moved to the inside of the wrapped attribute element.
*
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-invalid-range-container`
* when {@link module:engine/view/range~Range#start}
Expand All @@ -465,9 +467,6 @@ export function move( sourceRange, targetPosition ) {
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
* an instance of {module:engine/view/attributeelement~AttributeElement AttributeElement}.
*
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-nonselection-collapsed-range` when passed range
* is collapsed and different than view selection.
*
* @function module:engine/view/writer~writer.wrap
* @param {module:engine/view/range~Range} range Range to wrap.
* @param {module:engine/view/attributeelement~AttributeElement} attribute Attribute element to use as wrapper.
Expand Down

0 comments on commit a300c1f

Please sign in to comment.