@ckeditor/ckeditor5-engine 31.1.0 → 34.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +2 -2
- package/README.md +2 -1
- package/package.json +25 -25
- package/src/controller/datacontroller.js +65 -74
- package/src/controller/editingcontroller.js +83 -6
- package/src/conversion/conversion.js +15 -14
- package/src/conversion/conversionhelpers.js +1 -1
- package/src/conversion/downcastdispatcher.js +298 -367
- package/src/conversion/downcasthelpers.js +860 -81
- package/src/conversion/mapper.js +105 -60
- package/src/conversion/modelconsumable.js +85 -35
- package/src/conversion/upcastdispatcher.js +34 -7
- package/src/conversion/upcasthelpers.js +4 -2
- package/src/conversion/viewconsumable.js +1 -1
- package/src/dataprocessor/basichtmlwriter.js +1 -1
- package/src/dataprocessor/dataprocessor.jsdoc +1 -1
- package/src/dataprocessor/htmldataprocessor.js +9 -31
- package/src/dataprocessor/htmlwriter.js +1 -1
- package/src/dataprocessor/xmldataprocessor.js +1 -1
- package/src/dev-utils/model.js +16 -14
- package/src/dev-utils/operationreplayer.js +1 -1
- package/src/dev-utils/utils.js +1 -1
- package/src/dev-utils/view.js +1 -1
- package/src/index.js +8 -1
- package/src/model/batch.js +77 -10
- package/src/model/differ.js +115 -69
- package/src/model/document.js +13 -4
- package/src/model/documentfragment.js +1 -1
- package/src/model/documentselection.js +1 -1
- package/src/model/element.js +1 -1
- package/src/model/history.js +1 -1
- package/src/model/item.jsdoc +1 -1
- package/src/model/liveposition.js +1 -1
- package/src/model/liverange.js +1 -1
- package/src/model/markercollection.js +29 -5
- package/src/model/model.js +138 -12
- package/src/model/node.js +1 -1
- package/src/model/nodelist.js +1 -1
- package/src/model/operation/attributeoperation.js +1 -1
- package/src/model/operation/detachoperation.js +1 -1
- package/src/model/operation/insertoperation.js +1 -1
- package/src/model/operation/markeroperation.js +1 -1
- package/src/model/operation/mergeoperation.js +1 -1
- package/src/model/operation/moveoperation.js +1 -1
- package/src/model/operation/nooperation.js +1 -1
- package/src/model/operation/operation.js +1 -1
- package/src/model/operation/operationfactory.js +1 -1
- package/src/model/operation/renameoperation.js +1 -1
- package/src/model/operation/rootattributeoperation.js +1 -1
- package/src/model/operation/splitoperation.js +1 -1
- package/src/model/operation/transform.js +1 -1
- package/src/model/operation/utils.js +1 -1
- package/src/model/position.js +1 -1
- package/src/model/range.js +1 -1
- package/src/model/rootelement.js +1 -1
- package/src/model/schema.js +80 -11
- package/src/model/selection.js +1 -1
- package/src/model/text.js +1 -1
- package/src/model/textproxy.js +1 -1
- package/src/model/treewalker.js +3 -4
- package/src/model/utils/autoparagraphing.js +1 -1
- package/src/model/utils/deletecontent.js +16 -3
- package/src/model/utils/findoptimalinsertionrange.js +68 -0
- package/src/model/utils/getselectedcontent.js +1 -1
- package/src/model/utils/insertcontent.js +1 -1
- package/src/model/utils/insertobject.js +173 -0
- package/src/model/utils/modifyselection.js +15 -8
- package/src/model/utils/selection-post-fixer.js +1 -1
- package/src/model/writer.js +17 -27
- package/src/view/attributeelement.js +1 -11
- package/src/view/containerelement.js +1 -1
- package/src/view/document.js +3 -2
- package/src/view/documentfragment.js +1 -1
- package/src/view/documentselection.js +1 -1
- package/src/view/domconverter.js +55 -28
- package/src/view/downcastwriter.js +91 -50
- package/src/view/editableelement.js +1 -1
- package/src/view/element.js +1 -28
- package/src/view/elementdefinition.jsdoc +1 -1
- package/src/view/emptyelement.js +1 -4
- package/src/view/filler.js +1 -1
- package/src/view/item.jsdoc +1 -1
- package/src/view/matcher.js +3 -3
- package/src/view/node.js +1 -1
- package/src/view/observer/arrowkeysobserver.js +1 -1
- package/src/view/observer/bubblingemittermixin.js +1 -1
- package/src/view/observer/bubblingeventinfo.js +1 -1
- package/src/view/observer/clickobserver.js +1 -2
- package/src/view/observer/compositionobserver.js +1 -1
- package/src/view/observer/domeventdata.js +1 -1
- package/src/view/observer/domeventobserver.js +1 -1
- package/src/view/observer/fakeselectionobserver.js +1 -1
- package/src/view/observer/focusobserver.js +1 -1
- package/src/view/observer/inputobserver.js +2 -2
- package/src/view/observer/keyobserver.js +1 -1
- package/src/view/observer/mouseobserver.js +1 -1
- package/src/view/observer/mutationobserver.js +1 -1
- package/src/view/observer/observer.js +1 -1
- package/src/view/observer/selectionobserver.js +1 -1
- package/src/view/observer/tabobserver.js +68 -0
- package/src/view/placeholder.js +2 -2
- package/src/view/position.js +1 -1
- package/src/view/range.js +1 -1
- package/src/view/rawelement.js +1 -4
- package/src/view/renderer.js +3 -2
- package/src/view/rooteditableelement.js +1 -1
- package/src/view/selection.js +1 -1
- package/src/view/styles/background.js +1 -1
- package/src/view/styles/border.js +1 -1
- package/src/view/styles/margin.js +1 -1
- package/src/view/styles/padding.js +1 -1
- package/src/view/styles/utils.js +1 -1
- package/src/view/stylesmap.js +1 -1
- package/src/view/text.js +1 -1
- package/src/view/textproxy.js +1 -1
- package/src/view/treewalker.js +1 -1
- package/src/view/uielement.js +1 -4
- package/src/view/upcastwriter.js +1 -1
- package/src/view/view.js +5 -1
- package/theme/placeholder.css +10 -1
- package/theme/renderer.css +1 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module engine/model/utils/findoptimalinsertionrange
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import first from '@ckeditor/ckeditor5-utils/src/first';
|
|
11
|
+
|
|
12
|
+
// Returns a model range which is optimal (in terms of UX) for inserting a widget block.
|
|
13
|
+
//
|
|
14
|
+
// For instance, if a selection is in the middle of a paragraph, the collapsed range before this paragraph
|
|
15
|
+
// will be returned so that it is not split. If the selection is at the end of a paragraph,
|
|
16
|
+
// the collapsed range after this paragraph will be returned.
|
|
17
|
+
//
|
|
18
|
+
// Note: If the selection is placed in an empty block, the range in that block will be returned. If that range
|
|
19
|
+
// is then passed to {@link module:engine/model/model~Model#insertContent}, the block will be fully replaced
|
|
20
|
+
// by the inserted widget block.
|
|
21
|
+
//
|
|
22
|
+
// **Note:** Use {@link module:widget/utils#findOptimalInsertionRange} instead of this function outside engine.
|
|
23
|
+
// This function is only exposed to be used by {@link module:widget/utils#findOptimalInsertionRange findOptimalInsertionRange()}
|
|
24
|
+
// in `widget` package and inside `engine` package.
|
|
25
|
+
//
|
|
26
|
+
// @private
|
|
27
|
+
// @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection
|
|
28
|
+
// The selection based on which the insertion position should be calculated.
|
|
29
|
+
// @param {module:engine/model/model~Model} model Model instance.
|
|
30
|
+
// @param {'auto'|'before'|'after'} [place='auto'] Place where to look for optimal insertion range.
|
|
31
|
+
// Default value `auto` will determine itself the best position for insertion.
|
|
32
|
+
// Value `before` will try to find a position before selection.
|
|
33
|
+
// Value `after` will try to find a position after selection.
|
|
34
|
+
// @returns {module:engine/model/range~Range} The optimal range.
|
|
35
|
+
export function findOptimalInsertionRange( selection, model, place = 'auto' ) {
|
|
36
|
+
const selectedElement = selection.getSelectedElement();
|
|
37
|
+
|
|
38
|
+
if ( selectedElement && model.schema.isObject( selectedElement ) && !model.schema.isInline( selectedElement ) ) {
|
|
39
|
+
if ( [ 'before', 'after' ].includes( place ) ) {
|
|
40
|
+
return model.createRange( model.createPositionAt( selectedElement, place ) );
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return model.createRangeOn( selectedElement );
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const firstBlock = first( selection.getSelectedBlocks() );
|
|
47
|
+
|
|
48
|
+
// There are no block elements within ancestors (in the current limit element).
|
|
49
|
+
if ( !firstBlock ) {
|
|
50
|
+
return model.createRange( selection.focus );
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// If inserting into an empty block – return position in that block. It will get
|
|
54
|
+
// replaced with the image by insertContent(). #42.
|
|
55
|
+
if ( firstBlock.isEmpty ) {
|
|
56
|
+
return model.createRange( model.createPositionAt( firstBlock, 0 ) );
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const positionAfter = model.createPositionAfter( firstBlock );
|
|
60
|
+
|
|
61
|
+
// If selection is at the end of the block - return position after the block.
|
|
62
|
+
if ( selection.focus.isTouching( positionAfter ) ) {
|
|
63
|
+
return model.createRange( positionAfter );
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Otherwise, return position before the block.
|
|
67
|
+
return model.createRange( model.createPositionBefore( firstBlock ) );
|
|
68
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module engine/model/utils/insertobject
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import first from '@ckeditor/ckeditor5-utils/src/first';
|
|
11
|
+
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
12
|
+
|
|
13
|
+
import { findOptimalInsertionRange } from './findoptimalinsertionrange';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Inserts an {@glink framework/guides/deep-dive/schema#object-elements object element} at a specific position in the editor content.
|
|
17
|
+
*
|
|
18
|
+
* **Note:** Use {@link module:engine/model/model~Model#insertObject} instead of this function.
|
|
19
|
+
* This function is only exposed to be reusable in algorithms which change the {@link module:engine/model/model~Model#insertObject}
|
|
20
|
+
* method's behavior.
|
|
21
|
+
*
|
|
22
|
+
* **Note**: For more documentation and examples, see {@link module:engine/model/model~Model#insertObject}.
|
|
23
|
+
*
|
|
24
|
+
* @param {module:engine/model/model~Model} model The model in context of which the insertion
|
|
25
|
+
* should be performed.
|
|
26
|
+
* @param {module:engine/model/element~Element} object An object to be inserted into the model document.
|
|
27
|
+
* @param {module:engine/model/selection~Selectable} [selectable=model.document.selection]
|
|
28
|
+
* A selectable where the content should be inserted. If not specified, the current
|
|
29
|
+
* {@link module:engine/model/document~Document#selection document selection} will be used instead.
|
|
30
|
+
* @param {Number|'before'|'end'|'after'|'on'|'in'} placeOrOffset Specifies the exact place or offset for the insertion to take place,
|
|
31
|
+
* relative to `selectable`.
|
|
32
|
+
* @param {Object} [options] Additional options.
|
|
33
|
+
* @param {'auto'|'before'|'after'} [options.findOptimalPosition] An option that, when set, adjusts the insertion position (relative to
|
|
34
|
+
* `selectable` and `placeOrOffset`) so that the content of `selectable` is not split upon insertion (a.k.a. non-destructive insertion).
|
|
35
|
+
* * When `'auto'`, the algorithm will decide whether to insert the object before or after `selectable` to avoid content splitting.
|
|
36
|
+
* * When `'before'`, the closest position before `selectable` will be used that will not result in content splitting.
|
|
37
|
+
* * When `'after'`, the closest position after `selectable` will be used that will not result in content splitting.
|
|
38
|
+
*
|
|
39
|
+
* Note that this option works only for block objects. Inline objects are inserted into text and do not split blocks.
|
|
40
|
+
* @param {'on'|'after'} [options.setSelection] An option that, when set, moves the
|
|
41
|
+
* {@link module:engine/model/document~Document#selection document selection} after inserting the object.
|
|
42
|
+
* * When `'on'`, the document selection will be set on the inserted object.
|
|
43
|
+
* * When `'after'`, the document selection will move to the closest text node after the inserted object. If there is no
|
|
44
|
+
* such text node, a paragraph will be created and the document selection will be moved inside it.
|
|
45
|
+
* @returns {module:engine/model/range~Range} A range which contains all the performed changes. This is a range that, if removed,
|
|
46
|
+
* would return the model to the state before the insertion. If no changes were preformed by `insertObject()`, returns a range collapsed
|
|
47
|
+
* at the insertion position.
|
|
48
|
+
*/
|
|
49
|
+
export default function insertObject( model, object, selectable, placeOrOffset, options = {} ) {
|
|
50
|
+
if ( !model.schema.isObject( object ) ) {
|
|
51
|
+
/**
|
|
52
|
+
* Tried to insert an element with {@link module:engine/model/utils/insertobject insertObject()} function
|
|
53
|
+
* that is not defined as an object in schema.
|
|
54
|
+
* See {@link module:engine/model/schema~SchemaItemDefinition#isObject `SchemaItemDefinition`}.
|
|
55
|
+
* If you want to insert content that is not an object you might want to use
|
|
56
|
+
* {@link module:engine/model/utils/insertcontent insertContent()} function.
|
|
57
|
+
* @error insertobject-element-not-an-object
|
|
58
|
+
*/
|
|
59
|
+
throw new CKEditorError( 'insertobject-element-not-an-object', model, { object } );
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Normalize selectable to a selection instance.
|
|
63
|
+
let originalSelection;
|
|
64
|
+
|
|
65
|
+
if ( !selectable ) {
|
|
66
|
+
originalSelection = model.document.selection;
|
|
67
|
+
} else if ( selectable.is( 'selection' ) ) {
|
|
68
|
+
originalSelection = selectable;
|
|
69
|
+
} else {
|
|
70
|
+
originalSelection = model.createSelection( selectable, placeOrOffset );
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Adjust the insertion selection.
|
|
74
|
+
let insertionSelection = originalSelection;
|
|
75
|
+
|
|
76
|
+
if ( options.findOptimalPosition && model.schema.isBlock( object ) ) {
|
|
77
|
+
insertionSelection = model.createSelection( findOptimalInsertionRange( originalSelection, model, options.findOptimalPosition ) );
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Collect attributes to be copied on the inserted object.
|
|
81
|
+
const firstSelectedBlock = first( originalSelection.getSelectedBlocks() );
|
|
82
|
+
const attributesToCopy = {};
|
|
83
|
+
|
|
84
|
+
if ( firstSelectedBlock ) {
|
|
85
|
+
Object.assign( attributesToCopy, model.schema.getAttributesWithProperty( firstSelectedBlock, 'copyOnReplace', true ) );
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return model.change( writer => {
|
|
89
|
+
// Remove the selected content to find out what the parent of the inserted object would be.
|
|
90
|
+
// It would be removed inside model.insertContent() anyway.
|
|
91
|
+
if ( !insertionSelection.isCollapsed ) {
|
|
92
|
+
model.deleteContent( insertionSelection, { doNotAutoparagraph: true } );
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let elementToInsert = object;
|
|
96
|
+
const insertionPositionParent = insertionSelection.anchor.parent;
|
|
97
|
+
|
|
98
|
+
// Autoparagraphing of an inline objects.
|
|
99
|
+
if (
|
|
100
|
+
!model.schema.checkChild( insertionPositionParent, object ) &&
|
|
101
|
+
model.schema.checkChild( insertionPositionParent, 'paragraph' ) &&
|
|
102
|
+
model.schema.checkChild( 'paragraph', object )
|
|
103
|
+
) {
|
|
104
|
+
elementToInsert = writer.createElement( 'paragraph' );
|
|
105
|
+
|
|
106
|
+
writer.insert( object, elementToInsert );
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Apply attributes that are allowed on the inserted object (or paragraph if autoparagraphed).
|
|
110
|
+
model.schema.setAllowedAttributes( elementToInsert, attributesToCopy, writer );
|
|
111
|
+
|
|
112
|
+
// Insert the prepared content at the optionally adjusted selection.
|
|
113
|
+
const affectedRange = model.insertContent( elementToInsert, insertionSelection );
|
|
114
|
+
|
|
115
|
+
// Nothing got inserted.
|
|
116
|
+
if ( affectedRange.isCollapsed ) {
|
|
117
|
+
return affectedRange;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if ( options.setSelection ) {
|
|
121
|
+
updateSelection( writer, object, options.setSelection, attributesToCopy );
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return affectedRange;
|
|
125
|
+
} );
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Updates document selection based on given `place` parameter in relation to `contextElement` element.
|
|
129
|
+
//
|
|
130
|
+
// @private
|
|
131
|
+
// @param {module:engine/model/writer~Writer} writer An instance of the model writer.
|
|
132
|
+
// @param {module:engine/model/element~Element} contextElement An element to set attributes on.
|
|
133
|
+
// @param {'on'|'after'} place Place where selection should be set in relation to `contextElement` element.
|
|
134
|
+
// Value `on` will set selection on passed `contextElement`. Value `after` will set selection after `contextElement`.
|
|
135
|
+
// @param {Object} attributes Attributes keys and values to set on a paragraph that this function can create when
|
|
136
|
+
// `place` parameter is equal to `after` but there is no element with `$text` node to set selection in.
|
|
137
|
+
function updateSelection( writer, contextElement, place, paragraphAttributes ) {
|
|
138
|
+
const model = writer.model;
|
|
139
|
+
|
|
140
|
+
if ( place == 'after' ) {
|
|
141
|
+
let nextElement = contextElement.nextSibling;
|
|
142
|
+
|
|
143
|
+
// Check whether an element next to the inserted element is defined and can contain a text.
|
|
144
|
+
const canSetSelection = nextElement && model.schema.checkChild( nextElement, '$text' );
|
|
145
|
+
|
|
146
|
+
// If the element is missing, but a paragraph could be inserted next to the element, let's add it.
|
|
147
|
+
if ( !canSetSelection && model.schema.checkChild( contextElement.parent, 'paragraph' ) ) {
|
|
148
|
+
nextElement = writer.createElement( 'paragraph' );
|
|
149
|
+
|
|
150
|
+
model.schema.setAllowedAttributes( nextElement, paragraphAttributes, writer );
|
|
151
|
+
model.insertContent( nextElement, writer.createPositionAfter( contextElement ) );
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Put the selection inside the element, at the beginning.
|
|
155
|
+
if ( nextElement ) {
|
|
156
|
+
writer.setSelection( nextElement, 0 );
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if ( place == 'on' ) {
|
|
160
|
+
writer.setSelection( contextElement, 'on' );
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
/**
|
|
164
|
+
* Unsupported `options.setSelection` parameter was passed
|
|
165
|
+
* to the {@link module:engine/model/utils/insertobject insertObject()} function.
|
|
166
|
+
* Check {@link module:engine/model/utils/insertobject insertObject()} API documentation for allowed
|
|
167
|
+
* `options.setSelection` parameter values.
|
|
168
|
+
*
|
|
169
|
+
* @error insertobject-invalid-place-parameter-value
|
|
170
|
+
*/
|
|
171
|
+
throw new CKEditorError( 'insertobject-invalid-place-parameter-value', model );
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import Position from '../position';
|
|
11
11
|
import TreeWalker from '../treewalker';
|
|
12
12
|
import Range from '../range';
|
|
13
|
-
import { isInsideSurrogatePair, isInsideCombinedSymbol } from '@ckeditor/ckeditor5-utils/src/unicode';
|
|
13
|
+
import { isInsideSurrogatePair, isInsideCombinedSymbol, isInsideEmojiSequence } from '@ckeditor/ckeditor5-utils/src/unicode';
|
|
14
14
|
import DocumentSelection from '../documentselection';
|
|
15
15
|
|
|
16
16
|
const wordBoundaryCharacters = ' ,.?!:;"-()';
|
|
@@ -49,11 +49,13 @@ const wordBoundaryCharacters = ' ,.?!:;"-()';
|
|
|
49
49
|
* @param {Object} [options]
|
|
50
50
|
* @param {'forward'|'backward'} [options.direction='forward'] The direction in which the selection should be modified.
|
|
51
51
|
* @param {'character'|'codePoint'|'word'} [options.unit='character'] The unit by which selection should be modified.
|
|
52
|
+
* @param {Boolean} [options.treatEmojiAsSingleUnit=false] Whether multi-characer emoji sequences should be handled as single unit.
|
|
52
53
|
*/
|
|
53
54
|
export default function modifySelection( model, selection, options = {} ) {
|
|
54
55
|
const schema = model.schema;
|
|
55
56
|
const isForward = options.direction != 'backward';
|
|
56
57
|
const unit = options.unit ? options.unit : 'character';
|
|
58
|
+
const treatEmojiAsSingleUnit = !!options.treatEmojiAsSingleUnit;
|
|
57
59
|
|
|
58
60
|
const focus = selection.focus;
|
|
59
61
|
|
|
@@ -63,7 +65,7 @@ export default function modifySelection( model, selection, options = {} ) {
|
|
|
63
65
|
direction: isForward ? 'forward' : 'backward'
|
|
64
66
|
} );
|
|
65
67
|
|
|
66
|
-
const data = { walker, schema, isForward, unit };
|
|
68
|
+
const data = { walker, schema, isForward, unit, treatEmojiAsSingleUnit };
|
|
67
69
|
|
|
68
70
|
let next;
|
|
69
71
|
|
|
@@ -89,10 +91,10 @@ export default function modifySelection( model, selection, options = {} ) {
|
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
// Checks whether the selection can be extended to the the walker's next value (next position).
|
|
92
|
-
// @param {{ walker, unit, isForward, schema }} data
|
|
94
|
+
// @param {{ walker, unit, isForward, schema, treatEmojiAsSingleUnit }} data
|
|
93
95
|
// @param {module:engine/view/treewalker~TreeWalkerValue} value
|
|
94
96
|
function tryExtendingTo( data, value ) {
|
|
95
|
-
const { isForward, walker, unit, schema } = data;
|
|
97
|
+
const { isForward, walker, unit, schema, treatEmojiAsSingleUnit } = data;
|
|
96
98
|
const { type, item, nextPosition } = value;
|
|
97
99
|
|
|
98
100
|
// If found text, we can certainly put the focus in it. Let's just find a correct position
|
|
@@ -102,7 +104,7 @@ function tryExtendingTo( data, value ) {
|
|
|
102
104
|
return getCorrectWordBreakPosition( walker, isForward );
|
|
103
105
|
}
|
|
104
106
|
|
|
105
|
-
return getCorrectPosition( walker, unit,
|
|
107
|
+
return getCorrectPosition( walker, unit, treatEmojiAsSingleUnit );
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
// Entering an element.
|
|
@@ -139,14 +141,19 @@ function tryExtendingTo( data, value ) {
|
|
|
139
141
|
//
|
|
140
142
|
// @param {module:engine/model/treewalker~TreeWalker} walker
|
|
141
143
|
// @param {String} unit The unit by which selection should be modified.
|
|
142
|
-
|
|
144
|
+
// @param {Boolean} treatEmojiAsSingleUnit
|
|
145
|
+
function getCorrectPosition( walker, unit, treatEmojiAsSingleUnit ) {
|
|
143
146
|
const textNode = walker.position.textNode;
|
|
144
147
|
|
|
145
148
|
if ( textNode ) {
|
|
146
149
|
const data = textNode.data;
|
|
147
150
|
let offset = walker.position.offset - textNode.startOffset;
|
|
148
151
|
|
|
149
|
-
while (
|
|
152
|
+
while (
|
|
153
|
+
isInsideSurrogatePair( data, offset ) ||
|
|
154
|
+
( unit == 'character' && isInsideCombinedSymbol( data, offset ) ) ||
|
|
155
|
+
( treatEmojiAsSingleUnit && isInsideEmojiSequence( data, offset ) )
|
|
156
|
+
) {
|
|
150
157
|
walker.next();
|
|
151
158
|
|
|
152
159
|
offset = walker.position.offset - textNode.startOffset;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
package/src/model/writer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -27,7 +27,7 @@ import DocumentSelection from './documentselection';
|
|
|
27
27
|
|
|
28
28
|
import toMap from '@ckeditor/ckeditor5-utils/src/tomap';
|
|
29
29
|
|
|
30
|
-
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
30
|
+
import CKEditorError, { logWarning } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* The model can only be modified by using the writer. It should be used whenever you want to create a node, modify
|
|
@@ -968,30 +968,8 @@ export default class Writer {
|
|
|
968
968
|
* As the first parameter you can set marker name or instance. If none of them is provided, new marker, with a unique
|
|
969
969
|
* name is created and returned.
|
|
970
970
|
*
|
|
971
|
-
*
|
|
972
|
-
* the
|
|
973
|
-
* the marker {@link module:engine/view/element~Element view element} without changing any marker data.
|
|
974
|
-
*
|
|
975
|
-
* let isCommentActive = false;
|
|
976
|
-
*
|
|
977
|
-
* model.conversion.markerToHighlight( {
|
|
978
|
-
* model: 'comment',
|
|
979
|
-
* view: data => {
|
|
980
|
-
* const classes = [ 'comment-marker' ];
|
|
981
|
-
*
|
|
982
|
-
* if ( isCommentActive ) {
|
|
983
|
-
* classes.push( 'comment-marker--active' );
|
|
984
|
-
* }
|
|
985
|
-
*
|
|
986
|
-
* return { classes };
|
|
987
|
-
* }
|
|
988
|
-
* } );
|
|
989
|
-
*
|
|
990
|
-
* // Change the property that indicates if marker is displayed as active or not.
|
|
991
|
-
* isCommentActive = true;
|
|
992
|
-
*
|
|
993
|
-
* // And refresh the marker to convert it with additional class.
|
|
994
|
-
* model.change( writer => writer.updateMarker( 'comment' ) );
|
|
971
|
+
* **Note**: If you want to change the {@link module:engine/view/element~Element view element} of the marker while its data in the model
|
|
972
|
+
* remains the same, use the dedicated {@link module:engine/controller/editingcontroller~EditingController#reconvertMarker} method.
|
|
995
973
|
*
|
|
996
974
|
* The `options.usingOperation` parameter lets you change if the marker should be managed by operations or not. See
|
|
997
975
|
* {@link module:engine/model/markercollection~Marker marker class description} to learn about the difference between
|
|
@@ -1037,7 +1015,7 @@ export default class Writer {
|
|
|
1037
1015
|
|
|
1038
1016
|
if ( !currentMarker ) {
|
|
1039
1017
|
/**
|
|
1040
|
-
* Marker with provided name does not
|
|
1018
|
+
* Marker with provided name does not exist and will not be updated.
|
|
1041
1019
|
*
|
|
1042
1020
|
* @error writer-updatemarker-marker-not-exists
|
|
1043
1021
|
*/
|
|
@@ -1045,6 +1023,18 @@ export default class Writer {
|
|
|
1045
1023
|
}
|
|
1046
1024
|
|
|
1047
1025
|
if ( !options ) {
|
|
1026
|
+
/**
|
|
1027
|
+
* The usage of `writer.updateMarker()` only to reconvert (refresh) a
|
|
1028
|
+
* {@link module:engine/model/markercollection~Marker model marker} was deprecated and may not work in the future.
|
|
1029
|
+
* Please update your code to use
|
|
1030
|
+
* {@link module:engine/controller/editingcontroller~EditingController#reconvertMarker `editor.editing.reconvertMarker()`}
|
|
1031
|
+
* instead.
|
|
1032
|
+
*
|
|
1033
|
+
* @error writer-updatemarker-reconvert-using-editingcontroller
|
|
1034
|
+
* @param {String} markerName The name of the updated marker.
|
|
1035
|
+
*/
|
|
1036
|
+
logWarning( 'writer-updatemarker-reconvert-using-editingcontroller', { markerName } );
|
|
1037
|
+
|
|
1048
1038
|
this.model.markers._refresh( currentMarker );
|
|
1049
1039
|
|
|
1050
1040
|
return;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -24,16 +24,6 @@ const DEFAULT_PRIORITY = 10;
|
|
|
24
24
|
* To create a new attribute element instance use the
|
|
25
25
|
* {@link module:engine/view/downcastwriter~DowncastWriter#createAttributeElement `DowncastWriter#createAttributeElement()`} method.
|
|
26
26
|
*
|
|
27
|
-
* **Note:** Attribute elements by default can wrap {@link module:engine/view/text~Text},
|
|
28
|
-
* {@link module:engine/view/emptyelement~EmptyElement}, {@link module:engine/view/uielement~UIElement},
|
|
29
|
-
* {@link module:engine/view/rawelement~RawElement} and other attribute elements with higher priority. Other elements while placed inside
|
|
30
|
-
* an attribute element will split it (or nest in case of an `AttributeElement`). This behavior can be modified by changing
|
|
31
|
-
* the `isAllowedInsideAttributeElement` option while creating
|
|
32
|
-
* {@link module:engine/view/downcastwriter~DowncastWriter#createContainerElement},
|
|
33
|
-
* {@link module:engine/view/downcastwriter~DowncastWriter#createEmptyElement},
|
|
34
|
-
* {@link module:engine/view/downcastwriter~DowncastWriter#createUIElement} or
|
|
35
|
-
* {@link module:engine/view/downcastwriter~DowncastWriter#createRawElement}.
|
|
36
|
-
*
|
|
37
27
|
* @extends module:engine/view/element~Element
|
|
38
28
|
*/
|
|
39
29
|
export default class AttributeElement extends Element {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
package/src/view/document.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -141,7 +141,8 @@ export default class Document {
|
|
|
141
141
|
*
|
|
142
142
|
* * adding or removing attribute from elements,
|
|
143
143
|
* * changes inside of {@link module:engine/view/uielement~UIElement UI elements},
|
|
144
|
-
* * {@link module:engine/
|
|
144
|
+
* * {@link module:engine/controller/editingcontroller~EditingController#reconvertItem marking some of the model elements to be
|
|
145
|
+
* re-converted}.
|
|
145
146
|
*
|
|
146
147
|
* Try to avoid changes which touch view structure:
|
|
147
148
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|