Skip to content

Commit 2a099e6

Browse files
authored
Merge pull request #18729 from ckeditor/ck/18722-code-block-case
Internal (typing): The engine should prevent the browser from modifying the DOM structure while user is typing. See #18722.
2 parents bcb74fe + 67a88dc commit 2a099e6

File tree

7 files changed

+281
-396
lines changed

7 files changed

+281
-396
lines changed

packages/ckeditor5-engine/src/controller/editingcontroller.ts

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
import {
1111
CKEditorError,
12-
ObservableMixin,
13-
env,
14-
type GetCallback
12+
ObservableMixin
1513
} from '@ckeditor/ckeditor5-utils';
1614

1715
import RootEditableElement from '../view/rooteditableelement.js';
@@ -34,18 +32,14 @@ import {
3432

3533
import { convertSelectionChange } from '../conversion/upcasthelpers.js';
3634

37-
import { tryFixingRange } from '../model/utils/selection-post-fixer.js';
38-
3935
import type { default as Model, AfterChangesEvent, BeforeChangesEvent } from '../model/model.js';
4036
import type ModelItem from '../model/item.js';
4137
import type ModelText from '../model/text.js';
4238
import type ModelTextProxy from '../model/textproxy.js';
43-
import type Schema from '../model/schema.js';
4439
import type { DocumentChangeEvent } from '../model/document.js';
4540
import type { Marker } from '../model/markercollection.js';
4641
import type { StylesProcessor } from '../view/stylesmap.js';
4742
import type { ViewDocumentSelectionChangeEvent } from '../view/observer/selectionobserver.js';
48-
import type { ViewDocumentInputEvent } from '../view/observer/inputobserver.js';
4943

5044
// @if CK_DEBUG_ENGINE // const { dumpTrees, initDocumentDumping } = require( '../dev-utils/utils' );
5145

@@ -125,12 +119,6 @@ export default class EditingController extends /* #__PURE__ */ ObservableMixin()
125119
convertSelectionChange( this.model, this.mapper )
126120
);
127121

128-
// Fix `beforeinput` target ranges so that they map to the valid model ranges.
129-
this.listenTo<ViewDocumentInputEvent>( this.view.document, 'beforeinput',
130-
fixTargetRanges( this.mapper, this.model.schema, this.view ),
131-
{ priority: 'high' }
132-
);
133-
134122
// Attach default model converters.
135123
this.downcastDispatcher.on<DowncastInsertEvent<ModelText | ModelTextProxy>>( 'insert:$text', insertText(), { priority: 'lowest' } );
136124
this.downcastDispatcher.on<DowncastInsertEvent>( 'insert', insertAttributesAndChildren(), { priority: 'lowest' } );
@@ -248,30 +236,3 @@ export default class EditingController extends /* #__PURE__ */ ObservableMixin()
248236
} );
249237
}
250238
}
251-
252-
/**
253-
* Checks whether the target ranges provided by the `beforeInput` event can be properly mapped to model ranges and fixes them if needed.
254-
*
255-
* This is using the same logic as the selection post-fixer.
256-
*/
257-
function fixTargetRanges( mapper: Mapper, schema: Schema, view: View ): GetCallback<ViewDocumentInputEvent> {
258-
return ( evt, data ) => {
259-
// The Renderer is disabled while composing on non-android browsers, so we can't be sure that target ranges
260-
// could be properly mapped to view and model because the DOM and view tree drifted apart.
261-
if ( view.document.isComposing && !env.isAndroid ) {
262-
return;
263-
}
264-
265-
for ( let i = 0; i < data.targetRanges.length; i++ ) {
266-
const viewRange = data.targetRanges[ i ];
267-
const modelRange = mapper.toModelRange( viewRange );
268-
const correctedRange = tryFixingRange( modelRange, schema );
269-
270-
if ( !correctedRange || correctedRange.isEqual( modelRange ) ) {
271-
continue;
272-
}
273-
274-
data.targetRanges[ i ] = mapper.toViewRange( correctedRange );
275-
}
276-
};
277-
}

packages/ckeditor5-engine/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,7 @@ export {
231231
parse as _parseView,
232232
stringify as _stringifyView
233233
} from './dev-utils/view.js';
234+
235+
export {
236+
tryFixingRange as _tryFixingModelRange
237+
} from './model/utils/selection-post-fixer.js';

0 commit comments

Comments
 (0)