|
|
@@ -825,6 +825,8 @@ export default class Writer {
|
|
|
* // Removes all ranges.
|
|
|
* writer.setSelection( null );
|
|
|
*
|
|
|
+ * Throws `writer-incorrect-use` error when the writer is used outside the `change()` block.
|
|
|
+ *
|
|
|
* @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection|
|
|
|
* module:engine/model/position~Position|module:engine/model/element~Element|
|
|
|
* Iterable.<module:engine/model/range~Range>|module:engine/model/range~Range|null} selectable
|
|
|
@@ -871,27 +873,9 @@ export default class Writer {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @private
|
|
|
- * @param {String} key
|
|
|
- * @param {*} value
|
|
|
- */
|
|
|
- _setSelectionAttribute( key, value ) {
|
|
|
- const selection = this.model.document.selection;
|
|
|
-
|
|
|
- // Store attribute in parent element if the selection is collapsed in an empty node.
|
|
|
- if ( selection.isCollapsed && selection.anchor.parent.isEmpty ) {
|
|
|
- const storeKey = DocumentSelection._getStoreAttributeKey( key );
|
|
|
-
|
|
|
- this.setAttribute( storeKey, value, selection.anchor.parent );
|
|
|
- }
|
|
|
-
|
|
|
- selection._setAttribute( key, value );
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* Removes an attribute with given key from the selection.
|
|
|
*
|
|
|
- * @param {String|Iterable.<String>} keyOrIterableOfKeys Key of the attribute to remove.
|
|
|
+ * @param {String|Iterable.<String>} keyOrIterableOfKeys Key of the attribute to remove or an iterable of attribute keys to remove.
|
|
|
*/
|
|
|
removeSelectionAttribute( keyOrIterableOfKeys ) {
|
|
|
this._assertWriterUsedCorrectly();
|
|
|
@@ -908,6 +892,24 @@ export default class Writer {
|
|
|
/**
|
|
|
* @private
|
|
|
* @param {String} key Key of the attribute to remove.
|
|
|
+ * @param {*} value Attribute value.
|
|
|
+ */
|
|
|
+ _setSelectionAttribute( key, value ) {
|
|
|
+ const selection = this.model.document.selection;
|
|
|
+
|
|
|
+ // Store attribute in parent element if the selection is collapsed in an empty node.
|
|
|
+ if ( selection.isCollapsed && selection.anchor.parent.isEmpty ) {
|
|
|
+ const storeKey = DocumentSelection._getStoreAttributeKey( key );
|
|
|
+
|
|
|
+ this.setAttribute( storeKey, value, selection.anchor.parent );
|
|
|
+ }
|
|
|
+
|
|
|
+ selection._setAttribute( key, value );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @private
|
|
|
+ * @param {String} key Key of the attribute to remove.
|
|
|
*/
|
|
|
_removeSelectionAttribute( key ) {
|
|
|
const selection = this.model.document.selection;
|