Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 1 addition & 40 deletions packages/ckeditor5-engine/src/controller/editingcontroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

import {
CKEditorError,
ObservableMixin,
env,
type GetCallback
ObservableMixin
} from '@ckeditor/ckeditor5-utils';

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

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

import { tryFixingRange } from '../model/utils/selection-post-fixer.js';

import type { default as Model, AfterChangesEvent, BeforeChangesEvent } from '../model/model.js';
import type ModelItem from '../model/item.js';
import type ModelText from '../model/text.js';
import type ModelTextProxy from '../model/textproxy.js';
import type Schema from '../model/schema.js';
import type { DocumentChangeEvent } from '../model/document.js';
import type { Marker } from '../model/markercollection.js';
import type { StylesProcessor } from '../view/stylesmap.js';
import type { ViewDocumentSelectionChangeEvent } from '../view/observer/selectionobserver.js';
import type { ViewDocumentInputEvent } from '../view/observer/inputobserver.js';

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

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

// Fix `beforeinput` target ranges so that they map to the valid model ranges.
this.listenTo<ViewDocumentInputEvent>( this.view.document, 'beforeinput',
fixTargetRanges( this.mapper, this.model.schema, this.view ),
{ priority: 'high' }
);

// Attach default model converters.
this.downcastDispatcher.on<DowncastInsertEvent<ModelText | ModelTextProxy>>( 'insert:$text', insertText(), { priority: 'lowest' } );
this.downcastDispatcher.on<DowncastInsertEvent>( 'insert', insertAttributesAndChildren(), { priority: 'lowest' } );
Expand Down Expand Up @@ -248,30 +236,3 @@ export default class EditingController extends /* #__PURE__ */ ObservableMixin()
} );
}
}

/**
* Checks whether the target ranges provided by the `beforeInput` event can be properly mapped to model ranges and fixes them if needed.
*
* This is using the same logic as the selection post-fixer.
*/
function fixTargetRanges( mapper: Mapper, schema: Schema, view: View ): GetCallback<ViewDocumentInputEvent> {
return ( evt, data ) => {
// The Renderer is disabled while composing on non-android browsers, so we can't be sure that target ranges
// could be properly mapped to view and model because the DOM and view tree drifted apart.
if ( view.document.isComposing && !env.isAndroid ) {
return;
}

for ( let i = 0; i < data.targetRanges.length; i++ ) {
const viewRange = data.targetRanges[ i ];
const modelRange = mapper.toModelRange( viewRange );
const correctedRange = tryFixingRange( modelRange, schema );

if ( !correctedRange || correctedRange.isEqual( modelRange ) ) {
continue;
}

data.targetRanges[ i ] = mapper.toViewRange( correctedRange );
}
};
}
4 changes: 4 additions & 0 deletions packages/ckeditor5-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,7 @@ export {
parse as _parseView,
stringify as _stringifyView
} from './dev-utils/view.js';

export {
tryFixingRange as _tryFixingModelRange
} from './model/utils/selection-post-fixer.js';
Loading