@ckeditor/ckeditor5-engine 47.6.1 → 48.0.0-alpha.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.
Files changed (258) hide show
  1. package/LICENSE.md +1 -1
  2. package/{src → dist}/engineconfig.d.ts +6 -15
  3. package/dist/index-editor.css +38 -15
  4. package/dist/index.css +37 -37
  5. package/dist/index.css.map +1 -1
  6. package/{src → dist}/index.d.ts +0 -1
  7. package/dist/index.js +588 -94
  8. package/dist/index.js.map +1 -1
  9. package/{src → dist}/model/model.d.ts +10 -4
  10. package/{src → dist}/model/selection.d.ts +1 -1
  11. package/{src → dist}/view/downcastwriter.d.ts +3 -2
  12. package/{src → dist}/view/element.d.ts +2 -2
  13. package/{src → dist}/view/matcher.d.ts +4 -2
  14. package/dist/view/styles/background.d.ts +18 -0
  15. package/{src → dist}/view/styles/border.d.ts +0 -12
  16. package/{src → dist}/view/styles/margin.d.ts +0 -13
  17. package/{src → dist}/view/styles/padding.d.ts +0 -13
  18. package/{src → dist}/view/styles/utils.d.ts +12 -0
  19. package/package.json +20 -39
  20. package/src/controller/datacontroller.js +0 -522
  21. package/src/controller/editingcontroller.js +0 -181
  22. package/src/conversion/conversion.js +0 -606
  23. package/src/conversion/conversionhelpers.js +0 -33
  24. package/src/conversion/downcastdispatcher.js +0 -563
  25. package/src/conversion/downcasthelpers.js +0 -2160
  26. package/src/conversion/mapper.js +0 -1050
  27. package/src/conversion/modelconsumable.js +0 -331
  28. package/src/conversion/upcastdispatcher.js +0 -470
  29. package/src/conversion/upcasthelpers.js +0 -952
  30. package/src/conversion/viewconsumable.js +0 -541
  31. package/src/dataprocessor/basichtmlwriter.js +0 -22
  32. package/src/dataprocessor/dataprocessor.js +0 -5
  33. package/src/dataprocessor/htmldataprocessor.js +0 -107
  34. package/src/dataprocessor/htmlwriter.js +0 -5
  35. package/src/dataprocessor/xmldataprocessor.js +0 -127
  36. package/src/dev-utils/model.js +0 -396
  37. package/src/dev-utils/operationreplayer.js +0 -116
  38. package/src/dev-utils/utils.js +0 -122
  39. package/src/dev-utils/view.js +0 -990
  40. package/src/engineconfig.js +0 -5
  41. package/src/index.js +0 -134
  42. package/src/legacyerrors.js +0 -17
  43. package/src/model/batch.js +0 -98
  44. package/src/model/differ.js +0 -1288
  45. package/src/model/document.js +0 -398
  46. package/src/model/documentfragment.js +0 -332
  47. package/src/model/documentselection.js +0 -1026
  48. package/src/model/element.js +0 -323
  49. package/src/model/history.js +0 -206
  50. package/src/model/item.js +0 -5
  51. package/src/model/liveposition.js +0 -93
  52. package/src/model/liverange.js +0 -121
  53. package/src/model/markercollection.js +0 -436
  54. package/src/model/model.js +0 -866
  55. package/src/model/node.js +0 -371
  56. package/src/model/nodelist.js +0 -244
  57. package/src/model/operation/attributeoperation.js +0 -172
  58. package/src/model/operation/detachoperation.js +0 -87
  59. package/src/model/operation/insertoperation.js +0 -153
  60. package/src/model/operation/markeroperation.js +0 -136
  61. package/src/model/operation/mergeoperation.js +0 -184
  62. package/src/model/operation/moveoperation.js +0 -179
  63. package/src/model/operation/nooperation.js +0 -48
  64. package/src/model/operation/operation.js +0 -78
  65. package/src/model/operation/operationfactory.js +0 -44
  66. package/src/model/operation/renameoperation.js +0 -128
  67. package/src/model/operation/rootattributeoperation.js +0 -173
  68. package/src/model/operation/rootoperation.js +0 -106
  69. package/src/model/operation/splitoperation.js +0 -214
  70. package/src/model/operation/transform.js +0 -2211
  71. package/src/model/operation/utils.js +0 -217
  72. package/src/model/position.js +0 -1041
  73. package/src/model/range.js +0 -880
  74. package/src/model/rootelement.js +0 -82
  75. package/src/model/schema.js +0 -1542
  76. package/src/model/selection.js +0 -814
  77. package/src/model/text.js +0 -92
  78. package/src/model/textproxy.js +0 -202
  79. package/src/model/treewalker.js +0 -313
  80. package/src/model/typecheckable.js +0 -16
  81. package/src/model/utils/autoparagraphing.js +0 -63
  82. package/src/model/utils/deletecontent.js +0 -509
  83. package/src/model/utils/getselectedcontent.js +0 -126
  84. package/src/model/utils/insertcontent.js +0 -750
  85. package/src/model/utils/insertobject.js +0 -135
  86. package/src/model/utils/modifyselection.js +0 -187
  87. package/src/model/utils/selection-post-fixer.js +0 -264
  88. package/src/model/writer.js +0 -1318
  89. package/src/view/attributeelement.js +0 -220
  90. package/src/view/containerelement.js +0 -91
  91. package/src/view/datatransfer.js +0 -106
  92. package/src/view/document.js +0 -139
  93. package/src/view/documentfragment.js +0 -251
  94. package/src/view/documentselection.js +0 -270
  95. package/src/view/domconverter.js +0 -1661
  96. package/src/view/downcastwriter.js +0 -1589
  97. package/src/view/editableelement.js +0 -74
  98. package/src/view/element.js +0 -1053
  99. package/src/view/elementdefinition.js +0 -5
  100. package/src/view/emptyelement.js +0 -83
  101. package/src/view/filler.js +0 -161
  102. package/src/view/item.js +0 -5
  103. package/src/view/matcher.js +0 -437
  104. package/src/view/node.js +0 -238
  105. package/src/view/observer/arrowkeysobserver.js +0 -40
  106. package/src/view/observer/bubblingemittermixin.js +0 -215
  107. package/src/view/observer/bubblingeventinfo.js +0 -49
  108. package/src/view/observer/clickobserver.js +0 -26
  109. package/src/view/observer/compositionobserver.js +0 -64
  110. package/src/view/observer/domeventdata.js +0 -63
  111. package/src/view/observer/domeventobserver.js +0 -81
  112. package/src/view/observer/fakeselectionobserver.js +0 -95
  113. package/src/view/observer/focusobserver.js +0 -166
  114. package/src/view/observer/inputobserver.js +0 -236
  115. package/src/view/observer/keyobserver.js +0 -36
  116. package/src/view/observer/mouseobserver.js +0 -26
  117. package/src/view/observer/mutationobserver.js +0 -219
  118. package/src/view/observer/observer.js +0 -92
  119. package/src/view/observer/pointerobserver.js +0 -26
  120. package/src/view/observer/selectionobserver.js +0 -318
  121. package/src/view/observer/tabobserver.js +0 -42
  122. package/src/view/observer/touchobserver.js +0 -26
  123. package/src/view/placeholder.js +0 -285
  124. package/src/view/position.js +0 -341
  125. package/src/view/range.js +0 -451
  126. package/src/view/rawelement.js +0 -115
  127. package/src/view/renderer.js +0 -1148
  128. package/src/view/rooteditableelement.js +0 -78
  129. package/src/view/selection.js +0 -594
  130. package/src/view/styles/background.d.ts +0 -33
  131. package/src/view/styles/background.js +0 -74
  132. package/src/view/styles/border.js +0 -316
  133. package/src/view/styles/margin.js +0 -34
  134. package/src/view/styles/padding.js +0 -34
  135. package/src/view/styles/utils.js +0 -219
  136. package/src/view/stylesmap.js +0 -941
  137. package/src/view/text.js +0 -110
  138. package/src/view/textproxy.js +0 -136
  139. package/src/view/tokenlist.js +0 -194
  140. package/src/view/treewalker.js +0 -389
  141. package/src/view/typecheckable.js +0 -19
  142. package/src/view/uielement.js +0 -194
  143. package/src/view/upcastwriter.js +0 -363
  144. package/src/view/view.js +0 -579
  145. package/theme/placeholder.css +0 -36
  146. package/theme/renderer.css +0 -9
  147. /package/{src → dist}/controller/datacontroller.d.ts +0 -0
  148. /package/{src → dist}/controller/editingcontroller.d.ts +0 -0
  149. /package/{src → dist}/conversion/conversion.d.ts +0 -0
  150. /package/{src → dist}/conversion/conversionhelpers.d.ts +0 -0
  151. /package/{src → dist}/conversion/downcastdispatcher.d.ts +0 -0
  152. /package/{src → dist}/conversion/downcasthelpers.d.ts +0 -0
  153. /package/{src → dist}/conversion/mapper.d.ts +0 -0
  154. /package/{src → dist}/conversion/modelconsumable.d.ts +0 -0
  155. /package/{src → dist}/conversion/upcastdispatcher.d.ts +0 -0
  156. /package/{src → dist}/conversion/upcasthelpers.d.ts +0 -0
  157. /package/{src → dist}/conversion/viewconsumable.d.ts +0 -0
  158. /package/{src → dist}/dataprocessor/basichtmlwriter.d.ts +0 -0
  159. /package/{src → dist}/dataprocessor/dataprocessor.d.ts +0 -0
  160. /package/{src → dist}/dataprocessor/htmldataprocessor.d.ts +0 -0
  161. /package/{src → dist}/dataprocessor/htmlwriter.d.ts +0 -0
  162. /package/{src → dist}/dataprocessor/xmldataprocessor.d.ts +0 -0
  163. /package/{src → dist}/dev-utils/model.d.ts +0 -0
  164. /package/{src → dist}/dev-utils/operationreplayer.d.ts +0 -0
  165. /package/{src → dist}/dev-utils/utils.d.ts +0 -0
  166. /package/{src → dist}/dev-utils/view.d.ts +0 -0
  167. /package/{src → dist}/legacyerrors.d.ts +0 -0
  168. /package/{src → dist}/model/batch.d.ts +0 -0
  169. /package/{src → dist}/model/differ.d.ts +0 -0
  170. /package/{src → dist}/model/document.d.ts +0 -0
  171. /package/{src → dist}/model/documentfragment.d.ts +0 -0
  172. /package/{src → dist}/model/documentselection.d.ts +0 -0
  173. /package/{src → dist}/model/element.d.ts +0 -0
  174. /package/{src → dist}/model/history.d.ts +0 -0
  175. /package/{src → dist}/model/item.d.ts +0 -0
  176. /package/{src → dist}/model/liveposition.d.ts +0 -0
  177. /package/{src → dist}/model/liverange.d.ts +0 -0
  178. /package/{src → dist}/model/markercollection.d.ts +0 -0
  179. /package/{src → dist}/model/node.d.ts +0 -0
  180. /package/{src → dist}/model/nodelist.d.ts +0 -0
  181. /package/{src → dist}/model/operation/attributeoperation.d.ts +0 -0
  182. /package/{src → dist}/model/operation/detachoperation.d.ts +0 -0
  183. /package/{src → dist}/model/operation/insertoperation.d.ts +0 -0
  184. /package/{src → dist}/model/operation/markeroperation.d.ts +0 -0
  185. /package/{src → dist}/model/operation/mergeoperation.d.ts +0 -0
  186. /package/{src → dist}/model/operation/moveoperation.d.ts +0 -0
  187. /package/{src → dist}/model/operation/nooperation.d.ts +0 -0
  188. /package/{src → dist}/model/operation/operation.d.ts +0 -0
  189. /package/{src → dist}/model/operation/operationfactory.d.ts +0 -0
  190. /package/{src → dist}/model/operation/renameoperation.d.ts +0 -0
  191. /package/{src → dist}/model/operation/rootattributeoperation.d.ts +0 -0
  192. /package/{src → dist}/model/operation/rootoperation.d.ts +0 -0
  193. /package/{src → dist}/model/operation/splitoperation.d.ts +0 -0
  194. /package/{src → dist}/model/operation/transform.d.ts +0 -0
  195. /package/{src → dist}/model/operation/utils.d.ts +0 -0
  196. /package/{src → dist}/model/position.d.ts +0 -0
  197. /package/{src → dist}/model/range.d.ts +0 -0
  198. /package/{src → dist}/model/rootelement.d.ts +0 -0
  199. /package/{src → dist}/model/schema.d.ts +0 -0
  200. /package/{src → dist}/model/text.d.ts +0 -0
  201. /package/{src → dist}/model/textproxy.d.ts +0 -0
  202. /package/{src → dist}/model/treewalker.d.ts +0 -0
  203. /package/{src → dist}/model/typecheckable.d.ts +0 -0
  204. /package/{src → dist}/model/utils/autoparagraphing.d.ts +0 -0
  205. /package/{src → dist}/model/utils/deletecontent.d.ts +0 -0
  206. /package/{src → dist}/model/utils/getselectedcontent.d.ts +0 -0
  207. /package/{src → dist}/model/utils/insertcontent.d.ts +0 -0
  208. /package/{src → dist}/model/utils/insertobject.d.ts +0 -0
  209. /package/{src → dist}/model/utils/modifyselection.d.ts +0 -0
  210. /package/{src → dist}/model/utils/selection-post-fixer.d.ts +0 -0
  211. /package/{src → dist}/model/writer.d.ts +0 -0
  212. /package/{src → dist}/view/attributeelement.d.ts +0 -0
  213. /package/{src → dist}/view/containerelement.d.ts +0 -0
  214. /package/{src → dist}/view/datatransfer.d.ts +0 -0
  215. /package/{src → dist}/view/document.d.ts +0 -0
  216. /package/{src → dist}/view/documentfragment.d.ts +0 -0
  217. /package/{src → dist}/view/documentselection.d.ts +0 -0
  218. /package/{src → dist}/view/domconverter.d.ts +0 -0
  219. /package/{src → dist}/view/editableelement.d.ts +0 -0
  220. /package/{src → dist}/view/elementdefinition.d.ts +0 -0
  221. /package/{src → dist}/view/emptyelement.d.ts +0 -0
  222. /package/{src → dist}/view/filler.d.ts +0 -0
  223. /package/{src → dist}/view/item.d.ts +0 -0
  224. /package/{src → dist}/view/node.d.ts +0 -0
  225. /package/{src → dist}/view/observer/arrowkeysobserver.d.ts +0 -0
  226. /package/{src → dist}/view/observer/bubblingemittermixin.d.ts +0 -0
  227. /package/{src → dist}/view/observer/bubblingeventinfo.d.ts +0 -0
  228. /package/{src → dist}/view/observer/clickobserver.d.ts +0 -0
  229. /package/{src → dist}/view/observer/compositionobserver.d.ts +0 -0
  230. /package/{src → dist}/view/observer/domeventdata.d.ts +0 -0
  231. /package/{src → dist}/view/observer/domeventobserver.d.ts +0 -0
  232. /package/{src → dist}/view/observer/fakeselectionobserver.d.ts +0 -0
  233. /package/{src → dist}/view/observer/focusobserver.d.ts +0 -0
  234. /package/{src → dist}/view/observer/inputobserver.d.ts +0 -0
  235. /package/{src → dist}/view/observer/keyobserver.d.ts +0 -0
  236. /package/{src → dist}/view/observer/mouseobserver.d.ts +0 -0
  237. /package/{src → dist}/view/observer/mutationobserver.d.ts +0 -0
  238. /package/{src → dist}/view/observer/observer.d.ts +0 -0
  239. /package/{src → dist}/view/observer/pointerobserver.d.ts +0 -0
  240. /package/{src → dist}/view/observer/selectionobserver.d.ts +0 -0
  241. /package/{src → dist}/view/observer/tabobserver.d.ts +0 -0
  242. /package/{src → dist}/view/observer/touchobserver.d.ts +0 -0
  243. /package/{src → dist}/view/placeholder.d.ts +0 -0
  244. /package/{src → dist}/view/position.d.ts +0 -0
  245. /package/{src → dist}/view/range.d.ts +0 -0
  246. /package/{src → dist}/view/rawelement.d.ts +0 -0
  247. /package/{src → dist}/view/renderer.d.ts +0 -0
  248. /package/{src → dist}/view/rooteditableelement.d.ts +0 -0
  249. /package/{src → dist}/view/selection.d.ts +0 -0
  250. /package/{src → dist}/view/stylesmap.d.ts +0 -0
  251. /package/{src → dist}/view/text.d.ts +0 -0
  252. /package/{src → dist}/view/textproxy.d.ts +0 -0
  253. /package/{src → dist}/view/tokenlist.d.ts +0 -0
  254. /package/{src → dist}/view/treewalker.d.ts +0 -0
  255. /package/{src → dist}/view/typecheckable.d.ts +0 -0
  256. /package/{src → dist}/view/uielement.d.ts +0 -0
  257. /package/{src → dist}/view/upcastwriter.d.ts +0 -0
  258. /package/{src → dist}/view/view.d.ts +0 -0
@@ -1,1148 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module engine/view/renderer
7
- */
8
- import { ViewText } from './text.js';
9
- import { ViewPosition } from './position.js';
10
- import { INLINE_FILLER, INLINE_FILLER_LENGTH, startsWithFiller, isInlineFiller } from './filler.js';
11
- import { CKEditorError, ObservableMixin, diff, env, fastDiff, insertAt, isComment, isNode, isText, remove, indexOf } from '@ckeditor/ckeditor5-utils';
12
- // @if CK_DEBUG_TYPING // const { _buildLogMessage } = require( '../dev-utils/utils.js' );
13
- import '../../theme/renderer.css';
14
- /**
15
- * Renderer is responsible for updating the DOM structure and the DOM selection based on
16
- * the {@link module:engine/view/renderer~ViewRenderer#markToSync information about updated view nodes}.
17
- * In other words, it renders the view to the DOM.
18
- *
19
- * Its main responsibility is to make only the necessary, minimal changes to the DOM. However, unlike in many
20
- * virtual DOM implementations, the primary reason for doing minimal changes is not the performance but ensuring
21
- * that native editing features such as text composition, autocompletion, spell checking, selection's x-index are
22
- * affected as little as possible.
23
- *
24
- * Renderer uses {@link module:engine/view/domconverter~ViewDomConverter} to transform view nodes and positions
25
- * to and from the DOM.
26
- */
27
- export class ViewRenderer extends /* #__PURE__ */ ObservableMixin() {
28
- /**
29
- * Set of DOM Documents instances.
30
- */
31
- domDocuments = new Set();
32
- /**
33
- * Converter instance.
34
- */
35
- domConverter;
36
- /**
37
- * Set of nodes which attributes changed and may need to be rendered.
38
- */
39
- markedAttributes = new Set();
40
- /**
41
- * Set of elements which child lists changed and may need to be rendered.
42
- */
43
- markedChildren = new Set();
44
- /**
45
- * Set of text nodes which text data changed and may need to be rendered.
46
- */
47
- markedTexts = new Set();
48
- /**
49
- * View selection. Renderer updates DOM selection based on the view selection.
50
- */
51
- selection;
52
- /**
53
- * The text node in which the inline filler was rendered.
54
- */
55
- _inlineFiller = null;
56
- /**
57
- * DOM element containing fake selection.
58
- */
59
- _fakeSelectionContainer = null;
60
- /**
61
- * Creates a renderer instance.
62
- *
63
- * @param domConverter Converter instance.
64
- * @param selection View selection.
65
- */
66
- constructor(domConverter, selection) {
67
- super();
68
- this.domConverter = domConverter;
69
- this.selection = selection;
70
- this.set('isFocused', false);
71
- this.set('isSelecting', false);
72
- this.set('isComposing', false);
73
- // Rendering the selection and inline filler manipulation should be postponed in (non-Android) Blink until the user finishes
74
- // creating the selection in DOM to avoid accidental selection collapsing
75
- // (https://github.com/ckeditor/ckeditor5/issues/10562, https://github.com/ckeditor/ckeditor5/issues/10723).
76
- // When the user stops selecting, all pending changes should be rendered ASAP, though.
77
- if (env.isBlink && !env.isAndroid) {
78
- this.on('change:isSelecting', () => {
79
- if (!this.isSelecting) {
80
- this.render();
81
- }
82
- });
83
- }
84
- }
85
- /**
86
- * Marks a view node to be updated in the DOM by {@link #render `render()`}.
87
- *
88
- * Note that only view nodes whose parents have corresponding DOM elements need to be marked to be synchronized.
89
- *
90
- * @see #markedAttributes
91
- * @see #markedChildren
92
- * @see #markedTexts
93
- *
94
- * @param type Type of the change.
95
- * @param node ViewNode to be marked.
96
- */
97
- markToSync(type, node) {
98
- if (type === 'text') {
99
- if (this.domConverter.mapViewToDom(node.parent)) {
100
- this.markedTexts.add(node);
101
- }
102
- }
103
- else {
104
- // If the node has no DOM element it is not rendered yet,
105
- // its children/attributes do not need to be marked to be sync.
106
- if (!this.domConverter.mapViewToDom(node)) {
107
- return;
108
- }
109
- if (type === 'attributes') {
110
- this.markedAttributes.add(node);
111
- }
112
- else if (type === 'children') {
113
- this.markedChildren.add(node);
114
- }
115
- else {
116
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
117
- const unreachable = type;
118
- /**
119
- * Unknown type passed to Renderer.markToSync.
120
- *
121
- * @error view-renderer-unknown-type
122
- */
123
- throw new CKEditorError('view-renderer-unknown-type', this);
124
- }
125
- }
126
- }
127
- /**
128
- * Renders all buffered changes ({@link #markedAttributes}, {@link #markedChildren} and {@link #markedTexts}) and
129
- * the current view selection (if needed) to the DOM by applying a minimal set of changes to it.
130
- *
131
- * Renderer tries not to break the text composition (e.g. IME) and x-index of the selection,
132
- * so it does as little as it is needed to update the DOM.
133
- *
134
- * Renderer also handles {@link module:engine/view/filler fillers}. Especially, it checks if the inline filler is needed
135
- * at the selection position and adds or removes it. To prevent breaking text composition inline filler will not be
136
- * removed as long as the selection is in the text node which needed it at first.
137
- */
138
- render() {
139
- // Ignore rendering while in the composition mode. Composition events are not cancellable and browser will modify the DOM tree.
140
- // All marked elements, attributes, etc. will wait until next render after the composition ends.
141
- // On Android composition events are immediately applied to the model, so we don't need to skip rendering,
142
- // and we should not do it because the difference between view and DOM could lead to position mapping problems.
143
- if (this.isComposing && !env.isAndroid) {
144
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
145
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
146
- // @if CK_DEBUG_TYPING // '%cRendering aborted while isComposing.',
147
- // @if CK_DEBUG_TYPING // 'font-style: italic'
148
- // @if CK_DEBUG_TYPING // ) );
149
- // @if CK_DEBUG_TYPING // }
150
- return;
151
- }
152
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
153
- // @if CK_DEBUG_TYPING // console.group( ..._buildLogMessage( this, 'Renderer',
154
- // @if CK_DEBUG_TYPING // '%cRendering',
155
- // @if CK_DEBUG_TYPING // 'font-weight: bold'
156
- // @if CK_DEBUG_TYPING // ) );
157
- // @if CK_DEBUG_TYPING // }
158
- let inlineFillerPosition = null;
159
- const isInlineFillerRenderingPossible = env.isBlink && !env.isAndroid ? !this.isSelecting : true;
160
- // Refresh mappings.
161
- for (const element of this.markedChildren) {
162
- this._updateChildrenMappings(element);
163
- }
164
- // Don't manipulate inline fillers while the selection is being made in (non-Android) Blink to prevent accidental
165
- // DOM selection collapsing
166
- // (https://github.com/ckeditor/ckeditor5/issues/10562, https://github.com/ckeditor/ckeditor5/issues/10723).
167
- if (isInlineFillerRenderingPossible) {
168
- // There was inline filler rendered in the DOM but it's not
169
- // at the selection position any more, so we can remove it
170
- // (cause even if it's needed, it must be placed in another location).
171
- if (this._inlineFiller && !this._isSelectionInInlineFiller()) {
172
- this._removeInlineFiller();
173
- }
174
- // If we've got the filler, let's try to guess its position in the view.
175
- if (this._inlineFiller) {
176
- inlineFillerPosition = this._getInlineFillerPosition();
177
- }
178
- // Otherwise, if it's needed, create it at the selection position.
179
- else if (this._needsInlineFillerAtSelection()) {
180
- inlineFillerPosition = this.selection.getFirstPosition();
181
- // Do not use `markToSync` so it will be added even if the parent is already added.
182
- this.markedChildren.add(inlineFillerPosition.parent);
183
- }
184
- }
185
- // Make sure the inline filler has any parent, so it can be mapped to view position by ViewDomConverter.
186
- else if (this._inlineFiller && this._inlineFiller.parentNode) {
187
- // While the user is making selection, preserve the inline filler at its original position.
188
- inlineFillerPosition = this.domConverter.domPositionToView(this._inlineFiller);
189
- // While down-casting the document selection attributes, all existing empty
190
- // attribute elements (for selection position) are removed from the view and DOM,
191
- // so make sure that we were able to map filler position.
192
- // https://github.com/ckeditor/ckeditor5/issues/12026
193
- if (inlineFillerPosition && inlineFillerPosition.parent.is('$text')) {
194
- // The inline filler position is expected to be before the text node.
195
- inlineFillerPosition = ViewPosition._createBefore(inlineFillerPosition.parent);
196
- }
197
- }
198
- for (const element of this.markedAttributes) {
199
- this._updateAttrs(element);
200
- }
201
- for (const element of this.markedChildren) {
202
- this._updateChildren(element, { inlineFillerPosition });
203
- }
204
- for (const node of this.markedTexts) {
205
- if (!this.markedChildren.has(node.parent) && this.domConverter.mapViewToDom(node.parent)) {
206
- this._updateText(node, { inlineFillerPosition });
207
- }
208
- }
209
- // * Check whether the inline filler is required and where it really is in the DOM.
210
- // At this point in most cases it will be in the DOM, but there are exceptions.
211
- // For example, if the inline filler was deep in the created DOM structure, it will not be created.
212
- // Similarly, if it was removed at the beginning of this function and then neither text nor children were updated,
213
- // it will not be present. Fix those and similar scenarios.
214
- // * Don't manipulate inline fillers while the selection is being made in (non-Android) Blink to prevent accidental
215
- // DOM selection collapsing
216
- // (https://github.com/ckeditor/ckeditor5/issues/10562, https://github.com/ckeditor/ckeditor5/issues/10723).
217
- if (isInlineFillerRenderingPossible) {
218
- if (inlineFillerPosition) {
219
- const fillerDomPosition = this.domConverter.viewPositionToDom(inlineFillerPosition);
220
- const domDocument = fillerDomPosition.parent.ownerDocument;
221
- if (!startsWithFiller(fillerDomPosition.parent)) {
222
- // Filler has not been created at filler position. Create it now.
223
- this._inlineFiller = addInlineFiller(domDocument, fillerDomPosition.parent, fillerDomPosition.offset);
224
- }
225
- else {
226
- // Filler has been found, save it.
227
- this._inlineFiller = fillerDomPosition.parent;
228
- }
229
- }
230
- else {
231
- // There is no filler needed.
232
- this._inlineFiller = null;
233
- }
234
- }
235
- // First focus the new editing host, then update the selection.
236
- // Otherwise, FF may throw an error (https://github.com/ckeditor/ckeditor5/issues/721).
237
- this._updateFocus();
238
- this._updateSelection();
239
- this.domConverter._clearTemporaryCustomProperties();
240
- this.markedTexts.clear();
241
- this.markedAttributes.clear();
242
- this.markedChildren.clear();
243
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
244
- // @if CK_DEBUG_TYPING // console.groupEnd();
245
- // @if CK_DEBUG_TYPING // }
246
- }
247
- /**
248
- * Updates mappings of view element's children.
249
- *
250
- * Children that were replaced in the view structure by similar elements (same tag name) are treated as 'replaced'.
251
- * This means that their mappings can be updated so the new view elements are mapped to the existing DOM elements.
252
- * Thanks to that these elements do not need to be re-rendered completely.
253
- *
254
- * @param viewElement The view element whose children mappings will be updated.
255
- */
256
- _updateChildrenMappings(viewElement) {
257
- const domElement = this.domConverter.mapViewToDom(viewElement);
258
- if (!domElement) {
259
- // If there is no `domElement` it means that it was already removed from DOM and there is no need to process it.
260
- return;
261
- }
262
- // Removing nodes from the DOM as we iterate can cause `actualDomChildren`
263
- // (which is a live-updating `NodeList`) to get out of sync with the
264
- // indices that we compute as we iterate over `actions`.
265
- // This would produce incorrect element mappings.
266
- //
267
- // Converting live list to an array to make the list static.
268
- const actualDomChildren = Array.from(domElement.childNodes);
269
- const expectedDomChildren = Array.from(this.domConverter.viewChildrenToDom(viewElement, { withChildren: false }));
270
- const diff = this._diffNodeLists(actualDomChildren, expectedDomChildren);
271
- const actions = this._findUpdateActions(diff, actualDomChildren, expectedDomChildren, areSimilarElements);
272
- if (actions.indexOf('update') !== -1) {
273
- const counter = { equal: 0, insert: 0, delete: 0 };
274
- for (const action of actions) {
275
- if (action === 'update') {
276
- const insertIndex = counter.equal + counter.insert;
277
- const deleteIndex = counter.equal + counter.delete;
278
- const viewChild = viewElement.getChild(insertIndex);
279
- // UIElement and RawElement are special cases. Their children are not stored in a view (#799)
280
- // so we cannot use them with replacing flow (since they use view children during rendering
281
- // which will always result in rendering empty elements).
282
- if (viewChild && !viewChild.is('uiElement') && !viewChild.is('rawElement')) {
283
- this._updateElementMappings(viewChild, actualDomChildren[deleteIndex]);
284
- }
285
- remove(expectedDomChildren[insertIndex]);
286
- counter.equal++;
287
- }
288
- else {
289
- counter[action]++;
290
- }
291
- }
292
- }
293
- }
294
- /**
295
- * Updates mappings of a given view element.
296
- *
297
- * @param viewElement The view element whose mappings will be updated.
298
- * @param domElement The DOM element representing the given view element.
299
- */
300
- _updateElementMappings(viewElement, domElement) {
301
- // Remap 'DomConverter' bindings.
302
- this.domConverter.unbindDomElement(domElement);
303
- this.domConverter.bindElements(domElement, viewElement);
304
- // View element may have children which needs to be updated, but are not marked, mark them to update.
305
- this.markedChildren.add(viewElement);
306
- // Because we replace new view element mapping with the existing one, the corresponding DOM element
307
- // will not be rerendered. The new view element may have different attributes than the previous one.
308
- // Since its corresponding DOM element will not be rerendered, new attributes will not be added
309
- // to the DOM, so we need to mark it here to make sure its attributes gets updated. See #1427 for more
310
- // detailed case study.
311
- // Also there are cases where replaced element is removed from the view structure and then has
312
- // its attributes changed or removed. In such cases the element will not be present in `markedAttributes`
313
- // and also may be the same (`element.isSimilar()`) as the reused element not having its attributes updated.
314
- // To prevent such situations we always mark reused element to have its attributes rerenderd (#1560).
315
- this.markedAttributes.add(viewElement);
316
- }
317
- /**
318
- * Gets the position of the inline filler based on the current selection.
319
- * Here, we assume that we know that the filler is needed and
320
- * {@link #_isSelectionInInlineFiller is at the selection position}, and, since it is needed,
321
- * it is somewhere at the selection position.
322
- *
323
- * Note: The filler position cannot be restored based on the filler's DOM text node, because
324
- * when this method is called (before rendering), the bindings will often be broken. View-to-DOM
325
- * bindings are only dependable after rendering.
326
- */
327
- _getInlineFillerPosition() {
328
- const firstPos = this.selection.getFirstPosition();
329
- if (firstPos.parent.is('$text')) {
330
- return ViewPosition._createBefore(firstPos.parent);
331
- }
332
- else {
333
- return firstPos;
334
- }
335
- }
336
- /**
337
- * Returns `true` if the selection has not left the inline filler's text node.
338
- * If it is `true`, it means that the filler had been added for a reason and the selection did not
339
- * leave the filler's text node. For example, the user can be in the middle of a composition so it should not be touched.
340
- *
341
- * @returns `true` if the inline filler and selection are in the same place.
342
- */
343
- _isSelectionInInlineFiller() {
344
- if (this.selection.rangeCount != 1 || !this.selection.isCollapsed) {
345
- return false;
346
- }
347
- // Note, we can't check if selection's position equals position of the
348
- // this._inlineFiller node, because of #663. We may not be able to calculate
349
- // the filler's position in the view at this stage.
350
- // Instead, we check it the other way – whether selection is anchored in
351
- // that text node or next to it.
352
- // Possible options are:
353
- // "FILLER{}"
354
- // "FILLERadded-text{}"
355
- const selectionPosition = this.selection.getFirstPosition();
356
- const position = this.domConverter.viewPositionToDom(selectionPosition);
357
- if (position && isText(position.parent) && startsWithFiller(position.parent)) {
358
- return true;
359
- }
360
- return false;
361
- }
362
- /**
363
- * Removes the inline filler.
364
- */
365
- _removeInlineFiller() {
366
- const domFillerNode = this._inlineFiller;
367
- // Something weird happened and the stored node doesn't contain the filler's text.
368
- if (!startsWithFiller(domFillerNode)) {
369
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
370
- // @if CK_DEBUG_TYPING // console.log( ..._buildLogMessage( this, 'Renderer',
371
- // @if CK_DEBUG_TYPING // 'Inline filler node: ' +
372
- // @if CK_DEBUG_TYPING // `%c${ _escapeTextNodeData( domFillerNode.data ) }%c (${ domFillerNode.data.length })`,
373
- // @if CK_DEBUG_TYPING // 'color: blue',
374
- // @if CK_DEBUG_TYPING // ''
375
- // @if CK_DEBUG_TYPING // ) );
376
- // @if CK_DEBUG_TYPING // }
377
- /**
378
- * The inline filler node was lost. Most likely, something overwrote the filler text node
379
- * in the DOM.
380
- *
381
- * @error view-renderer-filler-was-lost
382
- */
383
- throw new CKEditorError('view-renderer-filler-was-lost', this);
384
- }
385
- if (isInlineFiller(domFillerNode)) {
386
- domFillerNode.remove();
387
- }
388
- else {
389
- domFillerNode.data = domFillerNode.data.substr(INLINE_FILLER_LENGTH);
390
- }
391
- this._inlineFiller = null;
392
- }
393
- /**
394
- * Checks if the inline {@link module:engine/view/filler filler} should be added.
395
- *
396
- * @returns `true` if the inline filler should be added.
397
- */
398
- _needsInlineFillerAtSelection() {
399
- if (this.selection.rangeCount != 1 || !this.selection.isCollapsed) {
400
- return false;
401
- }
402
- const selectionPosition = this.selection.getFirstPosition();
403
- const selectionParent = selectionPosition.parent;
404
- const selectionOffset = selectionPosition.offset;
405
- // If there is no DOM root we do not care about fillers.
406
- if (!this.domConverter.mapViewToDom(selectionParent.root)) {
407
- return false;
408
- }
409
- if (!(selectionParent.is('element'))) {
410
- return false;
411
- }
412
- // Prevent adding inline filler inside elements with contenteditable=false.
413
- // https://github.com/ckeditor/ckeditor5-engine/issues/1170
414
- if (!isEditable(selectionParent)) {
415
- return false;
416
- }
417
- const nodeBefore = selectionPosition.nodeBefore;
418
- const nodeAfter = selectionPosition.nodeAfter;
419
- if (nodeBefore instanceof ViewText || nodeAfter instanceof ViewText) {
420
- return false;
421
- }
422
- // We have block filler, we do not need inline one.
423
- if (selectionOffset === selectionParent.getFillerOffset() && (!nodeBefore || !nodeBefore.is('element', 'br'))) {
424
- return false;
425
- }
426
- // Do not use inline filler while typing outside inline elements on Android.
427
- // The deleteContentBackward would remove part of the inline filler instead of removing last letter in a link.
428
- if (env.isAndroid && (nodeBefore || nodeAfter)) {
429
- return false;
430
- }
431
- return true;
432
- }
433
- /**
434
- * Checks if text needs to be updated and possibly updates it.
435
- *
436
- * @param viewText View text to update.
437
- * @param options.inlineFillerPosition The position where the inline filler should be rendered.
438
- */
439
- _updateText(viewText, options) {
440
- const domText = this.domConverter.findCorrespondingDomText(viewText);
441
- const newDomText = this.domConverter.viewToDom(viewText);
442
- let expectedText = newDomText.data;
443
- const filler = options.inlineFillerPosition;
444
- if (filler && filler.parent == viewText.parent && filler.offset == viewText.index) {
445
- expectedText = INLINE_FILLER + expectedText;
446
- }
447
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
448
- // @if CK_DEBUG_TYPING // console.group( ..._buildLogMessage( this, 'Renderer',
449
- // @if CK_DEBUG_TYPING // '%cUpdate text',
450
- // @if CK_DEBUG_TYPING // 'font-weight: normal'
451
- // @if CK_DEBUG_TYPING // ) );
452
- // @if CK_DEBUG_TYPING // }
453
- this._updateTextNode(domText, expectedText);
454
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
455
- // @if CK_DEBUG_TYPING // console.groupEnd();
456
- // @if CK_DEBUG_TYPING // }
457
- }
458
- /**
459
- * Checks if attribute list needs to be updated and possibly updates it.
460
- *
461
- * @param viewElement The view element to update.
462
- */
463
- _updateAttrs(viewElement) {
464
- const domElement = this.domConverter.mapViewToDom(viewElement);
465
- if (!domElement) {
466
- // If there is no `domElement` it means that 'viewElement' is outdated as its mapping was updated
467
- // in 'this._updateChildrenMappings()'. There is no need to process it as new view element which
468
- // replaced old 'viewElement' mapping was also added to 'this.markedAttributes'
469
- // in 'this._updateChildrenMappings()' so it will be processed separately.
470
- return;
471
- }
472
- // Remove attributes from DOM elements if they do not exist in the view.
473
- //
474
- // Note: It is important to first remove DOM attributes and then set new ones, because some view attributes may be renamed
475
- // as they are set on DOM (due to unsafe attributes handling). If we set the view attribute first, and then remove
476
- // non-existing DOM attributes, then we would remove the attribute that we just set.
477
- //
478
- // Note: The domElement.attributes is a live collection, so we need to convert it to an array to avoid issues.
479
- for (const domAttr of Array.from(domElement.attributes)) {
480
- const key = domAttr.name;
481
- // All other attributes not present in the DOM should be removed.
482
- if (!viewElement.hasAttribute(key)) {
483
- this.domConverter.removeDomElementAttribute(domElement, key);
484
- }
485
- }
486
- // Add or overwrite attributes.
487
- for (const key of viewElement.getAttributeKeys()) {
488
- this.domConverter.setDomElementAttribute(domElement, key, viewElement.getAttribute(key), viewElement);
489
- }
490
- }
491
- /**
492
- * Checks if elements child list needs to be updated and possibly updates it.
493
- *
494
- * Note that on Android, to reduce the risk of composition breaks, it tries to update data of an existing
495
- * child text nodes instead of replacing them completely.
496
- *
497
- * @param viewElement View element to update.
498
- * @param options.inlineFillerPosition The position where the inline filler should be rendered.
499
- */
500
- _updateChildren(viewElement, options) {
501
- const domElement = this.domConverter.mapViewToDom(viewElement);
502
- if (!domElement) {
503
- // If there is no `domElement` it means that it was already removed from DOM.
504
- // There is no need to process it. It will be processed when re-inserted.
505
- return;
506
- }
507
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
508
- // @if CK_DEBUG_TYPING // console.group( ..._buildLogMessage( this, 'Renderer',
509
- // @if CK_DEBUG_TYPING // '%cUpdate children',
510
- // @if CK_DEBUG_TYPING // 'font-weight: normal'
511
- // @if CK_DEBUG_TYPING // ) );
512
- // @if CK_DEBUG_TYPING // }
513
- // IME on Android inserts a new text node while typing after a link
514
- // instead of updating an existing text node that follows the link.
515
- // We must normalize those text nodes so the diff won't get confused.
516
- // https://github.com/ckeditor/ckeditor5/issues/12574.
517
- if (env.isAndroid) {
518
- let previousDomNode = null;
519
- for (const domNode of Array.from(domElement.childNodes)) {
520
- if (previousDomNode && isText(previousDomNode) && isText(domNode)) {
521
- domElement.normalize();
522
- break;
523
- }
524
- previousDomNode = domNode;
525
- }
526
- }
527
- const inlineFillerPosition = options.inlineFillerPosition;
528
- const actualDomChildren = domElement.childNodes;
529
- const expectedDomChildren = Array.from(this.domConverter.viewChildrenToDom(viewElement, { bind: true }));
530
- // Inline filler element has to be created as it is present in the DOM, but not in the view. It is required
531
- // during diffing so text nodes could be compared correctly and also during rendering to maintain
532
- // proper order and indexes while updating the DOM.
533
- if (inlineFillerPosition && inlineFillerPosition.parent === viewElement) {
534
- addInlineFiller(domElement.ownerDocument, expectedDomChildren, inlineFillerPosition.offset);
535
- }
536
- const diff = this._diffNodeLists(actualDomChildren, expectedDomChildren);
537
- // We need to make sure that we update the existing text node and not replace it with another one.
538
- // The composition and different "language" browser extensions are fragile to text node being completely replaced.
539
- const actions = this._findUpdateActions(diff, actualDomChildren, expectedDomChildren, areTextNodes);
540
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping && actions.every( a => a == 'equal' ) ) {
541
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
542
- // @if CK_DEBUG_TYPING // '%cNothing to update.',
543
- // @if CK_DEBUG_TYPING // 'font-style: italic'
544
- // @if CK_DEBUG_TYPING // ) );
545
- // @if CK_DEBUG_TYPING // }
546
- let i = 0;
547
- const nodesToUnbind = new Set();
548
- // Handle deletions first.
549
- // This is to prevent a situation where an element that already exists in `actualDomChildren` is inserted at a different
550
- // index in `actualDomChildren`. Since `actualDomChildren` is a `NodeList`, this works like move, not like an insert,
551
- // and it disrupts the whole algorithm. See https://github.com/ckeditor/ckeditor5/issues/6367.
552
- //
553
- // It doesn't matter in what order we remove or add nodes, as long as we remove and add correct nodes at correct indexes.
554
- for (const action of actions) {
555
- if (action === 'delete') {
556
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
557
- // @if CK_DEBUG_TYPING // const node = actualDomChildren[ i ];
558
- // @if CK_DEBUG_TYPING // if ( isText( node ) ) {
559
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
560
- // @if CK_DEBUG_TYPING // '%cRemove text node' +
561
- // @if CK_DEBUG_TYPING // `${ this.isComposing ? ' while composing (may break composition)' : '' }: ` +
562
- // @if CK_DEBUG_TYPING // `%c${ _escapeTextNodeData( node.data ) }%c (${ node.data.length })`,
563
- // @if CK_DEBUG_TYPING // this.isComposing ? 'color: red; font-weight: bold' : '',
564
- // @if CK_DEBUG_TYPING // 'color: blue', ''
565
- // @if CK_DEBUG_TYPING // ) );
566
- // @if CK_DEBUG_TYPING // } else {
567
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
568
- // @if CK_DEBUG_TYPING // '%cRemove element' +
569
- // @if CK_DEBUG_TYPING // `${ this.isComposing ? ' while composing (may break composition)' : '' }: `,
570
- // @if CK_DEBUG_TYPING // this.isComposing ? 'color: red; font-weight: bold' : '',
571
- // @if CK_DEBUG_TYPING // node
572
- // @if CK_DEBUG_TYPING // ) );
573
- // @if CK_DEBUG_TYPING // }
574
- // @if CK_DEBUG_TYPING // }
575
- nodesToUnbind.add(actualDomChildren[i]);
576
- remove(actualDomChildren[i]);
577
- }
578
- else if (action === 'equal' || action === 'update') {
579
- i++;
580
- }
581
- }
582
- i = 0;
583
- for (const action of actions) {
584
- if (action === 'insert') {
585
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
586
- // @if CK_DEBUG_TYPING // const node = expectedDomChildren[ i ];
587
- // @if CK_DEBUG_TYPING // if ( isText( node ) ) {
588
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
589
- // @if CK_DEBUG_TYPING // '%cInsert text node' +
590
- // @if CK_DEBUG_TYPING // `${ this.isComposing ? ' while composing (may break composition)' : '' }: ` +
591
- // @if CK_DEBUG_TYPING // `%c${ _escapeTextNodeData( node.data ) }%c (${ node.data.length })`,
592
- // @if CK_DEBUG_TYPING // this.isComposing ? 'color: red; font-weight: bold' : '',
593
- // @if CK_DEBUG_TYPING // 'color: blue',
594
- // @if CK_DEBUG_TYPING // ''
595
- // @if CK_DEBUG_TYPING // ) );
596
- // @if CK_DEBUG_TYPING // } else {
597
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
598
- // @if CK_DEBUG_TYPING // '%cInsert element:',
599
- // @if CK_DEBUG_TYPING // 'font-weight: normal',
600
- // @if CK_DEBUG_TYPING // node
601
- // @if CK_DEBUG_TYPING // ) );
602
- // @if CK_DEBUG_TYPING // }
603
- // @if CK_DEBUG_TYPING // }
604
- insertAt(domElement, i, expectedDomChildren[i]);
605
- i++;
606
- }
607
- // Update the existing text node data.
608
- else if (action === 'update') {
609
- this._updateTextNode(actualDomChildren[i], expectedDomChildren[i].data);
610
- i++;
611
- }
612
- else if (action === 'equal') {
613
- // Force updating text nodes inside elements which did not change and do not need to be re-rendered (#1125).
614
- // Do it here (not in the loop above) because only after insertions the `i` index is correct.
615
- this._markDescendantTextToSync(this.domConverter.domToView(expectedDomChildren[i]));
616
- i++;
617
- }
618
- }
619
- // Unbind removed nodes. When node does not have a parent it means that it was removed from DOM tree during
620
- // comparison with the expected DOM. We don't need to check child nodes, because if child node was reinserted,
621
- // it was moved to DOM tree out of the removed node.
622
- for (const node of nodesToUnbind) {
623
- if (!node.parentNode) {
624
- this.domConverter.unbindDomElement(node);
625
- }
626
- }
627
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
628
- // @if CK_DEBUG_TYPING // console.groupEnd();
629
- // @if CK_DEBUG_TYPING // }
630
- }
631
- /**
632
- * Shorthand for diffing two arrays or node lists of DOM nodes.
633
- *
634
- * @param actualDomChildren Actual DOM children
635
- * @param expectedDomChildren Expected DOM children.
636
- * @returns The list of actions based on the {@link module:utils/diff~diff} function.
637
- */
638
- _diffNodeLists(actualDomChildren, expectedDomChildren) {
639
- actualDomChildren = filterOutFakeSelectionContainer(actualDomChildren, this._fakeSelectionContainer);
640
- return diff(actualDomChildren, expectedDomChildren, sameNodes.bind(null, this.domConverter));
641
- }
642
- /**
643
- * Finds DOM nodes that were replaced with the similar nodes (same tag name) in the view. All nodes are compared
644
- * within one `insert`/`delete` action group, for example:
645
- *
646
- * ```
647
- * Actual DOM: <p><b>Foo</b>Bar<i>Baz</i><b>Bax</b></p>
648
- * Expected DOM: <p>Bar<b>123</b><i>Baz</i><b>456</b></p>
649
- * Input actions: [ insert, insert, delete, delete, equal, insert, delete ]
650
- * Output actions: [ insert, replace, delete, equal, replace ]
651
- * ```
652
- *
653
- * @param actions Actions array which is a result of the {@link module:utils/diff~diff} function.
654
- * @param actualDom Actual DOM children
655
- * @param expectedDom Expected DOM children.
656
- * @param comparator A comparator function that should return `true` if the given node should be reused
657
- * (either by the update of a text node data or an element children list for similar elements).
658
- * @returns Actions array modified with the `update` actions.
659
- */
660
- _findUpdateActions(actions, actualDom, expectedDom, comparator) {
661
- // If there is no both 'insert' and 'delete' actions, no need to check for replaced elements.
662
- if (actions.indexOf('insert') === -1 || actions.indexOf('delete') === -1) {
663
- return actions;
664
- }
665
- let newActions = [];
666
- let actualSlice = [];
667
- let expectedSlice = [];
668
- const counter = { equal: 0, insert: 0, delete: 0 };
669
- for (const action of actions) {
670
- if (action === 'insert') {
671
- expectedSlice.push(expectedDom[counter.equal + counter.insert]);
672
- }
673
- else if (action === 'delete') {
674
- actualSlice.push(actualDom[counter.equal + counter.delete]);
675
- }
676
- else { // equal
677
- newActions = newActions.concat(diff(actualSlice, expectedSlice, comparator)
678
- .map(action => action === 'equal' ? 'update' : action));
679
- newActions.push('equal');
680
- // Reset stored elements on 'equal'.
681
- actualSlice = [];
682
- expectedSlice = [];
683
- }
684
- counter[action]++;
685
- }
686
- return newActions.concat(diff(actualSlice, expectedSlice, comparator)
687
- .map(action => action === 'equal' ? 'update' : action));
688
- }
689
- /**
690
- * Checks if text needs to be updated and possibly updates it by removing and inserting only parts
691
- * of the data from the existing text node to reduce impact on the IME composition.
692
- *
693
- * @param domText DOM text node to update.
694
- * @param expectedText The expected data of a text node.
695
- */
696
- _updateTextNode(domText, expectedText) {
697
- const actualText = domText.data;
698
- if (actualText == expectedText) {
699
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
700
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
701
- // @if CK_DEBUG_TYPING // '%cText node does not need update:%c ' +
702
- // @if CK_DEBUG_TYPING // `${ _escapeTextNodeData( actualText ) }%c (${ actualText.length })`,
703
- // @if CK_DEBUG_TYPING // 'font-style: italic',
704
- // @if CK_DEBUG_TYPING // 'color: blue',
705
- // @if CK_DEBUG_TYPING // ''
706
- // @if CK_DEBUG_TYPING // ) );
707
- // @if CK_DEBUG_TYPING // }
708
- return;
709
- }
710
- // Our approach to interleaving space character with NBSP might differ with the one implemented by the browser.
711
- // Avoid modifying the text node in the DOM if only NBSPs and spaces are interchanged.
712
- // We should avoid DOM modifications while composing to avoid breakage of composition.
713
- // See: https://github.com/ckeditor/ckeditor5/issues/13994.
714
- if (env.isAndroid && this.isComposing && actualText.replace(/\u00A0/g, ' ') == expectedText.replace(/\u00A0/g, ' ')) {
715
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
716
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
717
- // @if CK_DEBUG_TYPING // '%cText node ignore NBSP changes while composing: ' +
718
- // @if CK_DEBUG_TYPING // `%c${ _escapeTextNodeData( actualText ) }%c (${ actualText.length }) -> ` +
719
- // @if CK_DEBUG_TYPING // `%c${ _escapeTextNodeData( expectedText ) }%c (${ expectedText.length })`,
720
- // @if CK_DEBUG_TYPING // 'font-style: italic',
721
- // @if CK_DEBUG_TYPING // 'color: blue',
722
- // @if CK_DEBUG_TYPING // '',
723
- // @if CK_DEBUG_TYPING // 'color: blue',
724
- // @if CK_DEBUG_TYPING // ''
725
- // @if CK_DEBUG_TYPING // ) );
726
- // @if CK_DEBUG_TYPING // }
727
- return;
728
- }
729
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
730
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
731
- // @if CK_DEBUG_TYPING // '%cUpdate text node' +
732
- // @if CK_DEBUG_TYPING // `${ this.isComposing ? ' while composing (may break composition)' : '' }: ` +
733
- // @if CK_DEBUG_TYPING // `%c${ _escapeTextNodeData( actualText ) }%c (${ actualText.length }) -> ` +
734
- // @if CK_DEBUG_TYPING // `%c${ _escapeTextNodeData( expectedText ) }%c (${ expectedText.length })`,
735
- // @if CK_DEBUG_TYPING // this.isComposing ? 'color: red; font-weight: bold' : '',
736
- // @if CK_DEBUG_TYPING // 'color: blue',
737
- // @if CK_DEBUG_TYPING // '',
738
- // @if CK_DEBUG_TYPING // 'color: blue',
739
- // @if CK_DEBUG_TYPING // ''
740
- // @if CK_DEBUG_TYPING // ) );
741
- // @if CK_DEBUG_TYPING // }
742
- this._updateTextNodeInternal(domText, expectedText);
743
- }
744
- /**
745
- * Part of the `_updateTextNode` method extracted for easier testing.
746
- */
747
- _updateTextNodeInternal(domText, expectedText) {
748
- const actions = fastDiff(domText.data, expectedText);
749
- for (const action of actions) {
750
- if (action.type === 'insert') {
751
- domText.insertData(action.index, action.values.join(''));
752
- }
753
- else { // 'delete'
754
- domText.deleteData(action.index, action.howMany);
755
- }
756
- }
757
- }
758
- /**
759
- * Marks text nodes to be synchronized.
760
- *
761
- * If a text node is passed, it will be marked. If an element is passed, all descendant text nodes inside it will be marked.
762
- *
763
- * @param viewNode View node to sync.
764
- */
765
- _markDescendantTextToSync(viewNode) {
766
- if (!viewNode) {
767
- return;
768
- }
769
- if (viewNode.is('$text')) {
770
- this.markedTexts.add(viewNode);
771
- }
772
- else if (viewNode.is('element')) {
773
- for (const child of viewNode.getChildren()) {
774
- this._markDescendantTextToSync(child);
775
- }
776
- }
777
- }
778
- /**
779
- * Checks if the selection needs to be updated and possibly updates it.
780
- */
781
- _updateSelection() {
782
- // Block updating DOM selection in (non-Android) Blink while the user is selecting to prevent accidental selection collapsing.
783
- // Note: Structural changes in DOM must trigger selection rendering, though. Nodes the selection was anchored
784
- // to, may disappear in DOM which would break the selection (e.g. in real-time collaboration scenarios).
785
- // https://github.com/ckeditor/ckeditor5/issues/10562, https://github.com/ckeditor/ckeditor5/issues/10723
786
- if (env.isBlink && !env.isAndroid && this.isSelecting && !this.markedChildren.size) {
787
- return;
788
- }
789
- // If there is no selection - remove DOM and fake selections.
790
- if (this.selection.rangeCount === 0) {
791
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
792
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
793
- // @if CK_DEBUG_TYPING // 'Update DOM selection: remove all ranges'
794
- // @if CK_DEBUG_TYPING // ) );
795
- // @if CK_DEBUG_TYPING // }
796
- this._removeDomSelection();
797
- this._removeFakeSelection();
798
- return;
799
- }
800
- const domEditable = this.domConverter.mapViewToDom(this.selection.editableElement);
801
- // Do not update DOM selection if there is no focus, or there is no DOM element corresponding to selection's editable element.
802
- if (!this.isFocused || !domEditable) {
803
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
804
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
805
- // @if CK_DEBUG_TYPING // 'Skip updating DOM selection:',
806
- // @if CK_DEBUG_TYPING // `isFocused: ${ this.isFocused }, hasDomEditable: ${ !!domEditable }`
807
- // @if CK_DEBUG_TYPING // ) );
808
- // @if CK_DEBUG_TYPING // }
809
- // But if there was a fake selection, and it is not fake anymore - remove it as it can map to no longer existing widget.
810
- // See https://github.com/ckeditor/ckeditor5/issues/18123.
811
- if (!this.selection.isFake && this._fakeSelectionContainer && this._fakeSelectionContainer.isConnected) {
812
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
813
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
814
- // @if CK_DEBUG_TYPING // 'Remove fake selection (not focused editable)'
815
- // @if CK_DEBUG_TYPING // ) );
816
- // @if CK_DEBUG_TYPING // }
817
- this._removeFakeSelection();
818
- }
819
- return;
820
- }
821
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
822
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
823
- // @if CK_DEBUG_TYPING // 'Update DOM selection'
824
- // @if CK_DEBUG_TYPING // ) );
825
- // @if CK_DEBUG_TYPING // }
826
- // Render fake selection - create the fake selection container (if needed) and move DOM selection to it.
827
- if (this.selection.isFake) {
828
- this._updateFakeSelection(domEditable);
829
- }
830
- // There was a fake selection so remove it and update the DOM selection.
831
- // This is especially important on Android because otherwise IME will try to compose over the fake selection container.
832
- else if (this._fakeSelectionContainer && this._fakeSelectionContainer.isConnected) {
833
- this._removeFakeSelection();
834
- this._updateDomSelection(domEditable);
835
- }
836
- // Update the DOM selection in case of a plain selection change (no fake selection is involved).
837
- // On non-Android the whole rendering is disabled in composition mode (including DOM selection update),
838
- // but updating DOM selection should be also disabled on Android if in the middle of the composition
839
- // (to not interrupt it).
840
- else if (!(this.isComposing && env.isAndroid)) {
841
- this._updateDomSelection(domEditable);
842
- }
843
- }
844
- /**
845
- * Updates the fake selection.
846
- *
847
- * @param domEditable A valid DOM editable where the fake selection container should be added.
848
- */
849
- _updateFakeSelection(domEditable) {
850
- const domDocument = domEditable.ownerDocument;
851
- if (!this._fakeSelectionContainer) {
852
- this._fakeSelectionContainer = createFakeSelectionContainer(domDocument);
853
- }
854
- const container = this._fakeSelectionContainer;
855
- // Bind fake selection container with the current selection *position*.
856
- this.domConverter.bindFakeSelection(container, this.selection);
857
- if (!this._fakeSelectionNeedsUpdate(domEditable)) {
858
- return;
859
- }
860
- if (!container.parentElement || container.parentElement != domEditable) {
861
- domEditable.appendChild(container);
862
- }
863
- container.textContent = this.selection.fakeSelectionLabel || '\u00A0';
864
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
865
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
866
- // @if CK_DEBUG_TYPING // 'Set DOM fake selection'
867
- // @if CK_DEBUG_TYPING // ) );
868
- // @if CK_DEBUG_TYPING // }
869
- const domSelection = domDocument.getSelection();
870
- const domRange = domDocument.createRange();
871
- domSelection.removeAllRanges();
872
- domRange.selectNodeContents(container);
873
- domSelection.addRange(domRange);
874
- }
875
- /**
876
- * Updates the DOM selection.
877
- *
878
- * @param domEditable A valid DOM editable where the DOM selection should be rendered.
879
- */
880
- _updateDomSelection(domEditable) {
881
- const domSelection = domEditable.ownerDocument.defaultView.getSelection();
882
- // Let's check whether DOM selection needs updating at all.
883
- if (!this._domSelectionNeedsUpdate(domSelection)) {
884
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
885
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
886
- // @if CK_DEBUG_TYPING // '%cDOM selection is already correct',
887
- // @if CK_DEBUG_TYPING // 'font-style: italic;'
888
- // @if CK_DEBUG_TYPING // ) );
889
- // @if CK_DEBUG_TYPING // }
890
- return;
891
- }
892
- // Multi-range selection is not available in most browsers, and, at least in Chrome, trying to
893
- // set such selection, that is not continuous, throws an error. Because of that, we will just use anchor
894
- // and focus of view selection.
895
- // Since we are not supporting multi-range selection, we also do not need to check if proper editable is
896
- // selected. If there is any editable selected, it is okay (editable is taken from selection anchor).
897
- const anchor = this.domConverter.viewPositionToDom(this.selection.anchor);
898
- const focus = this.domConverter.viewPositionToDom(this.selection.focus);
899
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
900
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
901
- // @if CK_DEBUG_TYPING // 'Update DOM selection:',
902
- // @if CK_DEBUG_TYPING // anchor,
903
- // @if CK_DEBUG_TYPING // focus
904
- // @if CK_DEBUG_TYPING // ) );
905
- // @if CK_DEBUG_TYPING // }
906
- domSelection.setBaseAndExtent(anchor.parent, anchor.offset, focus.parent, focus.offset);
907
- // Firefox–specific hack (https://github.com/ckeditor/ckeditor5-engine/issues/1439).
908
- if (env.isGecko) {
909
- fixGeckoSelectionAfterBr(focus, domSelection);
910
- }
911
- }
912
- /**
913
- * Checks whether a given DOM selection needs to be updated.
914
- *
915
- * @param domSelection The DOM selection to check.
916
- */
917
- _domSelectionNeedsUpdate(domSelection) {
918
- if (!this.domConverter.isDomSelectionCorrect(domSelection)) {
919
- // Current DOM selection is in incorrect position. We need to update it.
920
- return true;
921
- }
922
- const oldViewSelection = domSelection && this.domConverter.domSelectionToView(domSelection);
923
- if (oldViewSelection && this.selection.isEqual(oldViewSelection)) {
924
- return false;
925
- }
926
- // If selection is not collapsed, it does not need to be updated if it is similar.
927
- if (!this.selection.isCollapsed && this.selection.isSimilar(oldViewSelection)) {
928
- // Selection did not changed and is correct, do not update.
929
- return false;
930
- }
931
- // Selections are not similar.
932
- return true;
933
- }
934
- /**
935
- * Checks whether the fake selection needs to be updated.
936
- *
937
- * @param domEditable A valid DOM editable where a new fake selection container should be added.
938
- */
939
- _fakeSelectionNeedsUpdate(domEditable) {
940
- const container = this._fakeSelectionContainer;
941
- const domSelection = domEditable.ownerDocument.getSelection();
942
- // Fake selection needs to be updated if there's no fake selection container, or the container currently sits
943
- // in a different root.
944
- if (!container || container.parentElement !== domEditable) {
945
- return true;
946
- }
947
- // Make sure that the selection actually is within the fake selection.
948
- if (domSelection.anchorNode !== container && !container.contains(domSelection.anchorNode)) {
949
- return true;
950
- }
951
- return container.textContent !== this.selection.fakeSelectionLabel;
952
- }
953
- /**
954
- * Removes the DOM selection.
955
- */
956
- _removeDomSelection() {
957
- for (const doc of this.domDocuments) {
958
- const domSelection = doc.getSelection();
959
- if (domSelection.rangeCount) {
960
- const activeDomElement = doc.activeElement;
961
- const viewElement = this.domConverter.mapDomToView(activeDomElement);
962
- if (activeDomElement && viewElement) {
963
- domSelection.removeAllRanges();
964
- }
965
- }
966
- }
967
- }
968
- /**
969
- * Removes the fake selection.
970
- */
971
- _removeFakeSelection() {
972
- const container = this._fakeSelectionContainer;
973
- if (container) {
974
- container.remove();
975
- }
976
- }
977
- /**
978
- * Checks if focus needs to be updated and possibly updates it.
979
- */
980
- _updateFocus() {
981
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
982
- // @if CK_DEBUG_TYPING // console.group( ..._buildLogMessage( this, 'Renderer',
983
- // @if CK_DEBUG_TYPING // `update focus: ${ this.isFocused ? 'focused' : 'not focused' }`
984
- // @if CK_DEBUG_TYPING // ) );
985
- // @if CK_DEBUG_TYPING // }
986
- if (this.isFocused) {
987
- const editable = this.selection.editableElement;
988
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
989
- // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'Renderer',
990
- // @if CK_DEBUG_TYPING // 'focus editable:',
991
- // @if CK_DEBUG_TYPING // { editable }
992
- // @if CK_DEBUG_TYPING // ) );
993
- // @if CK_DEBUG_TYPING // }
994
- if (editable) {
995
- this.domConverter.focus(editable);
996
- }
997
- }
998
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
999
- // @if CK_DEBUG_TYPING // console.groupEnd();
1000
- // @if CK_DEBUG_TYPING // }
1001
- }
1002
- }
1003
- /**
1004
- * Checks if provided element is editable.
1005
- */
1006
- function isEditable(element) {
1007
- if (element.getAttribute('contenteditable') == 'false') {
1008
- return false;
1009
- }
1010
- const parent = element.findAncestor(element => element.hasAttribute('contenteditable'));
1011
- return !parent || parent.getAttribute('contenteditable') == 'true';
1012
- }
1013
- /**
1014
- * Adds inline filler at a given position.
1015
- *
1016
- * The position can be given as an array of DOM nodes and an offset in that array,
1017
- * or a DOM parent element and an offset in that element.
1018
- *
1019
- * @returns The DOM text node that contains an inline filler.
1020
- */
1021
- function addInlineFiller(domDocument, domParentOrArray, offset) {
1022
- const childNodes = domParentOrArray instanceof Array ? domParentOrArray : domParentOrArray.childNodes;
1023
- const nodeAfterFiller = childNodes[offset];
1024
- if (isText(nodeAfterFiller)) {
1025
- nodeAfterFiller.data = INLINE_FILLER + nodeAfterFiller.data;
1026
- return nodeAfterFiller;
1027
- }
1028
- else {
1029
- const fillerNode = domDocument.createTextNode(INLINE_FILLER);
1030
- if (Array.isArray(domParentOrArray)) {
1031
- childNodes.splice(offset, 0, fillerNode);
1032
- }
1033
- else {
1034
- insertAt(domParentOrArray, offset, fillerNode);
1035
- }
1036
- return fillerNode;
1037
- }
1038
- }
1039
- /**
1040
- * Whether two DOM nodes should be considered as similar.
1041
- * Nodes are considered similar if they have the same tag name.
1042
- */
1043
- function areSimilarElements(node1, node2) {
1044
- return isNode(node1) && isNode(node2) &&
1045
- !isText(node1) && !isText(node2) &&
1046
- !isComment(node1) && !isComment(node2) &&
1047
- node1.tagName.toLowerCase() === node2.tagName.toLowerCase();
1048
- }
1049
- /**
1050
- * Whether two DOM nodes are text nodes.
1051
- */
1052
- function areTextNodes(node1, node2) {
1053
- return isNode(node1) && isNode(node2) &&
1054
- isText(node1) && isText(node2);
1055
- }
1056
- /**
1057
- * Whether two dom nodes should be considered as the same.
1058
- * Two nodes which are considered the same are:
1059
- *
1060
- * * Text nodes with the same text.
1061
- * * Element nodes represented by the same object.
1062
- * * Two block filler elements.
1063
- *
1064
- * @param blockFillerMode Block filler mode, see {@link module:engine/view/domconverter~ViewDomConverter#blockFillerMode}.
1065
- */
1066
- function sameNodes(domConverter, actualDomChild, expectedDomChild) {
1067
- // Elements.
1068
- if (actualDomChild === expectedDomChild) {
1069
- return true;
1070
- }
1071
- // Texts.
1072
- else if (isText(actualDomChild) && isText(expectedDomChild)) {
1073
- return actualDomChild.data === expectedDomChild.data;
1074
- }
1075
- // Block fillers.
1076
- else if (domConverter.isBlockFiller(actualDomChild) &&
1077
- domConverter.isBlockFiller(expectedDomChild)) {
1078
- return true;
1079
- }
1080
- // Not matching types.
1081
- return false;
1082
- }
1083
- /**
1084
- * The following is a Firefox–specific hack (https://github.com/ckeditor/ckeditor5-engine/issues/1439).
1085
- * When the native DOM selection is at the end of the block and preceded by <br /> e.g.
1086
- *
1087
- * ```html
1088
- * <p>foo<br/>[]</p>
1089
- * ```
1090
- *
1091
- * which happens a lot when using the soft line break, the browser fails to (visually) move the
1092
- * caret to the new line. A quick fix is as simple as force–refreshing the selection with the same range.
1093
- */
1094
- function fixGeckoSelectionAfterBr(focus, domSelection) {
1095
- let parent = focus.parent;
1096
- let offset = focus.offset;
1097
- if (isText(parent) && isInlineFiller(parent)) {
1098
- offset = indexOf(parent) + 1;
1099
- parent = parent.parentNode;
1100
- }
1101
- // This fix works only when the focus point is at the very end of an element.
1102
- // There is no point in running it in cases unrelated to the browser bug.
1103
- if (parent.nodeType != Node.ELEMENT_NODE || offset != parent.childNodes.length - 1) {
1104
- return;
1105
- }
1106
- const childAtOffset = parent.childNodes[offset];
1107
- // To stay on the safe side, the fix being as specific as possible, it targets only the
1108
- // selection which is at the very end of the element and preceded by <br />.
1109
- if (childAtOffset && childAtOffset.tagName == 'BR') {
1110
- domSelection.addRange(domSelection.getRangeAt(0));
1111
- }
1112
- }
1113
- function filterOutFakeSelectionContainer(domChildList, fakeSelectionContainer) {
1114
- const childList = Array.from(domChildList);
1115
- if (childList.length == 0 || !fakeSelectionContainer) {
1116
- return childList;
1117
- }
1118
- const last = childList[childList.length - 1];
1119
- if (last == fakeSelectionContainer) {
1120
- childList.pop();
1121
- }
1122
- return childList;
1123
- }
1124
- /**
1125
- * Creates a fake selection container for a given document.
1126
- */
1127
- function createFakeSelectionContainer(domDocument) {
1128
- const container = domDocument.createElement('div');
1129
- container.className = 'ck-fake-selection-container';
1130
- Object.assign(container.style, {
1131
- position: 'fixed',
1132
- top: 0,
1133
- left: '-9999px',
1134
- // See https://github.com/ckeditor/ckeditor5/issues/752.
1135
- width: '42px'
1136
- });
1137
- // Fill it with a text node so we can update it later.
1138
- container.textContent = '\u00A0';
1139
- return container;
1140
- }
1141
- // @if CK_DEBUG_TYPING // function _escapeTextNodeData( text ) {
1142
- // @if CK_DEBUG_TYPING // const escapedText = text
1143
- // @if CK_DEBUG_TYPING // .replace( /&/g, '&amp;' )
1144
- // @if CK_DEBUG_TYPING // .replace( /\u00A0/g, '&nbsp;' )
1145
- // @if CK_DEBUG_TYPING // .replace( /\u2060/g, '&NoBreak;' );
1146
- // @if CK_DEBUG_TYPING //
1147
- // @if CK_DEBUG_TYPING // return `"${ escapedText }"`;
1148
- // @if CK_DEBUG_TYPING // }