-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10973 from ckeditor/ck/10673-reversed-and-indexed…
…-lists Feature (list): Added support for reversed lists and list start index (`reversed` and `start` HTML attributes). Closes #10673.
- Loading branch information
Showing
11 changed files
with
6,471 additions
and
1,405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module list/listreversedcommand | ||
*/ | ||
|
||
import { Command } from 'ckeditor5/src/core'; | ||
import { getSelectedListItems } from './utils'; | ||
|
||
/** | ||
* The list reversed command. It changes `listReversed` attribute of the selected list items. | ||
* It is used by the {@link module:list/liststyle~ListStyle list style feature}. | ||
* | ||
* @extends module:core/command~Command | ||
*/ | ||
export default class ListReversedCommand extends Command { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
refresh() { | ||
const value = this._getValue(); | ||
this.value = value; | ||
this.isEnabled = value != null; | ||
} | ||
|
||
/** | ||
* Executes the command. | ||
* | ||
* @param {Object} options | ||
* @param {Boolean} [options.reversed=false] Whether the list should be reversed. | ||
* @protected | ||
*/ | ||
execute( options = {} ) { | ||
const model = this.editor.model; | ||
const listItems = getSelectedListItems( model ) | ||
.filter( item => item.getAttribute( 'listType' ) == 'numbered' ); | ||
|
||
model.change( writer => { | ||
for ( const item of listItems ) { | ||
writer.setAttribute( 'listReversed', !!options.reversed, item ); | ||
} | ||
} ); | ||
} | ||
|
||
/** | ||
* Checks the command's {@link #value}. | ||
* | ||
* @private | ||
* @returns {Boolean|null} The current value. | ||
*/ | ||
_getValue() { | ||
const listItem = this.editor.model.document.selection.getFirstPosition().parent; | ||
|
||
if ( listItem && listItem.is( 'element', 'listItem' ) && listItem.getAttribute( 'listType' ) == 'numbered' ) { | ||
return listItem.getAttribute( 'listReversed' ); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module list/liststartcommand | ||
*/ | ||
|
||
import { Command } from 'ckeditor5/src/core'; | ||
import { getSelectedListItems } from './utils'; | ||
|
||
/** | ||
* The list start index command. It changes `listStart` attribute of the selected list items. | ||
* It is used by the {@link module:list/liststyle~ListStyle list style feature}. | ||
* | ||
* @extends module:core/command~Command | ||
*/ | ||
export default class ListStartCommand extends Command { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
refresh() { | ||
const value = this._getValue(); | ||
this.value = value; | ||
this.isEnabled = value != null; | ||
} | ||
|
||
/** | ||
* Executes the command. | ||
* | ||
* @param {Object} options | ||
* @param {Number} [options.startIndex=1] Whether the list should be reversed. | ||
* @protected | ||
*/ | ||
execute( options = {} ) { | ||
const model = this.editor.model; | ||
const listItems = getSelectedListItems( model ) | ||
.filter( item => item.getAttribute( 'listType' ) == 'numbered' ); | ||
|
||
model.change( writer => { | ||
for ( const item of listItems ) { | ||
writer.setAttribute( 'listStart', options.startIndex || 1, item ); | ||
} | ||
} ); | ||
} | ||
|
||
/** | ||
* Checks the command's {@link #value}. | ||
* | ||
* @private | ||
* @returns {Boolean|null} The current value. | ||
*/ | ||
_getValue() { | ||
const listItem = this.editor.model.document.selection.getFirstPosition().parent; | ||
|
||
if ( listItem && listItem.is( 'element', 'listItem' ) && listItem.getAttribute( 'listType' ) == 'numbered' ) { | ||
return listItem.getAttribute( 'listStart' ); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.