engine/model/utils/selection-post-fixer
Functions
injectSelectionPostFixer( model ) → voidinternalmodule:engine/model/utils/selection-post-fixer~injectSelectionPostFixerInjects selection post-fixer to the model.
The role of the selection post-fixer is to ensure that the selection is in a correct place after a
change()block was executed.The correct position means that:
- All collapsed selection ranges are in a place where the
ModelSchemaallows a$text. - None of the selection's non-collapsed ranges crosses a limit element boundary (a range must be rooted within one limit element).
- Only selectable elements can be selected from the outside (e.g.
[<paragraph>foo</paragraph>]is invalid). This rule applies independently to both selection ends, so this selection is correct:<paragraph>f[oo</paragraph><imageBlock></imageBlock>].
If the position is not correct, the post-fixer will automatically correct it.
Fixing a non-collapsed selection
See as an example a selection that starts in a P1 element and ends inside the text of a TD element (
[and]are range boundaries and(l)denotes an element defined asisLimit=true):root |- element P1 | |- "foo" root |- element TABLE (l) P1 TABLE P2 | |- element TR (l) f o[o TR TR b a r | | |- element TD (l) TD TD | | |- "aaa" a]a a b b b | |- element TR (l) | | |- element TD (l) || | | |- "bbb" || |- element P2 VV | |- "bar" root P1 TABLE] P2 f o[o TR TR b a r TD TD a a a b b bCopy codeIn the example above, the TABLE, TR and TD are defined as
isLimit=truein the schema. The range which is not contained within a single limit element must be expanded to select the outermost limit element. The range end is inside the text node of the TD element. As the TD element is a child of the TR and TABLE elements, where both are defined asisLimit=truein the schema, the range must be expanded to select the whole TABLE element.Note If the selection contains multiple ranges, the method returns a minimal set of ranges that are not intersecting after expanding them to select
isLimit=trueelements.Parameters
model : Model
Returns
void
- All collapsed selection ranges are in a place where the
mergeIntersectingRanges( ranges ) → Array<ModelRange>internalmodule:engine/model/utils/selection-post-fixer~mergeIntersectingRangesReturns a minimal non-intersecting array of ranges without duplicates.
Parameters
ranges : Array<ModelRange>Ranges to merge.
Returns
Array<ModelRange>Array of unique and non-intersecting ranges.
tryFixingRange( range, schema ) → null | ModelRangeinternalmodule:engine/model/utils/selection-post-fixer~tryFixingRangeTries fixing a range if it's incorrect.
Note: This helper is used by the selection post-fixer and to fix the
beforeinputtarget ranges.Parameters
range : ModelRangeschema : ModelSchema
Returns
null | ModelRangeReturns fixed range or null if range is valid.