|
@@ -189,7 +189,6 @@ export default class ListStyleEditing extends Plugin {
|
|
|
// Returns a converter that consumes the `style` attribute and search for `list-style-type` definition.
|
|
// Returns a converter that consumes the `style` attribute and search for `list-style-type` definition.
|
|
|
// If not found, the `"default"` value will be used.
|
|
// If not found, the `"default"` value will be used.
|
|
|
//
|
|
//
|
|
|
-// @private
|
|
|
|
|
// @returns {Function}
|
|
// @returns {Function}
|
|
|
function upcastListItemStyle() {
|
|
function upcastListItemStyle() {
|
|
|
return dispatcher => {
|
|
return dispatcher => {
|
|
@@ -206,7 +205,6 @@ function upcastListItemStyle() {
|
|
|
// Returns a converter that adds the `list-style-type` definition as a value for the `style` attribute.
|
|
// Returns a converter that adds the `list-style-type` definition as a value for the `style` attribute.
|
|
|
// The `"default"` value is removed and not present in the view/data.
|
|
// The `"default"` value is removed and not present in the view/data.
|
|
|
//
|
|
//
|
|
|
-// @private
|
|
|
|
|
// @returns {Function}
|
|
// @returns {Function}
|
|
|
function downcastListStyleAttribute() {
|
|
function downcastListStyleAttribute() {
|
|
|
return dispatcher => {
|
|
return dispatcher => {
|
|
@@ -271,7 +269,6 @@ function downcastListStyleAttribute() {
|
|
|
// ○ List item 2.[]
|
|
// ○ List item 2.[]
|
|
|
// ■ List item 3.
|
|
// ■ List item 3.
|
|
|
//
|
|
//
|
|
|
-// @private
|
|
|
|
|
// @param {module:core/editor/editor~Editor} editor
|
|
// @param {module:core/editor/editor~Editor} editor
|
|
|
// @returns {Function}
|
|
// @returns {Function}
|
|
|
function fixListAfterIndentListCommand( editor ) {
|
|
function fixListAfterIndentListCommand( editor ) {
|
|
@@ -323,7 +320,6 @@ function fixListAfterIndentListCommand( editor ) {
|
|
|
// ■ List item 2.[]
|
|
// ■ List item 2.[]
|
|
|
// ■ List item 3.
|
|
// ■ List item 3.
|
|
|
//
|
|
//
|
|
|
-// @private
|
|
|
|
|
// @param {module:core/editor/editor~Editor} editor
|
|
// @param {module:core/editor/editor~Editor} editor
|
|
|
// @returns {Function}
|
|
// @returns {Function}
|
|
|
function fixListAfterOutdentListCommand( editor ) {
|
|
function fixListAfterOutdentListCommand( editor ) {
|
|
@@ -423,22 +419,17 @@ function fixListAfterOutdentListCommand( editor ) {
|
|
|
// ■ List item 2. // ...
|
|
// ■ List item 2. // ...
|
|
|
// ■ List item 3. // ...
|
|
// ■ List item 3. // ...
|
|
|
//
|
|
//
|
|
|
-// @private
|
|
|
|
|
// @param {module:core/editor/editor~Editor} editor
|
|
// @param {module:core/editor/editor~Editor} editor
|
|
|
// @returns {Function}
|
|
// @returns {Function}
|
|
|
function fixListStyleAttributeOnListItemElements( editor ) {
|
|
function fixListStyleAttributeOnListItemElements( editor ) {
|
|
|
return writer => {
|
|
return writer => {
|
|
|
let wasFixed = false;
|
|
let wasFixed = false;
|
|
|
- let insertedListItems = [];
|
|
|
|
|
|
|
|
|
|
- for ( const change of editor.model.document.differ.getChanges() ) {
|
|
|
|
|
- if ( change.type == 'insert' && change.name == 'listItem' ) {
|
|
|
|
|
- insertedListItems.push( change.position.nodeAfter );
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Don't touch todo lists.
|
|
|
|
|
- insertedListItems = insertedListItems.filter( item => item.getAttribute( 'listType' ) !== 'todo' );
|
|
|
|
|
|
|
+ const insertedListItems = getChangedListItems( editor.model.document.differ.getChanges() )
|
|
|
|
|
+ .filter( item => {
|
|
|
|
|
+ // Don't touch todo lists. They are handled in another post-fixer.
|
|
|
|
|
+ return item.getAttribute( 'listType' ) !== 'todo';
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
if ( !insertedListItems.length ) {
|
|
if ( !insertedListItems.length ) {
|
|
|
return wasFixed;
|
|
return wasFixed;
|
|
@@ -474,7 +465,7 @@ function fixListStyleAttributeOnListItemElements( editor ) {
|
|
|
|
|
|
|
|
for ( const item of insertedListItems ) {
|
|
for ( const item of insertedListItems ) {
|
|
|
if ( !item.hasAttribute( 'listStyle' ) ) {
|
|
if ( !item.hasAttribute( 'listStyle' ) ) {
|
|
|
- if ( shouldInheritListType( existingListItem ) ) {
|
|
|
|
|
|
|
+ if ( shouldInheritListType( existingListItem, item ) ) {
|
|
|
writer.setAttribute( 'listStyle', existingListItem.getAttribute( 'listStyle' ), item );
|
|
writer.setAttribute( 'listStyle', existingListItem.getAttribute( 'listStyle' ), item );
|
|
|
} else {
|
|
} else {
|
|
|
writer.setAttribute( 'listStyle', DEFAULT_LIST_TYPE, item );
|
|
writer.setAttribute( 'listStyle', DEFAULT_LIST_TYPE, item );
|
|
@@ -493,8 +484,9 @@ function fixListStyleAttributeOnListItemElements( editor ) {
|
|
|
// the value for the element is other than default in the base element.
|
|
// the value for the element is other than default in the base element.
|
|
|
//
|
|
//
|
|
|
// @param {module:engine/model/element~Element|null} baseItem
|
|
// @param {module:engine/model/element~Element|null} baseItem
|
|
|
|
|
+ // @param {module:engine/model/element~Element} itemToChange
|
|
|
// @returns {Boolean}
|
|
// @returns {Boolean}
|
|
|
- function shouldInheritListType( baseItem ) {
|
|
|
|
|
|
|
+ function shouldInheritListType( baseItem, itemToChange ) {
|
|
|
if ( !baseItem ) {
|
|
if ( !baseItem ) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -509,28 +501,25 @@ function fixListStyleAttributeOnListItemElements( editor ) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if ( baseItem.getAttribute( 'listType' ) !== itemToChange.getAttribute( 'listType' ) ) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Removes the `listStyle` attribute from "todo" list items.
|
|
// Removes the `listStyle` attribute from "todo" list items.
|
|
|
//
|
|
//
|
|
|
-// @private
|
|
|
|
|
// @param {module:core/editor/editor~Editor} editor
|
|
// @param {module:core/editor/editor~Editor} editor
|
|
|
// @returns {Function}
|
|
// @returns {Function}
|
|
|
function removeListStyleAttributeFromTodoList( editor ) {
|
|
function removeListStyleAttributeFromTodoList( editor ) {
|
|
|
return writer => {
|
|
return writer => {
|
|
|
- let todoListItems = [];
|
|
|
|
|
-
|
|
|
|
|
- for ( const change of editor.model.document.differ.getChanges() ) {
|
|
|
|
|
- const item = getItemFromChange( change );
|
|
|
|
|
-
|
|
|
|
|
- if ( item && item.is( 'element', 'listItem' ) && item.getAttribute( 'listType' ) === 'todo' ) {
|
|
|
|
|
- todoListItems.push( item );
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- todoListItems = todoListItems.filter( item => item.hasAttribute( 'listStyle' ) );
|
|
|
|
|
|
|
+ const todoListItems = getChangedListItems( editor.model.document.differ.getChanges() )
|
|
|
|
|
+ .filter( item => {
|
|
|
|
|
+ // Handle the todo lists only. The rest is handled in another post-fixer.
|
|
|
|
|
+ return item.getAttribute( 'listType' ) === 'todo' && item.hasAttribute( 'listStyle' );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
if ( !todoListItems.length ) {
|
|
if ( !todoListItems.length ) {
|
|
|
return false;
|
|
return false;
|
|
@@ -542,23 +531,10 @@ function removeListStyleAttributeFromTodoList( editor ) {
|
|
|
|
|
|
|
|
return true;
|
|
return true;
|
|
|
};
|
|
};
|
|
|
-
|
|
|
|
|
- function getItemFromChange( change ) {
|
|
|
|
|
- if ( change.type === 'attribute' ) {
|
|
|
|
|
- return change.range.start.nodeAfter;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if ( change.type === 'insert' ) {
|
|
|
|
|
- return change.position.nodeAfter;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Restores the `listStyle` attribute after changing the list type.
|
|
// Restores the `listStyle` attribute after changing the list type.
|
|
|
//
|
|
//
|
|
|
-// @private
|
|
|
|
|
// @param {module:core/editor/editor~Editor} editor
|
|
// @param {module:core/editor/editor~Editor} editor
|
|
|
// @returns {Function}
|
|
// @returns {Function}
|
|
|
function restoreDefaultListStyle( editor ) {
|
|
function restoreDefaultListStyle( editor ) {
|
|
@@ -573,3 +549,34 @@ function restoreDefaultListStyle( editor ) {
|
|
|
} );
|
|
} );
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// Returns `listItem` that were inserted or changed.
|
|
|
|
|
+//
|
|
|
|
|
+// @param {Array.<Object>} changes The changes list returned by the differ.
|
|
|
|
|
+// @returns {Array.<module:engine/model/element~Element>}
|
|
|
|
|
+function getChangedListItems( changes ) {
|
|
|
|
|
+ const items = [];
|
|
|
|
|
+
|
|
|
|
|
+ for ( const change of changes ) {
|
|
|
|
|
+ const item = getItemFromChange( change );
|
|
|
|
|
+
|
|
|
|
|
+ if ( item && item.is( 'element', 'listItem' ) ) {
|
|
|
|
|
+ items.push( item );
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return items;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function getItemFromChange( change ) {
|
|
|
|
|
+ if ( change.type === 'attribute' ) {
|
|
|
|
|
+ return change.range.start.nodeAfter;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ( change.type === 'insert' ) {
|
|
|
|
|
+ return change.position.nodeAfter;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return null;
|
|
|
|
|
+}
|
|
|
|
|
+
|